X hits on this document

375 views

0 shares

0 downloads

0 comments

98 / 120

13:

}

14:

15:

public static String serializeXML(SMPLCALCINTERFACE request)

16

{

24:

}

25:

26:

public static SMPLCALCINTERFACE loadXML(String xmlDoc)

27:

{

To cleanly integrate the JAXB marshalling with JSimpleCalculator.java,

SmplCalcJaxbMarshaller.java, which encapsulates the interaction with the JAXB, was

created. Table 9.4 gives an abbreviated listing of this class.

17: 18: 19: 20: 21: 22: 23:

marshaller.marshal(request, xmlBytes); } catch (JAXBException _je) {...} String xmlDoc = new String(xmlBytes.toByteArray()); return xmlDoc;

JSimpleCalculator.java to use SmplCalcJaxbMarshaller.java to generate and consume

Table 9.4. Partial listing of SmplCalcJaxbMarshaller.java interaction with JAXB.

ByteArrayOutputStream xmlBytes try {

= new ByteArrayOutputStream();

Next we need to update the add, subtract, and multiply methods in

01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12:

private static JAXBContext jaxbContext = null; private static Marshaller marshaller = null; private static Unmarshaller unmarshaller = null;

static { try { jaxbContext = JAXBContext.newInstance(SMPLCALCINTERFACE.class); marshaller = jaxbContext.createMarshaller(); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException _je) {...}

28: 29:

SMPLCALCINTERFACE response = null; ByteArrayInputStream xmlBytes = new

ByteArrayInputStream(xmlDoc.getBytes());

30: 31: 32: 33: 34:

35:

}

try {

response = (SMPLCALCINTERFACE)unmarshaller.unmarshal(xmlBytes); } catch (JAXBException _je) {...} return response;

90

Document info
Document views375
Page views376
Page last viewedFri Dec 09 10:21:20 UTC 2016
Pages120
Paragraphs2913
Words25794

Comments