Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.SchemaType


        ret = typeSystem.findType(qn).getFullJavaName();
        return ret.replace('$', '.');
    }

    public String getWrappedElementType(QName wrapperElement, QName item) {       
        SchemaType st = typeSystem.findElement(wrapperElement).getType();
        SchemaType partType = st.getElementProperty(item).getType();       
        return XMLBeansSchemaTypeUtils.getNaturalJavaClassName(partType);       
    }
View Full Code Here


                      SymbolTable st )
   throws IOException
   {
      try
      {
         SchemaType schemaType   = getResourcePropsDocSchemaType( emitter );
         QName[]    metricQNames = getMetricQNames( schemaType );

         writeGetMetricQNamesMethod( pw, schemaType, metricQNames );
      }
      catch ( Exception e )
View Full Code Here

                      SymbolTable symTable )
   throws IOException
   {
      try
      {
         SchemaType schemaType = getResourcePropsDocSchemaType( emitter );

         writeBackendResetMetricMethod( pw,
                                        schemaType,
                                        getMetricQNames( schemaType ) );
      }
View Full Code Here

      String      innerClassname =
         resourcePropsClassName.substring( 0, lastPeriod ) + "$"
         + resourcePropsClassName.substring( lastPeriod + 1 );

      Class      propClass  = xmlBeanClassLoader.loadClass( innerClassname );
      SchemaType schemaType = (SchemaType) propClass.getField( "type" ).get( null );

      return schemaType;
   }
View Full Code Here

               
                Class<?> cls[] = typeClass.getDeclaredClasses();
                for (Class<?> c : cls) {
                    if ("Factory".equals(c.getSimpleName())) {
                        try {
                            SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                            XmlOptions options = new XmlOptions();
                            if (schema != null) {
                                options.setValidateOnSet();
                            }
                            if (!st.isDocumentType()) {
                                options.setLoadReplaceDocumentElement(null);
                            }
                            Method meth = c.getMethod("newValue", Object.class);
                            obj = meth.invoke(null, obj);
                            break;
                        } catch (Exception e) {
                            throw new Fault("UNMARSHAL_ERROR", LOG, e, part.getTypeClass());
                        }
                    }
                }
            }

           
            if (obj != null) {
                XmlOptions options = new XmlOptions();
                if (schema != null) {
                    options.setValidateOnSet();
                }
                if (message != null
                    && MessageUtils.getContextualBoolean(message,
                                                      XmlBeansDataBinding.XMLBEANS_NAMESPACE_HACK,
                                                      false)) {
                    Object dom;
                    if (obj instanceof XmlObjectBase) {
                        XmlObjectBase source = (XmlObjectBase)obj;
                        dom = source.newDomNode(options);
                    } else {
                        XmlTokenSource source = (XmlTokenSource)obj;
                        dom = source.newDomNode(options);
                    }
                   
                    if (dom instanceof Document) {
                        org.w3c.dom.Element e = ((Document)dom).getDocumentElement();
                        StaxUtils.copy(e, output);
                    } else if (dom instanceof DocumentFragment) {
                        DocumentFragment frag = (DocumentFragment) dom;
                        Node node = frag.getFirstChild();
                        while (node != null) {
                            if (node instanceof Element) {
                                StaxUtils.copy((Element)node, output);
                            } else if (node instanceof Comment) {
                                output.writeComment(((Comment)node).getData());
                            } else if (node instanceof Text) {
                                output.writeCharacters(((Text)node).getData());
                            }
                            node = node.getNextSibling();
                        }
                    } else {
                        throw new Fault("Invalid document type returned: " + dom.toString(), LOG);
                    }
                    return;
                }
               
                XMLStreamReader reader;
                if (obj instanceof XmlObjectBase) {
                    XmlObjectBase source = (XmlObjectBase)obj;
                    reader = source.newCursorForce().newXMLStreamReader(options);
                } else {
                    XmlTokenSource source = (XmlTokenSource)obj;
                    reader = source.newCursor().newXMLStreamReader(options);                   
                }
                SchemaType st = part == null ? null
                    : (SchemaType)part.getProperty(SchemaType.class.getName());
                if (st == null) {
                    try {
                        Field f = typeClass.getField("type");
                        if (Modifier.isStatic(f.getModifiers())) {
                            st = (SchemaType)f.get(null);
                            if (part != null) {
                                part.setProperty(SchemaType.class.getName(), st);
                            }
                        }
                    } catch (Exception es) {
                        //ignore
                        es.printStackTrace();
                    }
                }
                int i = reader.getEventType();
                if (i == XMLStreamReader.START_DOCUMENT) {
                    i = reader.next();
                }
               
                if (st != null && !st.isDocumentType()
                    || reader.getEventType() == XMLStreamReader.CHARACTERS) {
                   
                    QName elementName = part != null ? part.getConcreteName() : st.getName();
                   
                    if (StringUtils.isEmpty(elementName.getNamespaceURI())) {
                        output.writeStartElement(elementName.getLocalPart());
                       
                    } else {
View Full Code Here

               
                Class<?> cls[] = typeClass.getDeclaredClasses();
                for (Class<?> c : cls) {
                    if ("Factory".equals(c.getSimpleName())) {
                        try {
                            SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                            XmlOptions options = new XmlOptions();
                            if (schema != null) {
                                options.setValidateOnSet();
                            }
                            if (!st.isDocumentType()) {
                                options.setLoadReplaceDocumentElement(null);
                            }
                            Method meth = c.getMethod("newValue", Object.class);
                            obj = meth.invoke(null, obj);
                            break;
                        } catch (Exception e) {
                            throw new Fault("UNMARSHAL_ERROR", LOG, e, part.getTypeClass());
                        }
                    }
                }
            }

           
            if (obj != null
                || !(part.getXmlSchema() instanceof XmlSchemaElement)) {
                XmlOptions options = new XmlOptions();
                if (schema != null) {
                    options.setValidateOnSet();
                }
                if (message != null
                    && MessageUtils.getContextualBoolean(message,
                                                      XmlBeansDataBinding.XMLBEANS_NAMESPACE_HACK,
                                                      false)) {
                    Object dom;
                    if (obj instanceof XmlObjectBase) {
                        XmlObjectBase source = (XmlObjectBase)obj;
                        dom = source.newDomNode(options);
                    } else {
                        XmlTokenSource source = (XmlTokenSource)obj;
                        dom = source.newDomNode(options);
                    }
                   
                    if (dom instanceof Document) {
                        org.w3c.dom.Element e = ((Document)dom).getDocumentElement();
                        StaxUtils.copy(e, output);
                    } else if (dom instanceof DocumentFragment) {
                        DocumentFragment frag = (DocumentFragment) dom;
                        Node node = frag.getFirstChild();
                        while (node != null) {
                            if (node instanceof Element) {
                                StaxUtils.copy((Element)node, output);
                            } else if (node instanceof Comment) {
                                output.writeComment(((Comment)node).getData());
                            } else if (node instanceof Text) {
                                output.writeCharacters(((Text)node).getData());
                            }
                            node = node.getNextSibling();
                        }
                    } else {
                        throw new Fault("Invalid document type returned: " + dom.toString(), LOG);
                    }
                    return;
                }
               
                XMLStreamReader reader;
                if (obj instanceof XmlObjectBase) {
                    XmlObjectBase source = (XmlObjectBase)obj;
                    reader = source.newCursorForce().newXMLStreamReader(options);
                } else {
                    XmlTokenSource source = (XmlTokenSource)obj;
                    reader = source.newCursor().newXMLStreamReader(options);                   
                }
                SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                int i = reader.getEventType();
                if (i == XMLStreamReader.START_DOCUMENT) {
                    i = reader.next();
                }
               
                if (st != null && !st.isDocumentType()
                    || reader.getEventType() == XMLStreamReader.CHARACTERS) {
                    if (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
                        output.writeStartElement(part.getConcreteName().getLocalPart());
                       
                    } else {
View Full Code Here

    {
        if ( xBean == null )
        {
            throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_PARAM_NOT_ALLOWED ) );
        }
        SchemaType docSchemaType;
        if ( isDocument( xBean ) )
        {
            docSchemaType = xBean.schemaType();
        }
        else
        {
            docSchemaType = xBean.schemaType().getOuterType();
        }

        QName name;
        if ( docSchemaType != null )
        {
            name = docSchemaType.getDocumentElementName();
        }
        else
        {
            XmlCursor xCursor = xBean.newCursor();
            name = getName( xCursor );
View Full Code Here

               
                Class<?> cls[] = typeClass.getDeclaredClasses();
                for (Class<?> c : cls) {
                    if ("Factory".equals(c.getSimpleName())) {
                        try {
                            SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                            XmlOptions options = new XmlOptions();
                            if (schema != null) {
                                options.setValidateOnSet();
                            }
                            if (!st.isDocumentType()) {
                                options.setLoadReplaceDocumentElement(null);
                            }
                            Method meth = c.getMethod("newValue", Object.class);
                            obj = meth.invoke(null, obj);
                            break;
                        } catch (Exception e) {
                            throw new Fault("UNMARSHAL_ERROR", LOG, e, part.getTypeClass());
                        }
                    }
                }
            }

           
            if (obj != null) {
                XmlOptions options = new XmlOptions();
                if (schema != null) {
                    options.setValidateOnSet();
                }
                if (message != null
                    && MessageUtils.getContextualBoolean(message,
                                                      XmlBeansDataBinding.XMLBEANS_NAMESPACE_HACK,
                                                      false)) {
                    Object dom;
                    if (obj instanceof XmlObjectBase) {
                        XmlObjectBase source = (XmlObjectBase)obj;
                        dom = source.newDomNode(options);
                    } else {
                        XmlTokenSource source = (XmlTokenSource)obj;
                        dom = source.newDomNode(options);
                    }
                   
                    if (dom instanceof Document) {
                        org.w3c.dom.Element e = ((Document)dom).getDocumentElement();
                        StaxUtils.copy(e, output);
                    } else if (dom instanceof DocumentFragment) {
                        DocumentFragment frag = (DocumentFragment) dom;
                        Node node = frag.getFirstChild();
                        while (node != null) {
                            if (node instanceof Element) {
                                StaxUtils.copy((Element)node, output);
                            } else if (node instanceof Comment) {
                                output.writeComment(((Comment)node).getData());
                            } else if (node instanceof Text) {
                                output.writeCharacters(((Text)node).getData());
                            }
                            node = node.getNextSibling();
                        }
                    } else {
                        throw new Fault("Invalid document type returned: " + dom.toString(), LOG);
                    }
                    return;
                }
               
                XMLStreamReader reader;
                if (obj instanceof XmlObjectBase) {
                    XmlObjectBase source = (XmlObjectBase)obj;
                    reader = source.newCursorForce().newXMLStreamReader(options);
                } else {
                    XmlTokenSource source = (XmlTokenSource)obj;
                    reader = source.newCursor().newXMLStreamReader(options);                   
                }
                SchemaType st = part == null ? null
                    : (SchemaType)part.getProperty(SchemaType.class.getName());
                if (st == null) {
                    try {
                        Field f = typeClass.getField("type");
                        if (Modifier.isStatic(f.getModifiers())) {
                            st = (SchemaType)f.get(null);
                            if (part != null) {
                                part.setProperty(SchemaType.class.getName(), st);
                            }
                        }
                    } catch (Exception es) {
                        //ignore
                        es.printStackTrace();
                    }
                }
                if (reader.getEventType() == XMLStreamReader.START_DOCUMENT) {
                    reader.next();
                }
               
                if (st != null && !st.isDocumentType()
                    || reader.getEventType() == XMLStreamReader.CHARACTERS) {
                   
                    QName elementName = part != null ? part.getConcreteName() : st.getName();
                   
                    if (StringUtils.isEmpty(elementName.getNamespaceURI())) {
                        output.writeStartElement(elementName.getLocalPart());
                       
                    } else {
View Full Code Here

        }
    }

    private static BigInteger getBigIntegerValue(XmlObject o)
    {
        SchemaType s = o.schemaType();
        switch (s.getDecimalSize())
        {
            case SchemaType.SIZE_BIG_DECIMAL:
                return ((XmlObjectBase)o).bigDecimalValue().toBigInteger();
            case SchemaType.SIZE_BIG_INTEGER:
                return ((XmlObjectBase)o).bigIntegerValue();
View Full Code Here

        _localElement = null;
        _wildcardElement = null;
        String message = null;
        State state = topState();

        SchemaType  elementType  = null;
        SchemaField elementField = null;

        if (state == null)
        {
            elementType = _rootType;
            elementField = _rootField;
        }
        else
        {

            QName name = event.getName();

            assert name != null;

            state._isEmpty = false;

            if (state._isNil)
            {
                emitFieldError(event,  "Nil element cannot have element content");
                _eatContent = 1;
                return;
            }

            if (!state.visit( name ))
            {
                message = findDetailedErrorBegin(state , name);
                if (message != null)
                {
                  emitFieldError(event, message);
                  message = null;
                }
                else
                {
                  emitFieldError(event, "Element not allowed:", name);
                }
                _eatContent = 1;

                return;
            }

            SchemaParticle currentParticle = state.currentParticle();
            _wildcardElement = currentParticle;

            if (currentParticle.getParticleType() == SchemaParticle.WILDCARD)
            {
                //_wildcardElement = currentParticle;
                QNameSet elemWildcardSet = currentParticle.getWildcardSet();

                if (!elemWildcardSet.contains( name ))
                {
                    // Additional processing may be needed to generate more
                    // descriptive messages
                    emitFieldError( event, "Element not allowed:", name );
                    _eatContent = 1;

                    return;
                }

                int wildcardProcess = currentParticle.getWildcardProcess();

                if (wildcardProcess == SchemaParticle.SKIP)
                {
                    _eatContent = 1;
                    return;
                }

                _localElement = _globalTypes.findElement( name );
                elementField = _localElement;

                if (elementField == null)
                {
                    if (wildcardProcess == SchemaParticle.STRICT)
                    {
                        emitFieldError(
                            event, "Element not allowed (strict wildcard, and no definition found):", name );
                    }

                    _eatContent = 1;

                    return;
                }
            }
            else
            {
                assert
                    currentParticle.getParticleType() == SchemaParticle.ELEMENT;

                // If the current element particle name does not match the name
                // of the event, then the current element is a substitute for
                // the current particle. Replace the field with the global
                // element for the replacement

                if (! currentParticle.getName().equals(name))
                {
                    if (((SchemaLocalElement)currentParticle).blockSubstitution())
                    {
                        emitFieldError(event,
                            "Element substitution not allowed when group head has block='substitution'", name);
                        _eatContent = 1;
                        return;
                    }

                    SchemaGlobalElement newField = _globalTypes.findElement(name);

                    assert newField != null;

                    if (newField != null)
                    {
                        elementField = newField;
                        _localElement = newField;
                    }
                }
                else
                {
                    elementField = (SchemaField) currentParticle;
                }
            }

            elementType = elementField.getType();
        }

        assert elementType != null;

        //
        // the no-type is always invalid (even if there is an xsi:type)
        //

        if (elementType.isNoType())
        {
            emitFieldError(event, "Invalid type.");
            _eatContent = 1;
        }

        //
        // See if the element has an xsi:type on it
        //

        SchemaType xsiType = null;

        if (event.getXsiType( _chars ))
        {
            String value = _chars.asString();

            // Turn off the listener so a public error message
            // does not get generated, but I can see if there was
            // an error through the error state

            int originalErrorState = _errorState;

            _suspendErrors++;

            try
            {
                _vc._event = null;

                xsiType =
                    _globalTypes.findType(
                        XmlQNameImpl.validateLexical( value, _vc, event ) );

            }
            catch ( Throwable t )
            {
                _errorState++;
            }
            finally
            {
                _suspendErrors--;
            }

            if (originalErrorState != _errorState)
            {
                emitFieldError(
                    event, "Invalid xsi:type qname: '" + value + "'" );

                _eatContent = 1;

                return;
            }
            else if (xsiType == null)
            {
                emitError(event,  "Could not find xsi:type: '" + value + "'");

                _eatContent = 1;

                return;
            }
        }

        if (xsiType != null && !xsiType.equals(elementType))
        {
            if (!elementType.isAssignableFrom(xsiType))
            {
                emitFieldError(
                    event,
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.SchemaType

Copyright © 2018 www.massapicom. 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.