Examples of JAXBIntrospector


Examples of javax.xml.bind.JAXBIntrospector

        }

        // Create a JAX-B context, and use this to generate us a bunch of
        // schema objects

        JAXBIntrospector introspector = null;

        try {
            JAXBContext context = JAXBContext.newInstance(classSet.toArray(new Class[classSet.size()]));

            final List<StreamResult> results = new ArrayList<StreamResult>();

            context.generateSchema(new SchemaOutputResolver() {

                int counter = 0;

                @Override
                public Result createOutput(String namespaceUri, String suggestedFileName) {
                    StreamResult result = new StreamResult(new CharArrayWriter());
                    result.setSystemId("xsd" + (counter++) + ".xsd");
                    results.add(result);
                    return result;
                }
            });

            // Store the new files for later use
            //

            for (StreamResult result : results) {
                CharArrayWriter writer = (CharArrayWriter) result.getWriter();
                byte[] contents = writer.toString().getBytes("UTF8");
                extraFiles.put(
                        result.getSystemId(),
                        new ApplicationDescription.ExternalGrammar(
                                MediaType.APPLICATION_XML_TYPE, // I don't think there is a specific media type for XML Schema
                                contents));
            }

            // Create an introspector
            //

            introspector = context.createJAXBIntrospector();


        } catch (JAXBException e) {
            LOGGER.log(Level.SEVERE, "Failed to generate the schema for the JAX-B elements", e);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Failed to generate the schema for the JAX-B elements due to an IO error", e);
        }

        // Create introspector

        if (introspector != null) {
            final JAXBIntrospector copy = introspector;

            return new Resolver() {

                public QName resolve(final Class type) {

                    Object parameterClassInstance = null;
                    try {
                        final Constructor<?> defaultConstructor =
                                AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>() {
                                    @SuppressWarnings("unchecked")
                                    @Override
                                    public Constructor<?> run() throws NoSuchMethodException {
                                        final Constructor<?> constructor = type.getDeclaredConstructor();
                                        constructor.setAccessible(true);
                                        return constructor;
                                    }
                                });
                        parameterClassInstance = defaultConstructor.newInstance();
                    } catch (InstantiationException ex) {
                        LOGGER.log(Level.FINE, null, ex);
                    } catch (IllegalAccessException ex) {
                        LOGGER.log(Level.FINE, null, ex);
                    } catch (IllegalArgumentException ex) {
                        LOGGER.log(Level.FINE, null, ex);
                    } catch (InvocationTargetException ex) {
                        LOGGER.log(Level.FINE, null, ex);
                    } catch (SecurityException ex) {
                        LOGGER.log(Level.FINE, null, ex);
                    } catch (PrivilegedActionException ex) {
                        LOGGER.log(Level.FINE, null, ex.getCause());
                    }

                    if (parameterClassInstance == null) {
                        return null;
                    }

                    try {
                        return copy.getElementName(parameterClassInstance);
                    } catch (NullPointerException e) {
                        // EclipseLink throws an NPE if an object annotated with @XmlType and without the @XmlRootElement
                        // annotation is passed as a parameter of #getElementName method.
                        return null;
                    }
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

     * @param jaxb
     * @param jbc
     * @throws WebServiceException
     */
    private static QName getQName(Object jaxb, JAXBBlockContext ctx) throws JAXBException {
        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(ctx.getJAXBContext());
        QName qName = jbi.getElementName(jaxb);
        JAXBUtils.releaseJAXBIntrospector(ctx.getJAXBContext(), jbi);
        return qName;
    }
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

     * @param context JAXBContext
     * @return JAXBIntrospector
     * @throws JAXBException
     */
    public static JAXBIntrospector getJAXBIntrospector(JAXBContext context) throws JAXBException {
        JAXBIntrospector i = null;
        if (!ENABLE_ADV_POOLING) {
            if (log.isDebugEnabled()) {
                log.debug("JAXBIntrospector created [no pooling]");
            }
            i = context.createJAXBIntrospector();
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

        ObjectFactory factory = new ObjectFactory();
        EchoString jaxb = factory.createEchoString();
        jaxb.setInput("Hello World");
        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
      
        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
        QName expectedQName = jbi.getElementName(jaxb);
       
    // Create a Block using the sample string as the content.  This simulates
    // what occurs on the outbound JAX-WS dispatch<JAXB> client
    Block block = f.createFrom(jaxb, context, null);
   
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

        ObjectFactory factory = new ObjectFactory();
        EchoString jaxb = factory.createEchoString();
        jaxb.setInput("Hello World");
        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
       
        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
        QName expectedQName = jbi.getElementName(jaxb);
       
    // Create a Block using the sample string as the content.  This simulates
    // what occurs with an outbound JAX-WS JAXB parameter
    Block block = f.createFrom(jaxb, context, expectedQName);
   
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

        ObjectFactory factory = new ObjectFactory();
        EchoString jaxb = factory.createEchoString();
        jaxb.setInput("Hello World");
        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());

        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
        QName expectedQName = jbi.getElementName(jaxb);
   
    // On inbound, there will already be a XMLStreamReader (probably from OM)
    // which represents the message.  We will simulate this with inflow.
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

        ObjectFactory factory = new ObjectFactory();
        EchoString jaxb = factory.createEchoString();
        jaxb.setInput("Hello World");
        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
       
        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
        QName expectedQName = jbi.getElementName(jaxb);
   
    // On inbound, there will already be a XMLStreamReader (probably from OM)
    // which represents the message.  We will simulate this with inflow.
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

     * @param context JAXBContext
     * @return JAXBIntrospector
     * @throws JAXBException
     */
    public static JAXBIntrospector getJAXBIntrospector(final JAXBContext context) throws JAXBException {
        JAXBIntrospector i = null;
        if (!ENABLE_INTROSPECTION_POOLING) {
            if (log.isDebugEnabled()) {
                log.debug("JAXBIntrospector created [no pooling]");
            }
            i = internalCreateIntrospector(context);
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

        }
        return i;
    }

    private static JAXBIntrospector internalCreateIntrospector(final JAXBContext context) {
        JAXBIntrospector i;
        i = (JAXBIntrospector) AccessController.doPrivileged(
                new PrivilegedAction() {
                    public Object run() {
                        return context.createJAXBIntrospector();
                    }
View Full Code Here

Examples of javax.xml.bind.JAXBIntrospector

            } else {
                type = Object.class;
            }
        }

        JAXBIntrospector introspector = context.createJAXBIntrospector();
        Object element = null;
        if (value != null && introspector.isElement(value)) {
            // NOTE: [rfeng] We cannot wrap an element in a JAXBElement
            element = value;
        }
        if (element == null) {
            element = new JAXBElement(name, type, value);
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.