use of org.apache.ws.commons.schema.XmlSchemaElement in project tomee by apache.
the class CommonsSchemaInfoBuilder method getNestedElements.
private static List<XmlSchemaElement> getNestedElements(XmlSchemaComplexType complexType) {
List<XmlSchemaElement> elements = new ArrayList<XmlSchemaElement>();
XmlSchemaParticle particle = complexType.getParticle();
if (particle instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) particle;
elements.add(element);
} else if (particle instanceof XmlSchemaGroupBase && !(particle instanceof XmlSchemaChoice)) {
XmlSchemaGroupBase groupBase = (XmlSchemaGroupBase) particle;
for (Iterator iterator = groupBase.getItems().getIterator(); iterator.hasNext(); ) {
XmlSchemaParticle child = (XmlSchemaParticle) iterator.next();
if (child instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) child;
elements.add(element);
}
}
} else {
// ignore all other types... you can have these other types, but JAX-RPC doesn't support them
}
return elements;
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tomee by apache.
the class CommonsSchemaInfoBuilder method extractSoapArrayComponentType.
/**
* Extract the nested component type of an Array from the XML Schema Type.
*
* @return the QName of the nested component type or null if the schema type can not be determined
* @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType
*/
private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) {
// Soap arrays are based on complex content restriction
if (!isSoapArray(complexType)) {
return null;
}
XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType.getContentModel().getContent();
//First, handle case that looks like this:
// <complexType name="ArrayOfstring">
// <complexContent>
// <restriction base="soapenc:Array">
// <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
// </restriction>
// </complexContent>
// </complexType>
XmlSchemaObjectCollection attributes = restriction.getAttributes();
for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
Object item = iterator.next();
if (item instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) {
for (Attr attr : attribute.getUnhandledAttributes()) {
QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName());
if (WSDL_ARRAY_TYPE.equals(attQName)) {
// value is a namespace prefixed xsd type
String value = attr.getValue();
// extract local part
int pos = value.lastIndexOf(":");
QName componentType;
if (pos < 0) {
componentType = new QName("", value);
} else {
String localPart = value.substring(pos + 1);
// resolve the namespace prefix
String prefix = value.substring(0, pos);
String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement());
componentType = new QName(namespace, localPart);
}
log.debug("determined component type from element type");
return componentType;
}
}
}
}
}
// If that didn't work, try to handle case like this:
// <complexType name="ArrayOfstring1">
// <complexContent>
// <restriction base="soapenc:Array">
// <sequence>
// <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
// </sequence>
// </restriction>
// </complexContent>
// </complexType>
XmlSchemaParticle particle = restriction.getParticle();
if (particle instanceof XmlSchemaSequence) {
XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
if (sequence.getItems().getCount() != 1) {
throw new IllegalArgumentException("more than one element inside array definition: " + complexType);
}
XmlSchemaObject item = sequence.getItems().getItem(0);
if (item instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) item;
QName componentType = element.getSchemaTypeName();
log.debug("determined component type from element type");
return componentType;
}
}
return null;
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tomee by apache.
the class CommonsSchemaInfoBuilder method addType.
private void addType(QName typeQName, XmlSchemaType type) {
// skip built in xml schema types
if (XML_SCHEMA_NS.equals(typeQName.getNamespaceURI())) {
return;
}
XmlTypeInfo typeInfo = createXmlTypeInfo(typeQName, type);
xmlTypes.put(typeQName, typeInfo);
if (type instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
// process elements nested inside of this element
List<XmlSchemaElement> elements = getNestedElements(complexType);
for (XmlSchemaElement element : elements) {
addNestedElement(element, typeInfo);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project ddf by codice.
the class TestGenericFeatureConverter method buildElementMap.
private Map<QName, XmlSchemaElement> buildElementMap(XmlSchema schema) {
Map<QName, XmlSchemaElement> elementMap = new HashMap<>();
elementMap.put(new QName(ID_ELEMENT), buildSchemaElement(ID_ELEMENT, schema, Constants.XSD_LONG));
elementMap.put(new QName(VERSION_ELEMENT), buildSchemaElement(VERSION_ELEMENT, schema, Constants.XSD_LONG));
elementMap.put(new QName(END_DATE_ELEMENT), buildSchemaElement(END_DATE_ELEMENT, schema, Constants.XSD_DATETIME));
elementMap.put(new QName(FILENAME_ELEMENT), buildSchemaElement(FILENAME_ELEMENT, schema, Constants.XSD_STRING));
elementMap.put(new QName(HEIGHT_ELEMENT), buildSchemaElement(HEIGHT_ELEMENT, schema, Constants.XSD_LONG));
elementMap.put(new QName(INDEX_ID_ELEMENT), buildSchemaElement(INDEX_ID_ELEMENT, schema, Constants.XSD_STRING));
elementMap.put(new QName(OTHER_TAGS_XML_ELEMENT), buildSchemaElement(OTHER_TAGS_XML_ELEMENT, schema, Constants.XSD_STRING));
elementMap.put(new QName(REPOSITORY_ID_ELEMENT), buildSchemaElement(REPOSITORY_ID_ELEMENT, schema, Constants.XSD_LONG));
elementMap.put(new QName(START_DATE_ELEMENT), buildSchemaElement(START_DATE_ELEMENT, schema, Constants.XSD_DATETIME));
elementMap.put(new QName(STYLE_ID_ELEMENT), buildSchemaElement(STYLE_ID_ELEMENT, schema, Constants.XSD_DECIMAL));
elementMap.put(new QName(WIDTH_ELEMENT), buildSchemaElement(WIDTH_ELEMENT, schema, Constants.XSD_LONG));
XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
gmlElement.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
gmlElement.setName(GROUND_GEOM_ELEMENT);
elementMap.put(new QName(GROUND_GEOM_ELEMENT), gmlElement);
return elementMap;
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project ddf by codice.
the class FeatureMetacardTypeTest method testfeatureMetacardTypeFindDateProperties.
@Test
public void testfeatureMetacardTypeFindDateProperties() {
XmlSchema schema = new XmlSchema();
XmlSchemaElement dateElement = new XmlSchemaElement(schema, true);
dateElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
dateElement.setSchemaTypeName(Constants.XSD_DATE);
dateElement.setName(ELEMENT_NAME_1);
XmlSchemaElement dateTimeElement = new XmlSchemaElement(schema, true);
dateTimeElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
dateTimeElement.setSchemaTypeName(Constants.XSD_DATETIME);
dateTimeElement.setName(ELEMENT_NAME_2);
schema.getElements().put(new QName(ELEMENT_NAME_1), dateElement);
schema.getElements().put(new QName(ELEMENT_NAME_2), dateTimeElement);
FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs10Constants.GML_NAMESPACE);
assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_1, BasicTypes.DATE_TYPE);
assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_2, BasicTypes.DATE_TYPE);
}
Aggregations