JAXBBlockFactory f = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create a jaxb object
ObjectFactory factory = new ObjectFactory();
EchoString jaxb = factory.createEchoString();
jaxb.setInput("Hello World");
JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
JAXBContext jaxbContext = context.getJAXBContext();
JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(jaxbContext);
QName expectedQName = jbi.getElementName(jaxb);
// On inbound, there will already be a probably be an OM
// which represents the message. In this scenario, the OM contains
// a OMSourcedElement that is backed by EchoString.
OMFactory omFactory = OMAbstractFactory.getOMFactory();
JAXBDSContext dsContext = new JAXBDSContext(jaxbContext);
JAXBDataSource ds = new JAXBDataSource(jaxb, dsContext);
OMNamespace ns = omFactory.createOMNamespace(expectedQName.getNamespaceURI(), "pre");
OMElement om = omFactory.createOMElement(ds, expectedQName.getLocalPart(), ns);
// Create a Block from the inflow.
Block block = f.createFrom(om, context, expectedQName);
// We passed in a qname, so the following should return true
assertTrue(block.isQNameAvailable());
// Assume that we need to find the QName (perhaps to identify the operation and
// determine if handlers are installed).
QName qName = block.getQName();
assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object.
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof EchoString);
// Since the EchoString was already provided in a data source, this
// object should be same as the original echoString
assertTrue(bo == jaxb);
// The block should be consumed
assertTrue(block.isConsumed());
// Check for accuracy
assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
}