Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.SchemaAttributeModel


        return new SchemaTypeVisitorImpl(schemaType().getContentModel());
    }

    public SchemaField get_attribute_field(QName attrName)
    {
        SchemaAttributeModel model = schemaType().getAttributeModel();
        if (model == null)
            return null;
        return model.getAttribute(attrName);
    }
View Full Code Here


     * for a given attribute name, or null if none.
     */
    protected XmlAnySimpleType get_default_attribute_value(QName name)
    {
        SchemaType sType = schemaType();
        SchemaAttributeModel aModel = sType.getAttributeModel();
        if (aModel == null)
            return null;
        SchemaLocalAttribute sAttr = aModel.getAttribute(name);
        if (sAttr == null)
            return null;
        return sAttr.getDefaultValue();
    }
View Full Code Here

        StscState state = StscState.get();
        if (seenAttributes == null)
            seenAttributes = new HashSet();
        boolean seenWildcard = false;
        boolean seenRedefinition = false;
        SchemaAttributeModel baseModel = null;
        if (baseType != null)
            baseModel = baseType.getAttributeModel();

        XmlCursor cur = parseTree.newCursor();

        for (boolean more = cur.toFirstChild(); more; more = cur.toNextSibling())
        {
            switch (translateAttributeCode(cur.getName()))
            {
                case ATTRIBUTE_CODE:
                {
                    Attribute xsdattr = (Attribute)cur.getObject();

                    SchemaLocalAttribute sAttr = StscTranslator.translateAttribute(xsdattr, targetNamespace, formDefault, chameleon, anonymousTypes, outerType, baseModel, true);
                    if (sAttr == null)
                        continue;

                    if (seenAttributes.contains(sAttr.getName()))
                    {
                        state.error(XmlErrorCodes.COMPLEX_TYPE_PROPERTIES$DUPLICATE_ATTRIBUTE,
                            new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) },
                            xsdattr.xgetName());
                        continue; // ignore the duplicate attr
                    }

                    seenAttributes.add(sAttr.getName());

                    if (baseModel != null)
                    {
                        SchemaLocalAttribute baseAttr = baseModel.getAttribute(sAttr.getName());
                        if (baseAttr == null)
                        {
                            if (!extension)
                            {
                                if (!baseModel.getWildcardSet().contains(sAttr.getName()))
                                    state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_IN_BASE_WILDCARD_SET,
                                        new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) }, xsdattr);
                            }
                        }
                        else
                        {
                            if (extension)
                            {
                                // KHK: cos-ct-extends.1.2?
                                if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
                                    state.error("An extension cannot prohibit an attribute from the base type; use restriction instead.", XmlErrorCodes.DUPLICATE_ATTRIBUTE_NAME, xsdattr.xgetUse());
                            }
                            else
                            {
                                if (sAttr.getUse() != SchemaLocalAttribute.REQUIRED)
                                {
                                    if (baseAttr.getUse() == SchemaLocalAttribute.REQUIRED)
                                        state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_REQUIRED,
                                            new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) }, xsdattr);

                                    if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
                                        result.removeProhibitedAttribute(sAttr.getName());
                                }
                            }
                        }
                    }

                    if (sAttr.getUse() != SchemaLocalAttribute.PROHIBITED)
                    {
                        result.addAttribute(sAttr);
                    }
                    else
                    {
                        // attribute is prohibited. If it has an anonymous type remove
                        // it from the list (this will prevent inclusion of any anonymous
                        // types defined within the prohibited attribute which would
                        // otherwise attempt to refer to the prohibited attribute at
                        // save() time)
                        SchemaType attrType = sAttr.getType();
                        if (anonymousTypes != null && anonymousTypes.contains(attrType))
                        {
                            anonymousTypes.remove(attrType);
                        }
                    }

                    if (sAttr.getDefaultText() != null && !sAttr.isFixed())
                    {
                        if (sAttr.getUse() != SchemaLocalAttribute.OPTIONAL)
                            state.error(XmlErrorCodes.SCHEMA_ATTR$DEFAULT_AND_USE_OPTIONAL,
                                new Object[] { QNameHelper.pretty(sAttr.getName()) }, xsdattr);
                    }


                    break;
                }
                case ANY_ATTRIBUTE_CODE:
                {
                    Wildcard xsdwc = (Wildcard)cur.getObject();
                    if (seenWildcard)
                    {
                        // KHK: ?
                        state.error("Only one attribute wildcard allowed", XmlErrorCodes.DUPLICATE_ANY_ATTRIBUTE, xsdwc);
                        continue; // ignore the extra wildcard
                    }
                    seenWildcard = true;
                    NamespaceList nsList = xsdwc.xgetNamespace();
                    String nsText;
                    if (nsList == null)
                        nsText = "##any";
                    else
                        nsText = nsList.getStringValue();
                    QNameSet wcset = QNameSet.forWildcardNamespaceString(nsText, targetNamespace);

                    if (baseModel != null && !extension)
                    {
                        if (baseModel.getWildcardSet() == null)
                        {
                            state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$BASE_HAS_ATTR_WILDCARD, null, xsdwc);
                            continue; // ignore the extra wildcard
                        }
                        else if (!baseModel.getWildcardSet().containsAll(wcset))
                        {
                            state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_WILDCARD_SUBSET,
                                new Object[] { nsText }, xsdwc);
                            continue; // ignore the restriction
                        }
View Full Code Here

        return new SchemaTypeVisitorImpl(schemaType().getContentModel());
    }

    public SchemaField get_attribute_field(QName attrName)
    {
        SchemaAttributeModel model = schemaType().getAttributeModel();
        if (model == null)
            return null;
        return model.getAttribute(attrName);
    }
View Full Code Here

     * for a given attribute name, or null if none.
     */
    protected XmlAnySimpleType get_default_attribute_value(QName name)
    {
        SchemaType sType = schemaType();
        SchemaAttributeModel aModel = sType.getAttributeModel();
        if (aModel == null)
            return null;
        SchemaLocalAttribute sAttr = aModel.getAttribute(name);
        if (sAttr == null)
            return null;
        return sAttr.getDefaultValue();
    }
View Full Code Here

        if (sType.isSimpleType())
            return;
       
        XmlObject location = sType.getParseObject();
       
        SchemaAttributeModel sAttrModel = sType.getAttributeModel();
        if (sAttrModel != null)
        {
            SchemaLocalAttribute[] sAttrs  = sAttrModel.getAttributes();
            QName idAttr = null;
            for (int i = 0; i < sAttrs.length; i++)
            {
                if (XmlID.type.isAssignableFrom(sAttrs[i].getType()))
                {
View Full Code Here

        StscState state = StscState.get();
        if (seenAttributes == null)
            seenAttributes = new HashSet();
        boolean seenWildcard = false;
        boolean seenRedefinition = false;
        SchemaAttributeModel baseModel = null;
        if (baseType != null)
            baseModel = baseType.getAttributeModel();

        XmlCursor cur = parseTree.newCursor();

        for (boolean more = cur.toFirstChild(); more; more = cur.toNextSibling())
        {
            switch (translateAttributeCode(cur.getName()))
            {
                case ATTRIBUTE_CODE:
                {
                    Attribute xsdattr = (Attribute)cur.getObject();

                    SchemaLocalAttribute sAttr = StscTranslator.translateAttribute(xsdattr, targetNamespace, chameleon, anonymousTypes, outerType, baseModel, true);
                    if (sAttr == null)
                        continue;

                    if (seenAttributes.contains(sAttr.getName()))
                    {
                        state.error("Attribute with the same name already defined ", XmlErrorContext.DUPLICATE_ATTRIBUTE_NAME, xsdattr.xgetName());
                        continue; // ignore the duplicate attr
                    }

                    seenAttributes.add(sAttr.getName());
                   
                    if (baseModel != null)
                    {
                        SchemaLocalAttribute baseAttr = baseModel.getAttribute(sAttr.getName());
                        if (baseAttr == null)
                        {
                            if (!extension)
                            {
                                if (!baseModel.getWildcardSet().contains(sAttr.getName()))
                                    state.error("A restriction cannot introduce a new attribute that would not be allowed in the base type.", XmlErrorContext.DUPLICATE_ATTRIBUTE_NAME, xsdattr);
                            }
                        }
                        else
                        {
                            if (extension)
                            {
                                if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
                                    state.error("An extension cannot prohibit an attribute from the base type; use restriction instead.", XmlErrorContext.DUPLICATE_ATTRIBUTE_NAME, xsdattr.xgetUse());
                            }
                            else
                            {
                                if (sAttr.getUse() != SchemaLocalAttribute.REQUIRED)
                                {
                                    if (baseAttr.getUse() == SchemaLocalAttribute.REQUIRED)
                                        state.error("A restriction cannot modify an attribute that is required in the base type to be prohibited or optional.", XmlErrorContext.DUPLICATE_ATTRIBUTE_NAME, xsdattr.xgetUse());
                                   
                                    if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
                                        result.removeProhibitedAttribute(sAttr.getName());
                                }
                            }
                        }
                    }

                    if (sAttr.getUse() != SchemaLocalAttribute.PROHIBITED)
                        result.addAttribute(sAttr);
                       
                    if (sAttr.getDefaultText() != null && !sAttr.isFixed())
                    {
                        if (sAttr.getUse() != SchemaLocalAttribute.OPTIONAL)
                            state.error("An attribute declaration must be optional in order to specify a default", XmlErrorContext.GENERIC_ERROR, xsdattr);
                    }
                       

                    break;
                }
                case ANY_ATTRIBUTE_CODE:
                {
                    Wildcard xsdwc = (Wildcard)cur.getObject();
                    if (seenWildcard)
                    {
                        state.error("Only one attribute wildcard allowed", XmlErrorContext.DUPLICATE_ANY_ATTRIBUTE, xsdwc);
                        continue; // ignore the extra wildcard
                    }
                    seenWildcard = true;
                    NamespaceList nsList = xsdwc.xgetNamespace();
                    String nsText;
                    if (nsList == null)
                        nsText = "##any";
                    else
                        nsText = nsList.getStringValue();
                    QNameSet wcset = QNameSet.forWildcardNamespaceString(nsText, targetNamespace);
                   
                    if (baseModel != null && !extension)
                    {
                        if (baseModel.getWildcardSet() == null)
                        {
                            state.error("A restriction cannot add anyAttribute when the base type does not have anyAttribute", XmlErrorContext.DUPLICATE_ANY_ATTRIBUTE, xsdwc);
                            continue; // ignore the extra wildcard
                        }
                        else if (!baseModel.getWildcardSet().containsAll(wcset))
                        {
                            state.error("The anyAttribute namespace='" + nsText + "' is not a subset of the base type anyAttribute", XmlErrorContext.DUPLICATE_ANY_ATTRIBUTE, xsdwc);
                            continue; // ignore the restriction
                        }
                    }
View Full Code Here

    public QName getAttributeTypeAttributeName()
    {
        if (_isAttributeType)
        {
            SchemaAttributeModel sam = getAttributeModel();
            if (sam != null)
            {
                SchemaLocalAttribute[] slaArray = sam.getAttributes();
                if (slaArray != null && slaArray.length > 0)
                {
                    SchemaLocalAttribute sla = slaArray[0];
                    return sla.getName();
                }
View Full Code Here

        if (sType.isSimpleType())
            return;
       
        XmlObject location = sType.getParseObject();
       
        SchemaAttributeModel sAttrModel = sType.getAttributeModel();
        if (sAttrModel != null)
        {
            SchemaLocalAttribute[] sAttrs  = sAttrModel.getAttributes();
            QName idAttr = null;
            for (int i = 0; i < sAttrs.length; i++)
            {
                if (XmlID.type.isAssignableFrom(sAttrs[i].getType()))
                {
View Full Code Here

        return new SchemaTypeVisitorImpl(schemaType().getContentModel());
    }

    public SchemaField get_attribute_field(QName attrName)
    {
        SchemaAttributeModel model = schemaType().getAttributeModel();
        if (model == null)
            return null;
        return model.getAttribute(attrName);
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.SchemaAttributeModel

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.