org.apache.ws.commons.schema.XmlSchemaObjectCollection Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaObjectCollection. 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: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * extract all complex types from a schema and cache into a map
 */
private void cacheComplexTypes(XmlSchema schema) {
    XmlSchemaObjectCollection schemaItems = schema.getItems();

    int numElements = schemaItems.getCount();

    // Iterate XML Schema items
    for (int i = 0; i < numElements; i++) {
        XmlSchemaObject schemaObject = schemaItems.getItem(i);
        if (schemaObject instanceof XmlSchemaComplexType) {
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaObject;
            String elementTypeName = complexType.getName();
            complexTypes.put(elementTypeName, complexType);
        }
    }
}
 
Example #2
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private static final List<Attribute> parseFields(final XmlSchemaComplexType schemaComplexType,
        final XmlSchema schema, final Xsd2UmlConfig context) {
    final List<Attribute> attributes = new LinkedList<Attribute>();
    
    final XmlSchemaObjectCollection schemaItems = schemaComplexType.getAttributes();
    for (int i = 0, count = schemaItems.getCount(); i < count; i++) {
        final XmlSchemaObject schemaObject = schemaItems.getItem(i);
        if (schemaObject instanceof XmlSchemaAttribute) {
            final XmlSchemaAttribute schemaAttribute = (XmlSchemaAttribute) schemaObject;
            attributes.add(parseAttribute(schemaAttribute, schema, context));
            
        } else {
            throw new AssertionError(schemaObject);
        }
    }
    // parseAttributes(schemaComplexType.getAttributes(), schema);
    attributes.addAll(parseParticle(schemaComplexType.getParticle(), schema, context));
    
    return Collections.unmodifiableList(attributes);
}
 
Example #3
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
void loadSchema(XmlSchema schema) {
    XmlSchemaObjectCollection schemaItems = schema.getItems();

    // Iterate XML Schema items
    for (int i = 0; i < schemaItems.getCount(); i++) {
        XmlSchemaObject schemaObject = schemaItems.getItem(i);

        NeutralSchema neutralSchema;
        if (schemaObject instanceof XmlSchemaType) {
            neutralSchema = parse((XmlSchemaType) schemaObject, schema);
        } else if (schemaObject instanceof XmlSchemaElement) {
            neutralSchema = parseElement((XmlSchemaElement) schemaObject, schema);
        } else if (schemaObject instanceof XmlSchemaInclude) {
            continue; // nothing to do for includes
        } else {
            throw new RuntimeException("Unhandled XmlSchemaObject: " + schemaObject.getClass().getCanonicalName());
        }
        schemas.put(neutralSchema.getType(), neutralSchema);
        partialSchemas.clear();
    }
}
 
Example #4
Source File: WSDLToDataService.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static boolean hasResultRowName(XmlSchemaComplexType wrapperSchemaComplexType) {
	XmlSchemaParticle wrapperSchemaParticle = wrapperSchemaComplexType.getParticle();
	// a single sequence must be there
	if (!(wrapperSchemaParticle instanceof XmlSchemaSequence)) {
		return false;
	}
	XmlSchemaSequence wrapperSchemaSequence = (XmlSchemaSequence) wrapperSchemaParticle;
	XmlSchemaObjectCollection objects = wrapperSchemaSequence.getItems(); 
	if (objects.getCount() != 1) {
		return false;
	}
	XmlSchemaObject schemaObject = objects.getItem(0); 
	if (!(schemaObject instanceof XmlSchemaElement)) {
		return false;
	}
	XmlSchemaElement schemaElement = (XmlSchemaElement) schemaObject;
	if (!((((XmlSchemaComplexType) schemaElement.getSchemaType())
			.getParticle()) instanceof XmlSchemaSequence)) {
		return false;
	}
	// cannot contain any attributes
	if (wrapperSchemaComplexType.getAttributes().getCount() > 0) {
		return false;
	}
	
	return true;
}
 
Example #5
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * The xs:annotation is parsed into {@link TaggedValue} with one entry per
 * xs:documentation or xs:appinfo.
 */
private static final List<TaggedValue> annotations(final XmlSchemaAnnotated schemaType, final Xsd2UmlConfig config) {
    if (schemaType == null) {
        return EMPTY_TAGGED_VALUES;
    }
    final XmlSchemaAnnotation annotation = schemaType.getAnnotation();
    if (annotation == null) {
        return EMPTY_TAGGED_VALUES;
    } else {
        final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
        final XmlSchemaObjectCollection children = annotation.getItems();
        
        for (int childIdx = 0; childIdx < children.getCount(); ++childIdx) {
            
            final XmlSchemaObject child = children.getItem(childIdx);
            if (child instanceof XmlSchemaDocumentation) {
                final XmlSchemaDocumentation documentation = (XmlSchemaDocumentation) child;
                taggedValues.add(documentation(documentation, config));
            } else if (child instanceof XmlSchemaAppInfo) {
                final XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) child;
                taggedValues.addAll(config.getPlugin().tagsFromAppInfo(appInfo, config));
            } else {
                throw new AssertionError(child);
            }
        }
        
        return taggedValues;
    }
}
 
Example #6
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private void parseDocumentation(NeutralSchema neutralSchema, XmlSchemaType schemaType) {
    XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems();
    for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) {

        XmlSchemaObject annotation = annotations.getItem(annotationIdx);
        if (annotation instanceof XmlSchemaDocumentation) {
            XmlSchemaDocumentation docs = (XmlSchemaDocumentation) annotation;
            neutralSchema.addAnnotation(new Documentation(docs.getMarkup()));
        }
    }
}
 
Example #7
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private void parseAppInfo(NeutralSchema neutralSchema, XmlSchemaType schemaType) {

        XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems();
        for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) {

            XmlSchemaObject annotation = annotations.getItem(annotationIdx);
            if (annotation instanceof XmlSchemaAppInfo) {
                XmlSchemaAppInfo info = (XmlSchemaAppInfo) annotation;
                neutralSchema.addAnnotation(new AppInfo(info.getMarkup()));
            }
        }
    }
 
Example #8
Source File: SmooksGenerator.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private void addComplexTypeData(XmlSchemaComplexType schemaType, ComplexTypeData complexTypeData) {
    XmlSchemaObjectCollection attributes = schemaType.getAttributes();
    int numElements = attributes.getCount();
    parseParticleForElements(extractParticle(schemaType), complexTypeData);

    // Iterate XML Schema items
    for (int i = 0; i < numElements; i++) {
        XmlSchemaAttribute schemaAttribute = (XmlSchemaAttribute) attributes.getItem(i);
        complexTypeData.getAttributes().add(schemaAttribute.getName());
    }
}
 
Example #9
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
    if (qname == null) throw new NullPointerException("qname is null");
    if (type == null) throw new NullPointerException("type is null");

    XmlTypeInfo typeInfo = new XmlTypeInfo();
    typeInfo.qname = qname;
    typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;

    if (type instanceof XmlSchemaSimpleType) {
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            typeInfo.simpleBaseType = list.getItemType().getQName();

            // this is a list
            typeInfo.listType = true;
        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            typeInfo.simpleBaseType = restriction.getBaseTypeName();

            // is this an enumeration?
            for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
                if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
                    typeInfo.enumType = true;
                    break;
                }

            }
        }
    } else if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;

        // SOAP array component type
        typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);

        // process attributes (skip soap arrays which have non-mappable attributes)
        if (!isSoapArray(complexType)) {
            XmlSchemaObjectCollection attributes = complexType.getAttributes();
            for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
                Object item = iterator.next();
                if (item instanceof XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
                    Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
                    if (old != null) {
                        throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
                    }
                }
            }
        }
    } else {
        LOG.warn("Unknown schema type class " + typeInfo.getClass().getName());
    }

    return typeInfo;
}
 
Example #10
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private void parseAttributes(XmlSchemaObjectCollection attributes, NeutralSchema complexSchema, XmlSchema schema) {

        if (attributes != null) {
            for (int i = 0; i < attributes.getCount(); i++) {
                XmlSchemaAttribute attribute = (XmlSchemaAttribute) attributes.getItem(i);
                QName attributeTypeName = attribute.getSchemaTypeName();

                XmlSchemaType attributeSchemaType = attribute.getSchemaType();

                if (attribute.getName() != null) {

                    String attributeName = attribute.getName();

                    // Derive Attribute Schema
                    NeutralSchema attributeSchema = null;
                    if (attributeSchemaType != null) {
                        attributeSchema = parse(attributeSchemaType, schema);
                    } else if (attributeTypeName != null) {
                        attributeSchema = getSchemaFactory().createSchema(attributeTypeName);
                    }

                    // Update Neutral Schema Field
                    if (attributeSchema != null) {

                        // Optional Attributes
                        if (attribute.getUse().equals(REQUIRED_USE)) {

                            AppInfo info = attributeSchema.getAppInfo();

                            if (info == null) {
                                info = new AppInfo(null);
                            }

                            info.put(REQUIRED_USE.getValue(), "true");
                            attributeSchema.addAnnotation(info);
                        }

                        complexSchema.addField(attributeName, attributeSchema);
                    }
                }
            }
        }
    }