use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class XmlSchemaUtils method findElementByRefName.
/**
* This copes with an observed phenomenon in the schema built by the
* ReflectionServiceFactoryBean. It is creating element such that: (a) the
* type is not set. (b) the refName is set. (c) the namespaceURI in the
* refName is set empty. This apparently indicates 'same Schema' to everyone
* else, so thus function implements that convention here. It is unclear if
* that is a correct structure, and it if changes, we can simplify or
* eliminate this function.
*
* @param name
* @param referencingURI
*/
public static XmlSchemaElement findElementByRefName(SchemaCollection xmlSchemaCollection, QName name, String referencingURI) {
String uri = name.getNamespaceURI();
if ("".equals(uri)) {
uri = referencingURI;
}
QName copyName = new QName(uri, name.getLocalPart());
XmlSchemaElement target = xmlSchemaCollection.getElementByQName(copyName);
assert target != null;
return target;
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class SchemaCollectionContextProxy method getBeanInfo.
public Object getBeanInfo(Class<?> cls) {
Class<?> origCls = cls;
String postfix = "";
while (cls.isArray()) {
cls = cls.getComponentType();
postfix = "Array";
}
XmlRootElement xre = cls.getAnnotation(XmlRootElement.class);
String name = xre == null ? "##default" : xre.name();
String namespace = xre == null ? "##default" : xre.namespace();
if ("##default".equals(name)) {
name = java.beans.Introspector.decapitalize(cls.getSimpleName());
}
if ("##default".equals(namespace) && cls.getPackage() != null) {
XmlSchema sc = cls.getPackage().getAnnotation(XmlSchema.class);
if (sc != null) {
namespace = sc.namespace();
}
}
if ("##default".equals(namespace) || StringUtils.isEmpty(namespace)) {
namespace = JAXBUtils.getPackageNamespace(cls);
if (namespace == null) {
namespace = defaultNamespace;
}
}
final QName qname = new QName(namespace, name + postfix);
final XmlSchemaElement el = schemas.getElementByQName(qname);
XmlSchemaType type = null;
if (el != null) {
type = el.getSchemaType();
}
if (type == null) {
type = schemas.getTypeByQName(getTypeQName(origCls, namespace));
if (type == null) {
type = schemas.getTypeByQName(qname);
}
}
if (type == null) {
type = mapToSchemaType(origCls, namespace);
/*
if (type == null) {
type = mapToSchemaType(cls, namespace);
}
*/
}
if (el == null && type == null) {
return null;
}
final QName typeName = type == null ? null : type.getQName();
return new JAXBBeanInfo() {
public boolean isElement() {
return el == null ? false : true;
}
public Collection<QName> getTypeNames() {
return Collections.singletonList(typeName);
}
public String getElementNamespaceURI(Object object) {
return qname.getNamespaceURI();
}
public String getElementLocalName(Object object) {
return qname.getLocalPart();
}
};
}
use of org.apache.ws.commons.schema.XmlSchemaElement 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.XmlSchemaElement 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());
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class MapType method writeSchema.
@Override
public void writeSchema(XmlSchema root) {
XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
complex.setName(getSchemaType().getLocalPart());
XmlSchemaSequence sequence = new XmlSchemaSequence();
complex.setParticle(sequence);
AegisType kType = getKeyType();
AegisType vType = getValueType();
XmlSchemaElement element = new XmlSchemaElement(root, false);
sequence.getItems().add(element);
element.setName(getEntryName().getLocalPart());
element.setMinOccurs(0);
element.setMaxOccurs(Long.MAX_VALUE);
XmlSchemaComplexType evType = new XmlSchemaComplexType(root, false);
element.setType(evType);
XmlSchemaSequence evSequence = new XmlSchemaSequence();
evType.setParticle(evSequence);
createElement(root, evSequence, getKeyName(), kType, false);
createElement(root, evSequence, getValueName(), vType, true);
}
Aggregations