Search in sources :

Example 1 with XSSimpleTypeDefinition

use of org.apache.xerces.xs.XSSimpleTypeDefinition in project iaf by ibissource.

the class ToXml method handleElement.

// @Override
public void handleElement(XSElementDeclaration elementDeclaration, N node) throws SAXException {
    String name = elementDeclaration.getName();
    String elementNamespace = elementDeclaration.getNamespace();
    String qname = getQName(elementNamespace, name);
    if (DEBUG)
        log.debug("handleNode() name [" + name + "] elementNamespace [" + elementNamespace + "]");
    newLine();
    AttributesImpl attributes = new AttributesImpl();
    Map<String, String> nodeAttributes = getAttributes(elementDeclaration, node);
    if (DEBUG)
        log.debug("node [" + name + "] search for attributeDeclaration");
    XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
    XSObjectList attributeUses = getAttributeUses(typeDefinition);
    if (attributeUses == null || attributeUses.getLength() == 0) {
        if (nodeAttributes != null && nodeAttributes.size() > 0) {
            log.warn("node [" + name + "] found [" + nodeAttributes.size() + "] attributes, but no declared AttributeUses");
        } else {
            if (DEBUG)
                log.debug("node [" + name + "] no attributeUses, no attributes");
        }
    } else {
        if (nodeAttributes == null || nodeAttributes.isEmpty()) {
            log.warn("node [" + name + "] declared [" + attributeUses.getLength() + "] attributes, but no attributes found");
        } else {
            for (int i = 0; i < attributeUses.getLength(); i++) {
                XSAttributeUse attributeUse = (XSAttributeUse) attributeUses.item(i);
                // if (DEBUG) log.debug("startElement ["+localName+"] attributeUse ["+ToStringBuilder.reflectionToString(attributeUse)+"]");
                XSAttributeDeclaration attributeDeclaration = attributeUse.getAttrDeclaration();
                if (DEBUG)
                    log.debug("node [" + name + "] attributeDeclaration [" + ToStringBuilder.reflectionToString(attributeDeclaration) + "]");
                XSSimpleTypeDefinition attTypeDefinition = attributeDeclaration.getTypeDefinition();
                if (DEBUG)
                    log.debug("node [" + name + "] attTypeDefinition [" + ToStringBuilder.reflectionToString(attTypeDefinition) + "]");
                String attName = attributeDeclaration.getName();
                if (nodeAttributes.containsKey(attName)) {
                    String value = nodeAttributes.remove(attName);
                    String uri = attributeDeclaration.getNamespace();
                    String attqname = getQName(uri, attName);
                    String type = null;
                    if (DEBUG)
                        log.debug("node [" + name + "] adding attribute [" + attName + "] value [" + value + "]");
                    attributes.addAttribute(uri, attName, attqname, type, value);
                }
            }
        }
    }
    if (isNil(elementDeclaration, node)) {
        validatorHandler.startPrefixMapping(XSI_PREFIX_MAPPING, XML_SCHEMA_INSTANCE_NAMESPACE);
        attributes.addAttribute(XML_SCHEMA_INSTANCE_NAMESPACE, XML_SCHEMA_NIL_ATTRIBUTE, XSI_PREFIX_MAPPING + ":" + XML_SCHEMA_NIL_ATTRIBUTE, "xs:boolean", "true");
        validatorHandler.startElement(elementNamespace, name, qname, attributes);
        validatorHandler.endElement(elementNamespace, name, qname);
        validatorHandler.endPrefixMapping(XSI_PREFIX_MAPPING);
    } else {
        validatorHandler.startElement(elementNamespace, name, qname, attributes);
        handleElementContents(elementDeclaration, node);
        validatorHandler.endElement(elementNamespace, name, qname);
    }
// if (createdPrefix!=null) {
// validatorHandler.endPrefixMapping(createdPrefix);
// }
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) AttributesImpl(org.xml.sax.helpers.AttributesImpl) XSObjectList(org.apache.xerces.xs.XSObjectList) XSAttributeDeclaration(org.apache.xerces.xs.XSAttributeDeclaration) XSAttributeUse(org.apache.xerces.xs.XSAttributeUse) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Example 2 with XSSimpleTypeDefinition

use of org.apache.xerces.xs.XSSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class SimpleXercesTypeDefinition method getMemberTypes.

public List getMemberTypes() {
    XSObjectList xsMemberTypes = simpleTypeDefinition.getMemberTypes();
    List /*<SimpleTypeDefinition>*/
    memberTypes = new LinkedList();
    for (int i = 0; i < xsMemberTypes.getLength(); i++) {
        memberTypes.add(createTypeDefinition((XSSimpleTypeDefinition) xsMemberTypes.item(i)));
    }
    return memberTypes;
}
Also used : XSObjectList(org.apache.xerces.xs.XSObjectList) List(java.util.List) XSObjectList(org.apache.xerces.xs.XSObjectList) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Example 3 with XSSimpleTypeDefinition

use of org.apache.xerces.xs.XSSimpleTypeDefinition in project iaf by ibissource.

the class XmlTo method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    boolean xmlArrayContainer = aligner.isParentOfSingleMultipleOccurringChildElement();
    boolean repeatedElement = aligner.isMultipleOccurringChildInParentElement(localName);
    XSTypeDefinition typeDefinition = aligner.getTypeDefinition();
    if (!localName.equals(topElement)) {
        if (topElement != null) {
            if (DEBUG)
                log.debug("endElementGroup [" + topElement + "]");
            documentContainer.endElementGroup(topElement);
        }
        if (DEBUG)
            log.debug("startElementGroup [" + localName + "]");
        documentContainer.startElementGroup(localName, xmlArrayContainer, repeatedElement, typeDefinition);
        topElement = localName;
    }
    element.push(topElement);
    topElement = null;
    if (DEBUG)
        log.debug("startElement [" + localName + "] xml array container [" + aligner.isParentOfSingleMultipleOccurringChildElement() + "] repeated element [" + aligner.isMultipleOccurringChildInParentElement(localName) + "]");
    documentContainer.startElement(localName, xmlArrayContainer, repeatedElement, typeDefinition);
    super.startElement(uri, localName, qName, atts);
    if (aligner.isNil(atts)) {
        documentContainer.setNull();
    } else {
        if (writeAttributes) {
            XSObjectList attributeUses = aligner.getAttributeUses();
            if (attributeUses == null) {
                if (atts.getLength() > 0) {
                    log.warn("found [" + atts.getLength() + "] attributes, but no declared AttributeUses");
                }
            } else {
                for (int i = 0; i < attributeUses.getLength(); i++) {
                    XSAttributeUse attributeUse = (XSAttributeUse) attributeUses.item(i);
                    XSAttributeDeclaration attributeDeclaration = attributeUse.getAttrDeclaration();
                    XSSimpleTypeDefinition attTypeDefinition = attributeDeclaration.getTypeDefinition();
                    String attName = attributeDeclaration.getName();
                    String attNS = attributeDeclaration.getNamespace();
                    if (DEBUG)
                        log.debug("startElement [" + localName + "] searching attribute [" + attNS + ":" + attName + "]");
                    int attIndex = attNS != null ? atts.getIndex(attNS, attName) : atts.getIndex(attName);
                    if (attIndex >= 0) {
                        String value = atts.getValue(attIndex);
                        if (DEBUG)
                            log.debug("startElement [" + localName + "] attribute [" + attNS + ":" + attName + "] value [" + value + "]");
                        if (StringUtils.isNotEmpty(value)) {
                            documentContainer.setAttribute(attName, value, attTypeDefinition);
                        }
                    }
                }
            }
        }
    }
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) XSObjectList(org.apache.xerces.xs.XSObjectList) XSAttributeDeclaration(org.apache.xerces.xs.XSAttributeDeclaration) XSAttributeUse(org.apache.xerces.xs.XSAttributeUse) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Example 4 with XSSimpleTypeDefinition

use of org.apache.xerces.xs.XSSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XercesFloatUserDefined method constructor.

public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new();
    if (arg.empty())
        return rs;
    // AnyAtomicType aat = (AnyAtomicType) arg.first();
    AnyType aat = arg.first();
    XSSimpleTypeDefinition simpletype = (XSSimpleTypeDefinition) typeInfo;
    if (simpletype != null) {
        if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE)) {
            String minValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE);
            float iminValue = Float.parseFloat(minValue);
            float actualValue = Float.parseFloat(aat.getStringValue());
            if (actualValue < iminValue) {
                throw DynamicError.invalidForCastConstructor();
            }
        }
        if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE)) {
            String maxValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE);
            float imaxValue = Float.parseFloat(maxValue);
            float actualValue = Float.parseFloat(aat.getStringValue());
            if (actualValue > imaxValue) {
                throw DynamicError.invalidForCastConstructor();
            }
        }
    }
    rs.add(new XercesFloatUserDefined(Float.parseFloat(aat.getStringValue())));
    return rs;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Example 5 with XSSimpleTypeDefinition

use of org.apache.xerces.xs.XSSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathTest method addUserDefinedSimpleTypes.

protected void addUserDefinedSimpleTypes(XSModel schema) {
    XSNamedMap xstypes = schema.getComponents(XSConstants.TYPE_DEFINITION);
    if (xstypes.getLength() == 0) {
        return;
    }
    addNamespace("myType", "http://www.w3.org/XQueryTest/userDefinedTypes");
    UserDefinedCtrLibrary udl = new UserDefinedCtrLibrary("http://www.w3.org/XQueryTest/userDefinedTypes");
    for (int i = 0; i < xstypes.getLength(); i++) {
        XSObject xsobject = xstypes.item(i);
        if ("http://www.w3.org/XQueryTest/userDefinedTypes".equals(xsobject.getNamespace())) {
            if (xsobject instanceof XSSimpleTypeDefinition) {
                XSSimpleTypeDefinition typeDef = (XSSimpleTypeDefinition) xsobject;
                if (typeDef.getNumeric()) {
                    if (xsobject.getName().equals("floatBased") || xsobject.getName().equals("shoesize")) {
                        XercesFloatUserDefined fudt = new XercesFloatUserDefined(xsobject);
                        udl.add_type(fudt);
                    } else {
                        XercesIntegerUserDefined iudt = new XercesIntegerUserDefined(xsobject);
                        udl.add_type(iudt);
                    }
                } else {
                    if (xsobject.getName().equals("QNameBased")) {
                        XercesQNameUserDefined qudt = new XercesQNameUserDefined(xsobject);
                        udl.add_type(qudt);
                    } else {
                        XercesUserDefined udt = new XercesUserDefined(typeDef);
                        udl.add_type(udt);
                    }
                }
            }
        }
    }
    addFunctionLibrary(udl);
}
Also used : XercesIntegerUserDefined(org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesIntegerUserDefined) XercesFloatUserDefined(org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesFloatUserDefined) XSObject(org.apache.xerces.xs.XSObject) XSNamedMap(org.apache.xerces.xs.XSNamedMap) UserDefinedCtrLibrary(org.eclipse.wst.xml.xpath2.processor.internal.types.userdefined.UserDefinedCtrLibrary) XercesUserDefined(org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesUserDefined) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition) XercesQNameUserDefined(org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesQNameUserDefined)

Aggregations

XSSimpleTypeDefinition (org.apache.xerces.xs.XSSimpleTypeDefinition)6 XSObjectList (org.apache.xerces.xs.XSObjectList)3 XSAttributeDeclaration (org.apache.xerces.xs.XSAttributeDeclaration)2 XSAttributeUse (org.apache.xerces.xs.XSAttributeUse)2 XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)2 BigInteger (java.math.BigInteger)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 XSNamedMap (org.apache.xerces.xs.XSNamedMap)1 XSObject (org.apache.xerces.xs.XSObject)1 Item (org.eclipse.wst.xml.xpath2.api.Item)1 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1 UserDefinedCtrLibrary (org.eclipse.wst.xml.xpath2.processor.internal.types.userdefined.UserDefinedCtrLibrary)1 XercesFloatUserDefined (org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesFloatUserDefined)1 XercesIntegerUserDefined (org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesIntegerUserDefined)1 XercesQNameUserDefined (org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesQNameUserDefined)1 XercesUserDefined (org.eclipse.wst.xml.xpath2.processor.testsuite.userdefined.XercesUserDefined)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1