use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class JAXBSchemaInitializer method addElement.
protected void addElement(XmlSchema schema, XmlSchemaSequence seq, JAXBBeanInfo beanInfo, QName name, boolean isArray, XmlElement xmlElementAnno) {
XmlSchemaElement el = new XmlSchemaElement(schema, false);
if (isArray) {
el.setMinOccurs(0);
el.setMaxOccurs(Long.MAX_VALUE);
} else {
if (xmlElementAnno == null) {
el.setMinOccurs(0);
el.setNillable(false);
} else {
el.setNillable(xmlElementAnno.nillable());
int minOccurs = xmlElementAnno.required() ? 1 : 0;
el.setMinOccurs(minOccurs);
}
}
if (beanInfo.isElement()) {
QName ename = new QName(beanInfo.getElementNamespaceURI(null), beanInfo.getElementLocalName(null));
XmlSchemaElement el2 = schemas.getElementByQName(ename);
el.setNillable(false);
el.getRef().setTargetQName(el2.getQName());
} else {
if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name())) {
el.setName(xmlElementAnno.name());
} else {
el.setName(name.getLocalPart());
}
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
return;
}
QName typeName = itr.next();
el.setSchemaTypeName(typeName);
}
seq.getItems().add(el);
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class JAXBSchemaInitializer method addExceptionMessage.
private void addExceptionMessage(Class<?> cls, XmlSchema schema, XmlSchemaSequence seq) {
try {
// a subclass could mark the message method as transient
Method m = cls.getMethod("getMessage");
if (!m.isAnnotationPresent(XmlTransient.class) && m.getDeclaringClass().equals(Throwable.class)) {
JAXBBeanInfo beanInfo = getBeanInfo(java.lang.String.class);
XmlSchemaElement exEle = new XmlSchemaElement(schema, false);
exEle.setName("message");
exEle.setSchemaTypeName(getTypeName(beanInfo));
exEle.setMinOccurs(0);
seq.getItems().add(exEle);
}
} catch (Exception e) {
// ignore, just won't have the message element
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class JAXBSchemaInitializer method createBridgeXsElement.
private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) {
SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI());
if (schemaInfo != null) {
XmlSchemaElement el = schemaInfo.getElementByQName(qn);
if (el == null) {
createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo);
} else if (!typeName.equals(el.getSchemaTypeName())) {
throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG, qn, typeName, el.getSchemaTypeName()));
}
return;
}
XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI());
if (qualifiedSchemas) {
schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
}
schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false);
schemaInfo.setSchema(schema);
createXsElement(schema, part, typeName, schemaInfo);
NamespaceMap nsMap = new NamespaceMap();
nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace());
nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
schema.setNamespaceContext(nsMap);
serviceInfo.addSchema(schemaInfo);
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class SchemaCollection method addElementCrossImportsElement.
private void addElementCrossImportsElement(XmlSchema schema, XmlSchemaElement item) {
XmlSchemaElement element = item;
XmlSchemaUtils.addImportIfNeeded(schema, element.getRef().getTargetQName());
XmlSchemaUtils.addImportIfNeeded(schema, element.getSchemaTypeName());
// if there's an anonymous type, it might have element refs in it.
XmlSchemaType schemaType = element.getSchemaType();
if (!crossImportsAdded(schema, schemaType)) {
addCrossImportsType(schema, schemaType);
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class SchemaCollection method addOneSchemaCrossImports.
private void addOneSchemaCrossImports(XmlSchema schema) {
/*
* We need to visit all the top-level items.
*/
for (XmlSchemaElement element : schema.getElements().values()) {
addElementCrossImportsElement(schema, element);
}
for (XmlSchemaAttribute attribute : schema.getAttributes().values()) {
XmlSchemaUtils.addImportIfNeeded(schema, attribute.getRef().getTargetQName());
XmlSchemaUtils.addImportIfNeeded(schema, attribute.getSchemaTypeName());
}
for (XmlSchemaType type : schema.getSchemaTypes().values()) {
addCrossImportsType(schema, type);
}
}
Aggregations