Search in sources :

Example 1 with StringList

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

the class XmlTypeToJsonSchemaConverter method findElementDeclaration.

public XSElementDeclaration findElementDeclaration(String elementName, String namespace) {
    for (XSModel model : models) {
        if (log.isDebugEnabled())
            log.debug("search for element [" + elementName + "] in namespace [" + namespace + "]");
        XSElementDeclaration elementDecl = model.getElementDeclaration(elementName, namespace);
        if (elementDecl != null) {
            if (log.isTraceEnabled())
                log.trace("findTypeDefinition found elementDeclaration [" + ToStringBuilder.reflectionToString(elementDecl, ToStringStyle.MULTI_LINE_STYLE) + "]");
            return elementDecl;
        }
    }
    if (namespace == null) {
        for (XSModel model : models) {
            StringList namespaces = model.getNamespaces();
            for (int i = 0; i < namespaces.getLength(); i++) {
                namespace = (String) namespaces.item(i);
                if (log.isDebugEnabled())
                    log.debug("search for element [" + elementName + "] in namespace [" + namespace + "]");
                XSElementDeclaration elementDecl = model.getElementDeclaration(elementName, namespace);
                if (elementDecl != null) {
                    if (log.isTraceEnabled())
                        log.trace("findTypeDefinition found elementDeclaration [" + ToStringBuilder.reflectionToString(elementDecl, ToStringStyle.MULTI_LINE_STYLE) + "]");
                    return elementDecl;
                }
            }
        }
    }
    return null;
}
Also used : StringList(org.apache.xerces.xs.StringList) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XSModel(org.apache.xerces.xs.XSModel)

Example 2 with StringList

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

the class XmlTypeToJsonSchemaConverter method applyFacet.

private void applyFacet(XSSimpleTypeDefinition simpleTypeDefinition, JsonObjectBuilder builder, String key, short facet) {
    if (simpleTypeDefinition.getFacet(facet) != null) {
        String lexicalFacetValue = simpleTypeDefinition.getLexicalFacetValue(facet);
        if (lexicalFacetValue != null) {
            switch(facet) {
                case XSSimpleTypeDefinition.FACET_MAXINCLUSIVE:
                case XSSimpleTypeDefinition.FACET_MININCLUSIVE:
                case XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE:
                case XSSimpleTypeDefinition.FACET_MINEXCLUSIVE:
                case XSSimpleTypeDefinition.FACET_MAXLENGTH:
                case XSSimpleTypeDefinition.FACET_MINLENGTH:
                    /*
							Not sure about this.. 
	
							simpleTypeDefinition.getLexicalFacetValue(facet) returns a numeric value as string
							if value > MAX_INT, Integer.parseInt(value) will throw NumberFormatException
	
							currently this exception is catched and retried as Long.ParseLong(value)
							but what if this throws NumberFormatException?
	
							how to deal with this properly?
							-----
							UPDATE:
							Tried parsing as long and logging the value when couldn't parse, appears to be a 20 digit numeric value
							which would require to use BigInteger

							What is the best method to do this? Try and catch int, long & then bigint or directly to big int?
						*/
                    try {
                        builder.add(key, Integer.parseInt(lexicalFacetValue));
                    } catch (NumberFormatException nfe) {
                        log.warn("Couldn't parse value [" + lexicalFacetValue + "] as Integer... retrying as Long");
                        try {
                            builder.add(key, Long.parseLong(lexicalFacetValue));
                        } catch (NumberFormatException nfex) {
                            log.warn("Couldn't parse value [" + lexicalFacetValue + "] as Long... retrying as BigInteger");
                            try {
                                builder.add(key, new BigInteger(lexicalFacetValue));
                            } catch (NumberFormatException nfexx) {
                                log.warn("Couldn't parse value [" + lexicalFacetValue + "] as BigInteger");
                            }
                        }
                    }
                    break;
                default:
                    // hmm never reaches this block?
                    log.debug("Setting value [" + lexicalFacetValue + "] as String for facet [" + simpleTypeDefinition.getFacet(facet) + "]");
                    builder.add(key, lexicalFacetValue);
                    break;
            }
        } else if (facet == XSSimpleTypeDefinition.FACET_PATTERN || facet == XSSimpleTypeDefinition.FACET_ENUMERATION) {
            XSObjectList multiValuedFacets = simpleTypeDefinition.getMultiValueFacets();
            for (int i = 0; i < multiValuedFacets.getLength(); i++) {
                XSMultiValueFacet multiValuedFacet = (XSMultiValueFacet) multiValuedFacets.item(i);
                if (log.isTraceEnabled())
                    log.trace("Inspecting single multi valued facet [" + multiValuedFacet + "] which is named [" + multiValuedFacet.getName() + "] which is of type [" + multiValuedFacet.getType() + "]");
                if (log.isTraceEnabled())
                    log.trace("Inspecting multiValuedFacet.getLexicalFacetValues() for [" + multiValuedFacet.getName() + "] which has value of [" + multiValuedFacet.getLexicalFacetValues() + "]");
                if (log.isTraceEnabled())
                    log.trace("Inspecting multiValuedFacet.getEnumerationValues() for [" + multiValuedFacet.getName() + "] which has value of [" + multiValuedFacet.getEnumerationValues() + "]");
                if (log.isTraceEnabled())
                    log.trace("Inspecting multiValuedFacet.getFacetKind() == enum for [" + multiValuedFacet.getName() + "] which has value of [" + (multiValuedFacet.getFacetKind() == XSSimpleTypeDefinition.FACET_ENUMERATION) + "]");
                if (log.isTraceEnabled())
                    log.trace("Inspecting multiValuedFacet.getFacetKind() == pattern for [" + multiValuedFacet.getName() + "] which has value of [" + (multiValuedFacet.getFacetKind() == XSSimpleTypeDefinition.FACET_PATTERN) + "]");
                if (facet == multiValuedFacet.getFacetKind()) {
                    StringList lexicalFacetValues = multiValuedFacet.getLexicalFacetValues();
                    if (facet == XSSimpleTypeDefinition.FACET_ENUMERATION) {
                        JsonArrayBuilder enumBuilder = Json.createArrayBuilder();
                        for (int x = 0; x < lexicalFacetValues.getLength(); x++) {
                            lexicalFacetValue = lexicalFacetValues.item(x);
                            enumBuilder.add(lexicalFacetValue);
                        }
                        builder.add(key, enumBuilder.build());
                    } else if (facet == XSSimpleTypeDefinition.FACET_PATTERN) {
                        builder.add(key, lexicalFacetValues.item(0));
                    }
                }
            }
        }
    }
}
Also used : XSObjectList(org.apache.xerces.xs.XSObjectList) XSMultiValueFacet(org.apache.xerces.xs.XSMultiValueFacet) StringList(org.apache.xerces.xs.StringList) BigInteger(java.math.BigInteger) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 3 with StringList

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

the class JavaxValidationContext method createValidationContext.

@Override
public JavaxValidationContext createValidationContext(PipeLineSession session, RootValidations rootValidations, Map<List<String>, List<String>> invalidRootNamespaces) throws ConfigurationException, PipeRunException {
    // clear session variables
    super.createValidationContext(session, rootValidations, invalidRootNamespaces);
    String schemasId;
    Schema schema;
    Set<String> namespaceSet = new HashSet<String>();
    List<XSModel> xsModels = null;
    start();
    schemasId = schemasProvider.getSchemasId();
    if (schemasId == null) {
        schemasId = schemasProvider.getSchemasId(session);
        getSchemaObject(schemasId, schemasProvider.getSchemas(session));
    }
    schema = javaxSchemas.get(schemasId);
    if (schema != null) {
        org.apache.xerces.jaxp.validation.XSGrammarPoolContainer xercesSchema = (org.apache.xerces.jaxp.validation.XSGrammarPoolContainer) schema;
        xercesSchema.getGrammarPool();
        xsModels = new LinkedList<XSModel>();
        Grammar[] grammars = xercesSchema.getGrammarPool().retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
        for (int i = 0; i < grammars.length; i++) {
            XSModel model = ((XSGrammar) grammars[i]).toXSModel();
            xsModels.add(model);
            StringList namespaces = model.getNamespaces();
            for (int j = 0; j < namespaces.getLength(); j++) {
                String namespace = namespaces.item(j);
                namespaceSet.add(namespace);
            }
        }
    }
    JavaxValidationContext result = new JavaxValidationContext(schemasId, schema, namespaceSet, xsModels);
    result.init(schemasProvider, schemasId, namespaceSet, rootValidations, invalidRootNamespaces, ignoreUnknownNamespaces);
    return result;
}
Also used : StringList(org.apache.xerces.xs.StringList) Schema(javax.xml.validation.Schema) Grammar(org.apache.xerces.xni.grammars.Grammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSModel(org.apache.xerces.xs.XSModel) HashSet(java.util.HashSet)

Example 4 with StringList

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

the class JavaxValidationContext method createValidationContext.

@Override
public JavaxValidationContext createValidationContext(IPipeLineSession session, Set<List<String>> rootValidations, Map<List<String>, List<String>> invalidRootNamespaces) throws ConfigurationException, PipeRunException {
    // clear session variables
    super.createValidationContext(session, rootValidations, invalidRootNamespaces);
    String schemasId;
    Schema schema;
    Set<String> namespaceSet = new HashSet<String>();
    List<XSModel> xsModels = null;
    init();
    schemasId = schemasProvider.getSchemasId();
    if (schemasId == null) {
        schemasId = schemasProvider.getSchemasId(session);
        getSchemaObject(schemasId, schemasProvider.getSchemas(session));
    }
    schema = javaxSchemas.get(schemasId);
    String mainFailureMessage = "Validation using " + schemasProvider.getClass().getSimpleName() + " with '" + schemasId + "' failed";
    if (schema != null) {
        org.apache.xerces.jaxp.validation.XSGrammarPoolContainer xercesSchema = (org.apache.xerces.jaxp.validation.XSGrammarPoolContainer) schema;
        xercesSchema.getGrammarPool();
        xsModels = new LinkedList<XSModel>();
        Grammar[] grammars = xercesSchema.getGrammarPool().retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
        for (int i = 0; i < grammars.length; i++) {
            XSModel model = ((XSGrammar) grammars[i]).toXSModel();
            xsModels.add(model);
            StringList namespaces = model.getNamespaces();
            for (int j = 0; j < namespaces.getLength(); j++) {
                String namespace = namespaces.item(j);
                namespaceSet.add(namespace);
            }
        }
    }
    JavaxValidationContext result = new JavaxValidationContext(schemasId, schema, namespaceSet, xsModels);
    result.init(schemasProvider, schemasId, namespaceSet, rootValidations, invalidRootNamespaces, ignoreUnknownNamespaces);
    return result;
}
Also used : StringList(org.apache.xerces.xs.StringList) Schema(javax.xml.validation.Schema) Grammar(org.apache.xerces.xni.grammars.Grammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSModel(org.apache.xerces.xs.XSModel) HashSet(java.util.HashSet)

Aggregations

StringList (org.apache.xerces.xs.StringList)4 XSModel (org.apache.xerces.xs.XSModel)3 HashSet (java.util.HashSet)2 Schema (javax.xml.validation.Schema)2 Grammar (org.apache.xerces.xni.grammars.Grammar)2 XSGrammar (org.apache.xerces.xni.grammars.XSGrammar)2 BigInteger (java.math.BigInteger)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)1 XSMultiValueFacet (org.apache.xerces.xs.XSMultiValueFacet)1 XSObjectList (org.apache.xerces.xs.XSObjectList)1