Java Code Examples for org.xml.sax.Attributes#getIndex()

The following examples show how to use org.xml.sax.Attributes#getIndex() . 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: SAXImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 2
Source File: SAXImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 3
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 4
Source File: SAXImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 5
Source File: SAXImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 6
Source File: SAXImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 7
Source File: SAXImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 8
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 9
Source File: SAXImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 10
Source File: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SAX2: Receive notification of the beginning of an element.
 */
public void startElement(String uri, String localName,
             String qname, Attributes attributes)
    throws SAXException
{
    super.startElement(uri, localName, qname, attributes);

    handleTextEscaping();

    if (m_wsfilter != null) {
        // Look for any xml:space attributes
        // Depending on the implementation of attributes, this
        // might be faster than looping through all attributes. ILENE
        final int index = attributes.getIndex(XMLSPACE_STRING);
        if (index >= 0) {
            xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
        }
    }
}
 
Example 11
Source File: Bug4970951.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    XMLReader xmlReader = createXMLReader();
    final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
    xmlReader.setContentHandler(validatorHandler);

    DefaultHandler handler = new DefaultHandler() {
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            if (!"ns:test".equals(qName)) {
                return;
            }

            TypeInfoProvider infoProvider = validatorHandler.getTypeInfoProvider();
            if (infoProvider == null) {
                throw new SAXException("Can't obtain TypeInfoProvider object.");
            }

            int index = attributes.getIndex("id");
            if (index == -1) {
                throw new SAXException("The attribute 'id' is not in the list.");
            }

            Assert.assertTrue(infoProvider.isSpecified(index));

            index = attributes.getIndex("date");
            if (index == -1) {
                throw new SAXException("The attribute 'date' is not in the list.");
            }

            Assert.assertFalse(infoProvider.isSpecified(index));

            System.out.println("OK");
        }
    };
    validatorHandler.setContentHandler(handler);

    parse(xmlReader, XML);
}
 
Example 12
Source File: TypeInfoProviderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    TypeInfoProvider typeInfoProvider = validatorHandler.getTypeInfoProvider();
    int index = atts.getIndex("orderid");
    if (index != -1) {
        System.out.println(" Index " + index);
        System.out.println(" ElementType " + typeInfoProvider.getElementTypeInfo().getTypeName());
        assertEquals(typeInfoProvider.getAttributeTypeInfo(index).getTypeName(), "string");
        assertTrue(typeInfoProvider.isSpecified(index));
        assertFalse(typeInfoProvider.isIdAttribute(index));
    }

}
 
Example 13
Source File: XsiTypeLoader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 14
Source File: XsiTypeLoader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 15
Source File: XsiTypeLoader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 16
Source File: XsiTypeLoader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 17
Source File: XsiTypeLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 18
Source File: XsiTypeLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 19
Source File: XsiTypeLoader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}
 
Example 20
Source File: XsiTypeLoader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException {
    UnmarshallingContext context = state.getContext();
    JaxBeanInfo beanInfo = null;

    // look for @xsi:type
    Attributes atts = ea.atts;
    int idx = atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"type");

    if(idx>=0) {
        // we'll consume the value only when it's a recognized value,
        // so don't consume it just yet.
        String value = atts.getValue(idx);

        QName type = DatatypeConverterImpl._parseQName(value,context);
        if(type==null) {
            reportError(Messages.NOT_A_QNAME.format(value),true);
        } else {
            if(defaultBeanInfo!=null && defaultBeanInfo.getTypeNames().contains(type))
                // if this xsi:type is something that the default type can already handle,
                // let it do so. This is added as a work around to bug https://jax-ws.dev.java.net/issues/show_bug.cgi?id=195
                // where a redundant xsi:type="xs:dateTime" causes JAXB to unmarshal XMLGregorianCalendar,
                // where Date is expected.
                // this is not a complete fix, as we still won't be able to handle simple type substitution in general,
                // but none-the-less
                return defaultBeanInfo;

            beanInfo = context.getJAXBContext().getGlobalType(type);
            if(beanInfo==null) { // let's report an error
                if (context.parent.hasEventHandler() // is somebody listening?
                        && context.shouldErrorBeReported()) { // should we report error?
                    String nearest = context.getJAXBContext().getNearestTypeName(type);
                    if(nearest!=null)
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME_MAYBE.format(type,nearest),true);
                    else
                        reportError(Messages.UNRECOGNIZED_TYPE_NAME.format(type),true);
                }
            }
            // TODO: resurrect the following check
    //                    else
    //                    if(!target.isAssignableFrom(actual)) {
    //                        reportError(context,
    //                            Messages.UNSUBSTITUTABLE_TYPE.format(value,actual.getName(),target.getName()),
    //                            true);
    //                        actual = targetBeanInfo;  // ditto
    //                    }
        }
    }
    return beanInfo;
}