use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class ImportRepairTest method createDerivedType1.
private XmlSchemaComplexContentExtension createDerivedType1(XmlSchema importingSchema) {
XmlSchemaComplexType derivedType1 = new XmlSchemaComplexType(importingSchema, true);
derivedType1.setName("derivedExtension");
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
extension.setBaseTypeName(new QName(BASE_TYPE_SCHEMA1, "baseType1"));
XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
complexContent.setContent(extension);
derivedType1.setContentModel(complexContent);
return extension;
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class ServiceModelUtil method getOperationInputPartNames.
public static List<String> getOperationInputPartNames(OperationInfo operation) {
List<String> names = new ArrayList<>();
List<MessagePartInfo> parts = operation.getInput().getMessageParts();
if (parts == null || parts.isEmpty()) {
return names;
}
for (MessagePartInfo part : parts) {
XmlSchemaAnnotated schema = part.getXmlSchema();
if (schema instanceof XmlSchemaElement && ((XmlSchemaElement) schema).getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaElement element = (XmlSchemaElement) schema;
XmlSchemaComplexType cplxType = (XmlSchemaComplexType) element.getSchemaType();
XmlSchemaSequence seq = (XmlSchemaSequence) cplxType.getParticle();
if (seq == null || seq.getItems() == null) {
return names;
}
for (int i = 0; i < seq.getItems().size(); i++) {
XmlSchemaElement elChild = (XmlSchemaElement) seq.getItems().get(i);
names.add(elChild.getName());
}
} else {
names.add(part.getConcreteName().getLocalPart());
}
}
return names;
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf 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
}
XmlSchema schema = null;
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);
}
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 cxf 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 cxf by apache.
the class BeanType method writeSchema.
@Override
public void writeSchema(XmlSchema root) {
BeanTypeInfo inf = getTypeInfo();
XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
complex.setName(getSchemaType().getLocalPart());
AegisType sooperType = getSuperType();
/*
* See Java Virtual Machine specification:
* http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
*/
if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) && !inf.getTypeClass().isInterface()) {
complex.setAbstract(true);
}
XmlSchemaSequence sequence = new XmlSchemaSequence();
/*
* Decide if we're going to extend another type. If we are going to defer, then make sure that we
* extend the type for our superclass.
*/
boolean isExtension = inf.isExtension();
if (isExtension && sooperType != null) {
// if sooperType is null, things are confused.
XmlSchemaComplexContent content = new XmlSchemaComplexContent();
complex.setContentModel(content);
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
content.setContent(extension);
extension.setBaseTypeName(sooperType.getSchemaType());
extension.setParticle(sequence);
} else {
complex.setParticle(sequence);
}
boolean needXmime = false;
boolean needUtilityTypes = false;
// Write out schema for elements
for (QName name : inf.getElements()) {
if (isInheritedProperty(inf, name)) {
continue;
}
XmlSchemaElement element = new XmlSchemaElement(root, false);
element.setName(name.getLocalPart());
sequence.getItems().add(element);
AegisType type = getType(inf, name);
if (type.isFlatArray()) {
// ok, we need some tricks here
element.setMinOccurs(type.getMinOccurs());
element.setMaxOccurs(type.getMaxOccurs());
// for now, assume ArrayType. Look at lists or more general solutions later.
ArrayType aType = (ArrayType) type;
type = aType.getComponentType();
element.setNillable(type.isNillable());
} else {
if (AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
}
}
writeTypeReference(name, element, type, root);
needXmime |= type.usesXmime();
needUtilityTypes |= type.usesUtilityTypes();
}
if (needXmime) {
addXmimeToSchema(root);
}
if (needUtilityTypes) {
AegisContext.addUtilityTypesToSchema(root);
}
/**
* if future proof then add <xsd:any/> element
*/
if (inf.isExtensibleElements()) {
XmlSchemaAny any = new XmlSchemaAny();
any.setMinOccurs(0);
any.setMaxOccurs(Long.MAX_VALUE);
sequence.getItems().add(any);
}
// Write out schema for attributes
for (QName name : inf.getAttributes()) {
if (isInheritedProperty(inf, name)) {
continue;
}
XmlSchemaAttribute attribute = new XmlSchemaAttribute(root, false);
complex.getAttributes().add(attribute);
attribute.setName(name.getLocalPart());
AegisType type = getType(inf, name);
attribute.setSchemaTypeName(type.getSchemaType());
String ns = name.getNamespaceURI();
if (!ns.equals(root.getTargetNamespace())) {
XmlSchemaUtils.addImportIfNeeded(root, ns);
}
}
/**
* If extensible attributes then add <xsd:anyAttribute/>
*/
if (inf.isExtensibleAttributes()) {
complex.setAnyAttribute(new XmlSchemaAnyAttribute());
}
}
Aggregations