I have been trying to create an XML doc using jaxb, and sending that xml file through a socket to a client where to XML file would be created and also it would be unmarshaled and have its content printed on the screen. The thing is that I can not get the values if the child elements like DAint printed out and I not sure what to do. Please help!!!!!
For the output I get the values of the id, and is alert, but I can't get the values from getDataEvents().
Here is the server
// GET THE jaxb CONTEXT OBJECT
JAXBContext jaxbCtx = JAXBContext.newInstance("osacbmx");
// CREATES THE MARSHALLER
Marshaller marshaller = jaxbCtx.createMarshaller();
// THE OBJECTfACTORY CLASS IS CREATED
ObjectFactory objFactory = new ObjectFactory();
// OTHER OBJECTS
OsacbmTime time = new OsacbmTime();
time.setTime("5.00");
Site site = new Site();
site.setSiteId("Site1");
// THE DATA EVENT SET OBJECT IS CREATED
DAReal dareal = new DAReal();
dareal.setValue(21.23);
DAInt daint = new DAInt();
daint.setValue(21);
DAString dastring = new DAString();
dastring.setValue("Steven Romero");
DABool dabool = new DABool();
dabool.setValue(true);
DAVector davector = new DAVector();
davector.setXValue(45);
DAString dastring1 = new DAString();
dastring1.setValue("Applied Research Labs");
List waveForm = new ArrayList();
waveForm.add(121.54);
waveForm.add(12.3);
waveForm.add(45.5);
waveForm.add(23.45);
DAWaveform dawaveform = new DAWaveform();
dawaveform.setId(good);
dawaveform.setConfid(24.55);
dawaveform.setTime(time);
dawaveform.setSite(site);
byte[] myByteArray = { (byte)2, (byte)3, (byte)41 };
dawaveform.setValuesBinary(myByteArray);
dawaveform.getValues().addAll(waveForm);
DADataSeq dadataseq = new DADataSeq();
dadataseq.setSequenceNum(good);
dadataseq.setConfid(23.456);
dadataseq.setTime(time);
dadataseq.setSite(site);
// data event object created
DataEventSet dataEvent = new DataEventSet();
dataEvent.setAlertStatus(java.lang.Boolean.TRUE);
dataEvent.setId(goods);
ArrayList<DataEvent> data = new ArrayList<DataEvent>();
data.add(daint);
data.add(dareal);
data.add(dastring);
data.add(dabool);
data.add(davector);
data.add(dastring1);
data.add(dawaveform);
data.add(dadataseq);
dataEvent.getDataEvents().addAll(data);
// THE JAXBELEMENT DATAEVENTSET IS CREATED
JAXBElement <DataEventSet> xElement = objFactory.createDataEventSet(dataEvent);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT ,
new java.lang.Boolean(true));
// DataEvenSet marshalled then sent through the socket.
marshaller.marshal( xElement, socket.getOutputStream() );
System.out.println("the xml file has been created and sent to the client");
socket.shutdownOutput(); // send EOS
socket.close();
}catch(Exception e){ e.getMessage();}
}
public void createConnection()
{
try {
serverSocket = new ServerSocket(100);
System.out.println("OSACBM server running ...");
} catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}
}
}
Here are classes involved with the server.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DataEventSet", propOrder = {
"alertStatus",
"dataEvents",
"id",
"sequenceNum",
"site",
"time"
})
public class DataEventSet {
protected java.lang.Boolean alertStatus;
@XmlElement(required = true)
protected List<DataEvent> dataEvents;
@XmlSchemaType(name = "unsignedInt")
protected long id;
@XmlSchemaType(name = "unsignedInt")
protected java.lang.Long sequenceNum;
@XmlElement(required = true)
protected Site site;
@XmlElement(required = true)
protected OsacbmTime time;
/**
* Gets the value of the alertStatus property.
*
* @return
* possible object is
* {@link java.lang.Boolean }
*
*/
public java.lang.Boolean isAlertStatus() {
return alertStatus;
}
/**
* Sets the value of the alertStatus property.
*
* @param value
* allowed object is
* {@link java.lang.Boolean }
*
*/
public void setAlertStatus(java.lang.Boolean value) {
this.alertStatus = value;
}
/**
* Gets the value of the dataEvents 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 dataEvents property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getDataEvents().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link DataEvent }
*
*
*/
public List<DataEvent> getDataEvents() {
if (dataEvents == null) {
dataEvents = new ArrayList<DataEvent>();
}
return this.dataEvents;
}
Here is part of the client side that wont work.
JAXBContext jaxbCtx = JAXBContext.newInstance("osacbmx");
Unmarshaller u = jaxbCtx.createUnmarshaller();
System.out.println("new.xml has been recieved and unmarshalled");
JAXBElement <DataEventSet> element1 = u.unmarshal(new StreamSource("new.xml"),DataEventSet.class);
DataEventSet dataEvent = element1.getValue();
\
for (int i = 0; i < dataEvent.getDataEvents().toArray().length; i++) {
System.out.println("The Attribute are " + (i + 1) + ": "
+ dataEvent.getDataEvents().get(i)
);
}
System.out.println(dataEvent.isAlertStatus());
System.out.println(dataEvent.getId());
// System.out.println("The values for the DataEventSet XML are \n " +(DataEvent)dataEvent.getDataEvents());
}catch(Exception e){System.err.println(e.getMessage());}
}code}