Examples of JAXBDSContext


Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

    public void testMarshalArray() throws Exception {
       
        // Create a JAXBDSContext for the package containing Data
        TreeSet<String> packages = new TreeSet<String>();
        packages.add(Data.class.getPackage().getName());
        JAXBDSContext context = new JAXBDSContext(packages);
       
        TestLogger.logger.debug(context.getJAXBContext().toString());
       
        // Force marshal by type
        context.setProcessType(Data[].class);
       
        // Create an Data value
        ObjectFactory factory = new ObjectFactory();
        Data value[] = new Data[3];
        value[0] = factory.createData();
        value[0].setInput("Hello");
        value[1] = factory.createData();
        value[1].setInput("Beautiful");
        value[2] = factory.createData();
        value[2].setInput("World");
       
        // Create a JAXBElement.
        // To indicate "occurrence elements", the value is wrapped in
        // an OccurrenceArray
        QName qName = new QName("urn://sample", "data");
        OccurrenceArray occurrenceArray = new OccurrenceArray(value);
        JAXBElement jaxbElement = new JAXBElement(qName, Data[].class, occurrenceArray);

        // Create a writer
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OMOutputFormat format = new OMOutputFormat();
        format.setDoOptimize(true);
        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, format);
       
        // Marshal the value
        writer.writeStartElement("root");
        context.marshal(jaxbElement, writer);
        writer.writeEndElement();

        writer.flush();
       
        String outputText = baos.toString();
View Full Code Here

Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
            if (ds instanceof JAXBDataSource) {
                // Update the business context to use the one provided
                // by the datasource
                try {
                    JAXBDSContext dsContext = ((JAXBDataSource) ds).getContext();
                    busContext = new JAXBBlockContext(dsContext.getJAXBContext());
                } catch (JAXBException e) {
                    throw ExceptionFactory.makeWebServiceException(e);
                }
                return ((JAXBDataSource) ds).getObject();
            } else if (ds instanceof JAXBBlockImpl) {
View Full Code Here

Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

       
        if (omElement instanceof OMSourcedElement) {
           
            if ( ((OMSourcedElement) omElement).getDataSource() instanceof JAXBDataSource) {
                JAXBDataSource ds = (JAXBDataSource) ((OMSourcedElement)omElement).getDataSource();
                JAXBDSContext dsContext = ds.getContext();
                try {
                    if (dsContext.getJAXBContext() == ((JAXBBlockContext)context).getJAXBContext()) {
                        // Shortcut, use existing JAXB object
                        Object jaxb = ds.getObject();
                        return new JAXBBlockImpl(jaxb, (JAXBBlockContext)context, qName, this);
                    }
                } catch (JAXBException e) {
View Full Code Here

Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

        StringReader sr = new StringReader(sampleJAXBEnvelope);
        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
        StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
        OMElement omElement = builder.getSOAPEnvelope();
       
        JAXBDSContext jds = null;
        if (installJAXBCustomBuilder) {
            jds = new JAXBDSContext(EchoStringResponse.class.getPackage().getName());
            JAXBCustomBuilder jcb = new JAXBCustomBuilder(jds);
            builder.registerCustomBuilderForPayload(jcb);
        }
       
        // Create a SOAP 1.1 Message from the sample incoming XML
        MessageFactory mf = (MessageFactory)
            FactoryRegistry.getFactory(MessageFactory.class);
        Message m = mf.createFrom(omElement, null);
       
        // Check to see if the message is a fault.  The client/server will always call this method.
        // The Message must respond appropriately without doing a conversion.
        boolean isFault = m.isFault();
        assertTrue(!isFault);
        assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
                    "OM".equals(m.getXMLPartContentType()));
       
        if (installJAXBCustomBuilder) {
            // The JAXBDSContext and the JAXBUtils access the JAXBContext
            // for the "test" package.
            // The JAXBContext creation is very expensive.
            // However the JAXBContext can also be very large.
            //
            // For these reasons, the JAXBUtils code caches the JAXBContext values.
            // And, the JAXBDSContext and JAXBUtils code use WeakReferences to refer
            // to the JAXBContext (so that it is easily gc'd).
           
            // The following code checks makes sure that the caching and gc is correct.
           
            // Get the JAXBContext
            JAXBContext context = jds.getJAXBContext();
           
            // Get the identity hash code.  This is an indicator of the unique memory pointer
            // for the context.
            int contextPointer = System.identityHashCode(context);
           
View Full Code Here

Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

        // 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);
       
View Full Code Here

Examples of org.apache.axis2.datasource.jaxb.JAXBDSContext

        // 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(), null);
        OMElement om = omFactory.createOMElement(ds, expectedQName.getLocalPart(), ns);
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.