use of org.apache.ws.commons.schema.XmlSchemaComplexType in project tomee by apache.
the class JAXBSchemaInitializer method buildGenericElements.
private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Method m, Type type) {
String rawType = ((ParameterizedType) type).getRawType().toString();
String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
XmlSchemaComplexType generics = (XmlSchemaComplexType) schema.getTypeByName(typeName);
if (generics == null) {
generics = new XmlSchemaComplexType(schema, true);
generics.setName(typeName);
}
Class<?> genericsClass = m.getReturnType();
buildGenericSeq(schema, generics, genericsClass);
int idx = m.getName().startsWith("get") ? 3 : 2;
String name = m.getName().substring(idx);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
XmlSchemaElement newel = new XmlSchemaElement(schema, false);
newel.setName(name);
newel.setSchemaTypeName(generics.getQName());
newel.setMinOccurs(0);
if (!seq.getItems().contains(newel)) {
seq.getItems().add(newel);
}
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project tomee by apache.
the class JAXBSchemaInitializer method buildExceptionType.
private void buildExceptionType(MessagePartInfo part, Class<?> cls) {
SchemaInfo schemaInfo = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
if (s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())) {
schemaInfo = s;
break;
}
}
XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
XmlType xmlTypeAnno = cls.getAnnotation(XmlType.class);
String[] propertyOrder = null;
boolean respectXmlTypeNS = false;
XmlSchema faultBeanSchema = null;
if (xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.namespace()) && !xmlTypeAnno.namespace().equals(part.getElementQName().getNamespaceURI())) {
respectXmlTypeNS = true;
NamespaceMap nsMap = new NamespaceMap();
nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, xmlTypeAnno.namespace());
nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
SchemaInfo faultBeanSchemaInfo = createSchemaIfNeeded(xmlTypeAnno.namespace(), nsMap);
faultBeanSchema = faultBeanSchemaInfo.getSchema();
}
if (xmlTypeAnno != null && xmlTypeAnno.propOrder().length > 0) {
propertyOrder = xmlTypeAnno.propOrder();
// TODO: handle @XmlAccessOrder
}
if (schemaInfo == null) {
NamespaceMap nsMap = new NamespaceMap();
nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, part.getElementQName().getNamespaceURI());
nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
schemaInfo = createSchemaIfNeeded(part.getElementQName().getNamespaceURI(), nsMap);
}
XmlSchema schema = schemaInfo.getSchema();
// Before updating everything, make sure we haven't added this
// type yet. Multiple methods that throw the same exception
// types will cause duplicates.
String faultTypeName = xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.name()) ? xmlTypeAnno.name() : part.getElementQName().getLocalPart();
XmlSchemaType existingType = schema.getTypeByName(faultTypeName);
if (existingType != null) {
return;
}
XmlSchemaElement el = new XmlSchemaElement(schema, true);
el.setName(part.getElementQName().getLocalPart());
part.setXmlSchema(el);
schemaInfo.setElement(null);
if (respectXmlTypeNS) {
// create complexType in the new created schema for xmlType
schema = faultBeanSchema;
}
XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
ct.setName(faultTypeName);
el.setSchemaTypeName(ct.getQName());
XmlSchemaSequence seq = new XmlSchemaSequence();
ct.setParticle(seq);
String namespace = part.getElementQName().getNamespaceURI();
XmlAccessType accessType = Utils.getXmlAccessType(cls);
//
for (Field f : Utils.getFields(cls, accessType)) {
// map field
Type type = Utils.getFieldType(f);
// generic return type.
if ((type == null) && (f.getGenericType() instanceof ParameterizedType)) {
type = f.getGenericType();
}
if (generateGenericType(type)) {
buildGenericElements(schema, seq, f);
} else {
JAXBBeanInfo beanInfo = getBeanInfo(type);
if (beanInfo != null) {
XmlElement xmlElementAnno = f.getAnnotation(XmlElement.class);
addElement(schema, seq, beanInfo, new QName(namespace, f.getName()), isArray(type), xmlElementAnno);
}
}
}
for (Method m : Utils.getGetters(cls, accessType)) {
// map method
Type type = Utils.getMethodReturnType(m);
// generic return type.
if ((type == null) && (m.getGenericReturnType() instanceof ParameterizedType)) {
type = m.getGenericReturnType();
}
if (generateGenericType(type)) {
buildGenericElements(schema, seq, m, type);
} else {
JAXBBeanInfo beanInfo = getBeanInfo(type);
if (beanInfo != null) {
int idx = m.getName().startsWith("get") ? 3 : 2;
String name = m.getName().substring(idx);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
XmlElement xmlElementAnno = m.getAnnotation(XmlElement.class);
addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type), xmlElementAnno);
}
}
}
// Create element in xsd:sequence for Exception.class
if (Exception.class.isAssignableFrom(cls)) {
addExceptionMessage(cls, schema, seq);
}
if (propertyOrder != null) {
if (propertyOrder.length == seq.getItems().size()) {
sortItems(seq, propertyOrder);
} else if (propertyOrder.length > 1 || (propertyOrder.length == 1 && !propertyOrder[0].isEmpty())) {
LOG.log(Level.WARNING, "propOrder in @XmlType doesn't define all schema elements :" + Arrays.toString(propertyOrder));
}
}
if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL) && propertyOrder == null) {
sort(seq);
}
schemas.addCrossImports();
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project ddf by codice.
the class GenericFeatureConverterWfs11Test method buildElementMap.
private Map<QName, XmlSchemaElement> buildElementMap(XmlSchema schema) {
Map<QName, XmlSchemaElement> elementMap = new HashMap<>();
XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
gmlElement.setSchemaTypeName(new QName(Wfs11Constants.GML_3_1_1_NAMESPACE, GML));
gmlElement.setName("the_geom");
elementMap.put(new QName("the_geom"), gmlElement);
return elementMap;
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project ddf by codice.
the class FeatureMetacardType method processXmlSchemaParticle.
private void processXmlSchemaParticle(XmlSchemaParticle particle) {
if (particle instanceof XmlSchemaSequence) {
XmlSchemaSequence schemaSequence = (XmlSchemaSequence) particle;
for (final XmlSchemaSequenceMember element : schemaSequence.getItems()) {
if (element instanceof XmlSchemaElement) {
XmlSchemaElement innerElement = ((XmlSchemaElement) element);
XmlSchemaType innerEleType = innerElement.getSchemaType();
if (innerEleType instanceof XmlSchemaComplexType) {
processComplexType(innerElement);
} else if (innerEleType instanceof XmlSchemaSimpleType) {
processSimpleType(innerElement);
} else if (innerEleType == null) {
// Check if this is the GML location Property
processGmlType(innerElement);
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project tdi-studio-se by Talend.
the class ComponentBuilder method buildParameterFromElements.
private void buildParameterFromElements(String partElement, ParameterInfo parameterRoot, int ioOrRecursion) {
// XmlSchemaObjectTable elements = xmlSchema.getElements();
if (ioOrRecursion < 3) {
parametersName.clear();
parametersName.add(parameterRoot.getName());
} else if (ioOrRecursion == 3) {
parametersName.add(parameterRoot.getName());
}
Iterator elementsItr = allXmlSchemaElement.iterator();
if (partElement != null) {
while (elementsItr.hasNext()) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) elementsItr.next();
if (partElement.equals(xmlSchemaElement.getName())) {
// parameter.setName(partName);
if (xmlSchemaElement.getSchemaType() != null) {
if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaGroupBase.getItems();
if (xmlSchemaObjectCollection != null) {
buildParameterFromCollection(xmlSchemaObjectCollection, parameterRoot, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
}
}
} else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
String typeName = xmlSchemaSimpleType.getName();
if (typeName != null && typeName.equals("anyType")) {
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName("anyType");
parameterSon.setParent(parameterRoot);
parameterRoot.getParameterInfos().add(parameterSon);
}
parameterRoot.setType(typeName);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
}
}
}
}
}
}
Aggregations