i have got an own vector.class and a polygon.class Vector.class
package org.onvif.ver10.schema;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Vector")
public class Vector {
@XmlAttribute(name = "x")
protected Float x;
@XmlAttribute(name = "y")
protected Float y;
/**
* Gets the value of the x property.
*
* @return
* possible object is
* {@link Float }
*
*/
public Float getX() {
return x;
}
/**
* Sets the value of the x property.
*
* @param value
* allowed object is
* {@link Float }
*
*/
public void setX(Float value) {
this.x = value;
}
/**
* Gets the value of the y property.
*
* @return
* possible object is
* {@link Float }
*
*/
public Float getY() {
return y;
}
/**
* Sets the value of the y property.
*
* @param value
* allowed object is
* {@link Float }
*
*/
public void setY(Float value) {
this.y = value;
}
}
and the polygon class
public class Polygon {
@XmlElement(name = "Point", required = true)
protected List<Vector> point;
/**
* Gets the value of the point property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the point property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPoint().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Vector }
*
*
*/
public List<Vector> getPoint() {
if (point == null) {
point = new ArrayList<Vector>();
}
return this.point;
}
}
So, i give the vector elements:
org.onvif.ver10.schema.Vector MyVector = new Vector(); // létrehozzuk az
// onvif féle
// vector-t
org.onvif.ver10.schema.Polygon op = new org.onvif.ver10.schema.Polygon();
for (int i = 1; i <= p.npoints; i++) {
// IJ.log("X: "+ i);
// MyVector.setX((float) p.xpoints[i]); // hozzáadjuk az elemet
// MyVector.setY((float) p.ypoints[i]);
MyVector.setX((float)p.xpoints[i-1]);
op.getPoint().add(MyVector);
IJ.log("Vector X Elements "+i+" :"+ MyVector.getX());
}
IJ.log("Op size " + op.getPoint().size());
My question is how can i get the op (onvif polygon) elements? Because i no matter how i try i just got the last element 10 times.
Your bug is that you are adding the same Vector
instance to the polygon 10 times and setting the points on that one instance over and over.
Your code should be changed to move the new Vector()
line inside the loop:
org.onvif.ver10.schema.Polygon op = new org.onvif.ver10.schema.Polygon();
for (int i = 1; i <= p.npoints; i++) {
org.onvif.ver10.schema.Vector MyVector = new Vector();
MyVector.setX((float)p.xpoints[i-1]);
op.getPoint().add(MyVector);
IJ.log("Vector X Elements "+i+" :"+ MyVector.getX());
}
Style issues with your code include, but are not limited to:
myVector
not MyVector
Vector
)