com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo Java Examples

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnmarshallerImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public final Object unmarshal0( Node node, JaxBeanInfo expectedType ) throws JAXBException {
    try {
        final DOMScanner scanner = new DOMScanner();

        InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType));
        scanner.setContentHandler(new SAXConnector(handler,scanner));

        if(node.getNodeType() == Node.ELEMENT_NODE) {
            scanner.scan((Element)node);
        } else if(node.getNodeType() == Node.DOCUMENT_NODE) {
            scanner.scan((Document)node);
        } else {
            throw new IllegalArgumentException("Unexpected node type: "+node);
        }

        Object retVal = handler.getContext().getResult();
        handler.getContext().clearResult();
        return retVal;
    } catch( SAXException e ) {
        throw createUnmarshalException(e);
    }
}
 
Example #2
Source File: ArrayReferenceNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException {
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(isMixed && item.getClass()==String.class) {
                    w.text((String)item,null);
                } else {
                    JaxBeanInfo bi = w.grammar.getBeanInfo(item,true);
                    if(bi.jaxbType==Object.class && domHandler!=null)
                        // even if 'v' is a DOM node, it always derive from Object,
                        // so the getBeanInfo returns BeanInfo for Object
                        w.writeDom(item,domHandler,o,fieldName);
                    else
                        bi.serializeRoot(item,w);
                }
            }
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this item
        }
    }
}
 
Example #3
Source File: UnmarshallerImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public final Object unmarshal0( Node node, JaxBeanInfo expectedType ) throws JAXBException {
    try {
        final DOMScanner scanner = new DOMScanner();

        InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType));
        scanner.setContentHandler(new SAXConnector(handler,scanner));

        if(node.getNodeType() == Node.ELEMENT_NODE) {
            scanner.scan((Element)node);
        } else if(node.getNodeType() == Node.DOCUMENT_NODE) {
            scanner.scan((Document)node);
        } else {
            throw new IllegalArgumentException("Unexpected node type: "+node);
        }

        Object retVal = handler.getContext().getResult();
        handler.getContext().clearResult();
        return retVal;
    } catch( SAXException e ) {
        throw createUnmarshalException(e);
    }
}
 
Example #4
Source File: ArrayReferenceNodeProperty.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ArrayReferenceNodeProperty(JAXBContextImpl p, RuntimeReferencePropertyInfo prop) {
    super(p, prop, prop.getXmlName(), prop.isCollectionNillable());

    for (RuntimeElement e : prop.getElements()) {
        JaxBeanInfo bi = p.getOrCreate(e);
        expectedElements.put( e.getElementName().getNamespaceURI(),e.getElementName().getLocalPart(), bi );
    }

    isMixed = prop.isMixed();

    if(prop.getWildcard()!=null) {
        domHandler = (DomHandler) ClassFactory.create(prop.getDOMHandler());
        wcMode = prop.getWildcard();
    } else {
        domHandler = null;
        wcMode = null;
    }
}
 
Example #5
Source File: UnmarshallingContext.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Receives the root element and determines how to start
 * unmarshalling.
 */
@Override
public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    Loader loader = state.getContext().selectRootLoader(state,ea);
    if(loader!=null) {
        state.loader = loader;
        state.receiver = this;
        return;
    }

    // the registry doesn't know about this element.
    // try its xsi:type
    JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null);
    if(beanInfo==null) {
        // we don't even know its xsi:type
        reportUnexpectedChildElement(ea,false);
        return;
    }

    state.loader = beanInfo.getLoader(null,false);
    state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null);
    state.receiver = this;
}
 
Example #6
Source File: UnmarshallerImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and configures a new unmarshalling pipe line.
 * Depending on the setting, we put a validator as a filter.
 *
 * @return
 *      A component that implements both {@link UnmarshallerHandler}
 *      and {@link ValidationEventHandler}. All the parsing errors
 *      should be reported to this error handler for the unmarshalling
 *      process to work correctly.
 *
 *      Also, returned handler expects all the XML names to be interned.
 *
 */
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType ) {

    coordinator.reset(scanner,inplace,expectedType,idResolver);
    XmlVisitor unmarshaller = coordinator;

    // delegate to JAXP 1.3 for validation if the client provided a schema
    if (schema != null) {
        unmarshaller = new ValidatingUnmarshaller(schema,unmarshaller);
    }

    if(attachmentUnmarshaller!=null && attachmentUnmarshaller.isXOPPackage()) {
        unmarshaller = new MTOMDecorator(this,unmarshaller,attachmentUnmarshaller);
    }

    return unmarshaller;
}
 
Example #7
Source File: ArrayReferenceNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void createBodyUnmarshaller(UnmarshallerChain chain, QNameMap<ChildLoader> loaders) {
    final int offset = chain.allocateOffset();

    Receiver recv = new ReceiverImpl(offset);

    for( QNameMap.Entry<JaxBeanInfo> n : expectedElements.entrySet() ) {
        final JaxBeanInfo beanInfo = n.getValue();
        loaders.put(n.nsUri,n.localName,new ChildLoader(beanInfo.getLoader(chain.context,true),recv));
    }

    if(isMixed) {
        // handler for processing mixed contents.
        loaders.put(TEXT_HANDLER,
            new ChildLoader(new MixedTextLoader(recv),null));
    }

    if(domHandler!=null) {
        loaders.put(CATCH_ALL,
            new ChildLoader(new WildcardLoader(domHandler,wcMode),recv));
    }
}
 
Example #8
Source File: SingleElementNodeProperty.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public SingleElementNodeProperty(JAXBContextImpl context, RuntimeElementPropertyInfo prop) {
    super(context,prop);
    acc = prop.getAccessor().optimize(context);
    this.prop = prop;

    QName nt = null;
    boolean nil = false;

    acceptedElements = new QName[prop.getTypes().size()];
    for( int i=0; i<acceptedElements.length; i++ )
        acceptedElements[i] = prop.getTypes().get(i).getTagName();

    for (RuntimeTypeRef e : prop.getTypes()) {
        JaxBeanInfo beanInfo = context.getOrCreate(e.getTarget());
        if(nt==null)    nt = e.getTagName();
        typeNames.put( beanInfo.jaxbType, new TagAndType(
            context.nameBuilder.createElementName(e.getTagName()),beanInfo) );
        nil |= e.isNillable();
    }

    nullTagName = context.nameBuilder.createElementName(nt);

    nillable = nil;
}
 
Example #9
Source File: ArrayReferenceNodeProperty.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException {
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(isMixed && item.getClass()==String.class) {
                    w.text((String)item,null);
                } else {
                    JaxBeanInfo bi = w.grammar.getBeanInfo(item,true);
                    if(bi.jaxbType==Object.class && domHandler!=null)
                        // even if 'v' is a DOM node, it always derive from Object,
                        // so the getBeanInfo returns BeanInfo for Object
                        w.writeDom(item,domHandler,o,fieldName);
                    else
                        bi.serializeRoot(item,w);
                }
            }
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this item
        }
    }
}
 
Example #10
Source File: ArrayReferenceNodeProperty.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public ArrayReferenceNodeProperty(JAXBContextImpl p, RuntimeReferencePropertyInfo prop) {
    super(p, prop, prop.getXmlName(), prop.isCollectionNillable());

    for (RuntimeElement e : prop.getElements()) {
        JaxBeanInfo bi = p.getOrCreate(e);
        expectedElements.put( e.getElementName().getNamespaceURI(),e.getElementName().getLocalPart(), bi );
    }

    isMixed = prop.isMixed();

    if(prop.getWildcard()!=null) {
        domHandler = (DomHandler) ClassFactory.create(prop.getDOMHandler());
        wcMode = prop.getWildcard();
    } else {
        domHandler = null;
        wcMode = null;
    }
}
 
Example #11
Source File: ArrayReferenceNodeProperty.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException {
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(isMixed && item.getClass()==String.class) {
                    w.text((String)item,null);
                } else {
                    JaxBeanInfo bi = w.grammar.getBeanInfo(item,true);
                    if(bi.jaxbType==Object.class && domHandler!=null)
                        // even if 'v' is a DOM node, it always derive from Object,
                        // so the getBeanInfo returns BeanInfo for Object
                        w.writeDom(item,domHandler,o,fieldName);
                    else
                        bi.serializeRoot(item,w);
                }
            }
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this item
        }
    }
}
 
Example #12
Source File: ArrayReferenceNodeProperty.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void createBodyUnmarshaller(UnmarshallerChain chain, QNameMap<ChildLoader> loaders) {
    final int offset = chain.allocateOffset();

    Receiver recv = new ReceiverImpl(offset);

    for( QNameMap.Entry<JaxBeanInfo> n : expectedElements.entrySet() ) {
        final JaxBeanInfo beanInfo = n.getValue();
        loaders.put(n.nsUri,n.localName,new ChildLoader(beanInfo.getLoader(chain.context,true),recv));
    }

    if(isMixed) {
        // handler for processing mixed contents.
        loaders.put(TEXT_HANDLER,
            new ChildLoader(new MixedTextLoader(recv),null));
    }

    if(domHandler!=null) {
        loaders.put(CATCH_ALL,
            new ChildLoader(new WildcardLoader(domHandler,wcMode),recv));
    }
}
 
Example #13
Source File: UnmarshallingContext.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Receives the root element and determines how to start
 * unmarshalling.
 */
@Override
public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    Loader loader = state.getContext().selectRootLoader(state,ea);
    if(loader!=null) {
        state.loader = loader;
        state.receiver = this;
        return;
    }

    // the registry doesn't know about this element.
    // try its xsi:type
    JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null);
    if(beanInfo==null) {
        // we don't even know its xsi:type
        reportUnexpectedChildElement(ea,false);
        return;
    }

    state.loader = beanInfo.getLoader(null,false);
    state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null);
    state.receiver = this;
}
 
Example #14
Source File: UnmarshallingContext.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Receives the root element and determines how to start
 * unmarshalling.
 */
@Override
public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    Loader loader = state.getContext().selectRootLoader(state,ea);
    if(loader!=null) {
        state.loader = loader;
        state.receiver = this;
        return;
    }

    // the registry doesn't know about this element.
    // try its xsi:type
    JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null);
    if(beanInfo==null) {
        // we don't even know its xsi:type
        reportUnexpectedChildElement(ea,false);
        return;
    }

    state.loader = beanInfo.getLoader(null,false);
    state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null);
    state.receiver = this;
}
 
Example #15
Source File: UnmarshallerImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and configures a new unmarshalling pipe line.
 * Depending on the setting, we put a validator as a filter.
 *
 * @return
 *      A component that implements both {@link UnmarshallerHandler}
 *      and {@link ValidationEventHandler}. All the parsing errors
 *      should be reported to this error handler for the unmarshalling
 *      process to work correctly.
 *
 *      Also, returned handler expects all the XML names to be interned.
 *
 */
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType ) {

    coordinator.reset(scanner,inplace,expectedType,idResolver);
    XmlVisitor unmarshaller = coordinator;

    // delegate to JAXP 1.3 for validation if the client provided a schema
    if (schema != null) {
        unmarshaller = new ValidatingUnmarshaller(schema,unmarshaller);
    }

    if(attachmentUnmarshaller!=null && attachmentUnmarshaller.isXOPPackage()) {
        unmarshaller = new MTOMDecorator(this,unmarshaller,attachmentUnmarshaller);
    }

    return unmarshaller;
}
 
Example #16
Source File: ArrayElementProperty.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected ArrayElementProperty(JAXBContextImpl grammar, RuntimeElementPropertyInfo prop) {
    super(grammar, prop, prop.getXmlName(), prop.isCollectionNillable());
    this.prop = prop;

    List<? extends RuntimeTypeRef> types = prop.getTypes();

    Name n = null;

    for (RuntimeTypeRef typeRef : types) {
        Class type = (Class)typeRef.getTarget().getType();
        if(type.isPrimitive())
            type = RuntimeUtil.primitiveToBox.get(type);

        JaxBeanInfo beanInfo = grammar.getOrCreate(typeRef.getTarget());
        TagAndType tt = new TagAndType(
                            grammar.nameBuilder.createElementName(typeRef.getTagName()),
                            beanInfo);
        typeMap.put(type,tt);
        refs.put(typeRef,beanInfo);
        if(typeRef.isNillable() && n==null)
            n = tt.tagName;
    }

    nillableTagName = n;
}
 
Example #17
Source File: UnmarshallerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and configures a new unmarshalling pipe line.
 * Depending on the setting, we put a validator as a filter.
 *
 * @return
 *      A component that implements both {@link UnmarshallerHandler}
 *      and {@link ValidationEventHandler}. All the parsing errors
 *      should be reported to this error handler for the unmarshalling
 *      process to work correctly.
 *
 *      Also, returned handler expects all the XML names to be interned.
 *
 */
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType ) {

    coordinator.reset(scanner,inplace,expectedType,idResolver);
    XmlVisitor unmarshaller = coordinator;

    // delegate to JAXP 1.3 for validation if the client provided a schema
    if (schema != null) {
        unmarshaller = new ValidatingUnmarshaller(schema,unmarshaller);
    }

    if(attachmentUnmarshaller!=null && attachmentUnmarshaller.isXOPPackage()) {
        unmarshaller = new MTOMDecorator(this,unmarshaller,attachmentUnmarshaller);
    }

    return unmarshaller;
}
 
Example #18
Source File: SingleElementNodeProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public SingleElementNodeProperty(JAXBContextImpl context, RuntimeElementPropertyInfo prop) {
    super(context,prop);
    acc = prop.getAccessor().optimize(context);
    this.prop = prop;

    QName nt = null;
    boolean nil = false;

    acceptedElements = new QName[prop.getTypes().size()];
    for( int i=0; i<acceptedElements.length; i++ )
        acceptedElements[i] = prop.getTypes().get(i).getTagName();

    for (RuntimeTypeRef e : prop.getTypes()) {
        JaxBeanInfo beanInfo = context.getOrCreate(e.getTarget());
        if(nt==null)    nt = e.getTagName();
        typeNames.put( beanInfo.jaxbType, new TagAndType(
            context.nameBuilder.createElementName(e.getTagName()),beanInfo) );
        nil |= e.isNillable();
    }

    nullTagName = context.nameBuilder.createElementName(nt);

    nillable = nil;
}
 
Example #19
Source File: SingleElementNodeProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public SingleElementNodeProperty(JAXBContextImpl context, RuntimeElementPropertyInfo prop) {
    super(context,prop);
    acc = prop.getAccessor().optimize(context);
    this.prop = prop;

    QName nt = null;
    boolean nil = false;

    acceptedElements = new QName[prop.getTypes().size()];
    for( int i=0; i<acceptedElements.length; i++ )
        acceptedElements[i] = prop.getTypes().get(i).getTagName();

    for (RuntimeTypeRef e : prop.getTypes()) {
        JaxBeanInfo beanInfo = context.getOrCreate(e.getTarget());
        if(nt==null)    nt = e.getTagName();
        typeNames.put( beanInfo.jaxbType, new TagAndType(
            context.nameBuilder.createElementName(e.getTagName()),beanInfo) );
        nil |= e.isNillable();
    }

    nullTagName = context.nameBuilder.createElementName(nt);

    nillable = nil;
}
 
Example #20
Source File: ArrayReferenceNodeProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public ArrayReferenceNodeProperty(JAXBContextImpl p, RuntimeReferencePropertyInfo prop) {
    super(p, prop, prop.getXmlName(), prop.isCollectionNillable());

    for (RuntimeElement e : prop.getElements()) {
        JaxBeanInfo bi = p.getOrCreate(e);
        expectedElements.put( e.getElementName().getNamespaceURI(),e.getElementName().getLocalPart(), bi );
    }

    isMixed = prop.isMixed();

    if(prop.getWildcard()!=null) {
        domHandler = (DomHandler) ClassFactory.create(prop.getDOMHandler());
        wcMode = prop.getWildcard();
    } else {
        domHandler = null;
        wcMode = null;
    }
}
 
Example #21
Source File: ArrayElementProperty.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected ArrayElementProperty(JAXBContextImpl grammar, RuntimeElementPropertyInfo prop) {
    super(grammar, prop, prop.getXmlName(), prop.isCollectionNillable());
    this.prop = prop;

    List<? extends RuntimeTypeRef> types = prop.getTypes();

    Name n = null;

    for (RuntimeTypeRef typeRef : types) {
        Class type = (Class)typeRef.getTarget().getType();
        if(type.isPrimitive())
            type = RuntimeUtil.primitiveToBox.get(type);

        JaxBeanInfo beanInfo = grammar.getOrCreate(typeRef.getTarget());
        TagAndType tt = new TagAndType(
                            grammar.nameBuilder.createElementName(typeRef.getTagName()),
                            beanInfo);
        typeMap.put(type,tt);
        refs.put(typeRef,beanInfo);
        if(typeRef.isNillable() && n==null)
            n = tt.tagName;
    }

    nillableTagName = n;
}
 
Example #22
Source File: ArrayReferenceNodeProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void createBodyUnmarshaller(UnmarshallerChain chain, QNameMap<ChildLoader> loaders) {
    final int offset = chain.allocateOffset();

    Receiver recv = new ReceiverImpl(offset);

    for( QNameMap.Entry<JaxBeanInfo> n : expectedElements.entrySet() ) {
        final JaxBeanInfo beanInfo = n.getValue();
        loaders.put(n.nsUri,n.localName,new ChildLoader(beanInfo.getLoader(chain.context,true),recv));
    }

    if(isMixed) {
        // handler for processing mixed contents.
        loaders.put(TEXT_HANDLER,
            new ChildLoader(new MixedTextLoader(recv),null));
    }

    if(domHandler!=null) {
        loaders.put(CATCH_ALL,
            new ChildLoader(new WildcardLoader(domHandler,wcMode),recv));
    }
}
 
Example #23
Source File: ArrayReferenceNodeProperty.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void createBodyUnmarshaller(UnmarshallerChain chain, QNameMap<ChildLoader> loaders) {
    final int offset = chain.allocateOffset();

    Receiver recv = new ReceiverImpl(offset);

    for( QNameMap.Entry<JaxBeanInfo> n : expectedElements.entrySet() ) {
        final JaxBeanInfo beanInfo = n.getValue();
        loaders.put(n.nsUri,n.localName,new ChildLoader(beanInfo.getLoader(chain.context,true),recv));
    }

    if(isMixed) {
        // handler for processing mixed contents.
        loaders.put(TEXT_HANDLER,
            new ChildLoader(new MixedTextLoader(recv),null));
    }

    if(domHandler!=null) {
        loaders.put(CATCH_ALL,
            new ChildLoader(new WildcardLoader(domHandler,wcMode),recv));
    }
}
 
Example #24
Source File: UnmarshallingContext.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Receives the root element and determines how to start
 * unmarshalling.
 */
@Override
public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    Loader loader = state.getContext().selectRootLoader(state,ea);
    if(loader!=null) {
        state.loader = loader;
        state.receiver = this;
        return;
    }

    // the registry doesn't know about this element.
    // try its xsi:type
    JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null);
    if(beanInfo==null) {
        // we don't even know its xsi:type
        reportUnexpectedChildElement(ea,false);
        return;
    }

    state.loader = beanInfo.getLoader(null,false);
    state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null);
    state.receiver = this;
}
 
Example #25
Source File: SingleReferenceNodeProperty.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        try {
            JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
            if(bi.jaxbType==Object.class && domHandler!=null)
                // even if 'v' is a DOM node, it always derive from Object,
                // so the getBeanInfo returns BeanInfo for Object
                w.writeDom(v,domHandler,o,fieldName);
            else
                bi.serializeRoot(v,w);
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this property
        }
    }
}
 
Example #26
Source File: UnmarshallingContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Receives the root element and determines how to start
 * unmarshalling.
 */
@Override
public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    Loader loader = state.getContext().selectRootLoader(state,ea);
    if(loader!=null) {
        state.loader = loader;
        state.receiver = this;
        return;
    }

    // the registry doesn't know about this element.
    // try its xsi:type
    JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null);
    if(beanInfo==null) {
        // we don't even know its xsi:type
        reportUnexpectedChildElement(ea,false);
        return;
    }

    state.loader = beanInfo.getLoader(null,false);
    state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null);
    state.receiver = this;
}
 
Example #27
Source File: ArrayElementProperty.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected ArrayElementProperty(JAXBContextImpl grammar, RuntimeElementPropertyInfo prop) {
    super(grammar, prop, prop.getXmlName(), prop.isCollectionNillable());
    this.prop = prop;

    List<? extends RuntimeTypeRef> types = prop.getTypes();

    Name n = null;

    for (RuntimeTypeRef typeRef : types) {
        Class type = (Class)typeRef.getTarget().getType();
        if(type.isPrimitive())
            type = RuntimeUtil.primitiveToBox.get(type);

        JaxBeanInfo beanInfo = grammar.getOrCreate(typeRef.getTarget());
        TagAndType tt = new TagAndType(
                            grammar.nameBuilder.createElementName(typeRef.getTagName()),
                            beanInfo);
        typeMap.put(type,tt);
        refs.put(typeRef,beanInfo);
        if(typeRef.isNillable() && n==null)
            n = tt.tagName;
    }

    nillableTagName = n;
}
 
Example #28
Source File: UnmarshallerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public final Object unmarshal0( Node node, JaxBeanInfo expectedType ) throws JAXBException {
    try {
        final DOMScanner scanner = new DOMScanner();

        InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType));
        scanner.setContentHandler(new SAXConnector(handler,scanner));

        if(node.getNodeType() == Node.ELEMENT_NODE) {
            scanner.scan((Element)node);
        } else if(node.getNodeType() == Node.DOCUMENT_NODE) {
            scanner.scan((Document)node);
        } else {
            throw new IllegalArgumentException("Unexpected node type: "+node);
        }

        Object retVal = handler.getContext().getResult();
        handler.getContext().clearResult();
        return retVal;
    } catch( SAXException e ) {
        throw createUnmarshalException(e);
    }
}
 
Example #29
Source File: SingleReferenceNodeProperty.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        try {
            JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
            if(bi.jaxbType==Object.class && domHandler!=null)
                // even if 'v' is a DOM node, it always derive from Object,
                // so the getBeanInfo returns BeanInfo for Object
                w.writeDom(v,domHandler,o,fieldName);
            else
                bi.serializeRoot(v,w);
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this property
        }
    }
}
 
Example #30
Source File: ArrayReferenceNodeProperty.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public ArrayReferenceNodeProperty(JAXBContextImpl p, RuntimeReferencePropertyInfo prop) {
    super(p, prop, prop.getXmlName(), prop.isCollectionNillable());

    for (RuntimeElement e : prop.getElements()) {
        JaxBeanInfo bi = p.getOrCreate(e);
        expectedElements.put( e.getElementName().getNamespaceURI(),e.getElementName().getLocalPart(), bi );
    }

    isMixed = prop.isMixed();

    if(prop.getWildcard()!=null) {
        domHandler = (DomHandler) ClassFactory.create(prop.getDOMHandler());
        wcMode = prop.getWildcard();
    } else {
        domHandler = null;
        wcMode = null;
    }
}