use of org.apache.ws.commons.schema.XmlSchemaComplexType in project tomee by apache.
the class JAXBSchemaInitializer method end.
public void end(FaultInfo fault) {
MessagePartInfo part = fault.getFirstMessagePart();
Class<?> cls = part.getTypeClass();
Class<?> cl2 = (Class<?>) fault.getProperty(Class.class.getName());
if (cls != cl2) {
QName name = (QName) fault.getProperty("elementName");
part.setElementQName(name);
JAXBBeanInfo beanInfo = getBeanInfo(cls);
if (beanInfo == null) {
throw new Fault(new Message("NO_BEAN_INFO", LOG, cls.getName()));
}
SchemaInfo schemaInfo = serviceInfo.getSchema(part.getElementQName().getNamespaceURI());
if (schemaInfo != null && !isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName())) {
XmlSchemaElement el = new XmlSchemaElement(schemaInfo.getSchema(), true);
el.setName(part.getElementQName().getLocalPart());
el.setNillable(true);
schemaInfo.setElement(null);
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
return;
}
QName typeName = itr.next();
el.setSchemaTypeName(typeName);
}
} else if (part.getXmlSchema() == null) {
try {
cls.getConstructor(new Class[] { String.class });
} catch (Exception e) {
try {
cls.getConstructor(new Class[0]);
} catch (Exception e2) {
// no String or default constructor, we cannot use it
return;
}
}
// not mappable in JAXBContext directly, we'll have to do it manually :-(
SchemaInfo schemaInfo = serviceInfo.getSchema(part.getElementQName().getNamespaceURI());
if (schemaInfo == null || isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName())) {
return;
}
XmlSchemaElement el = new XmlSchemaElement(schemaInfo.getSchema(), true);
el.setName(part.getElementQName().getLocalPart());
schemaInfo.setElement(null);
part.setXmlSchema(el);
XmlSchemaComplexType ct = new XmlSchemaComplexType(schemaInfo.getSchema(), false);
el.setSchemaType(ct);
XmlSchemaSequence seq = new XmlSchemaSequence();
ct.setParticle(seq);
Method[] methods = cls.getMethods();
for (Method m : methods) {
if (m.getName().startsWith("get") || m.getName().startsWith("is")) {
int beginIdx = m.getName().startsWith("get") ? 3 : 2;
try {
m.getDeclaringClass().getMethod("set" + m.getName().substring(beginIdx), m.getReturnType());
JAXBBeanInfo beanInfo = getBeanInfo(m.getReturnType());
if (beanInfo != null) {
el = new XmlSchemaElement(schemaInfo.getSchema(), false);
el.setName(m.getName().substring(beginIdx));
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
return;
}
QName typeName = itr.next();
el.setSchemaTypeName(typeName);
}
seq.getItems().add(el);
} catch (Exception e) {
// not mappable
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project tomee by apache.
the class SchemaCollection method addCrossImportsType.
private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
// the base type might cross schemas.
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
addCrossImports(schema, complexType.getContentModel());
addCrossImportsAttributeList(schema, complexType.getAttributes());
if (complexType.getParticle() instanceof XmlSchemaChoice) {
XmlSchemaChoice choice = (XmlSchemaChoice) complexType.getParticle();
addCrossImports(schema, choice);
} else if (complexType.getParticle() instanceof XmlSchemaAll) {
XmlSchemaAll all = (XmlSchemaAll) complexType.getParticle();
addCrossImports(schema, all);
} else if (complexType.getParticle() instanceof XmlSchemaSequence) {
XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle();
addCrossImports(schema, sequence);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class ImportRepairTest method createTypeImportingElement.
private void createTypeImportingElement(XmlSchema importingSchema) {
XmlSchemaComplexType typeWithElementRef = new XmlSchemaComplexType(importingSchema, true);
typeWithElementRef.setName("typeWithRef");
XmlSchemaSequence sequence = new XmlSchemaSequence();
typeWithElementRef.setParticle(sequence);
XmlSchemaElement refElement = new XmlSchemaElement(importingSchema, false);
refElement.getRef().setTargetQName(new QName(ELEMENT_SCHEMA, "importedElement"));
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project wso2-axis2-transports by wso2.
the class XMPPSender method getParameterListForOperation.
/**
* Retrieves list of parameter names & their type for a given operation
* @param operation
*/
private static String getParameterListForOperation(AxisOperation operation) {
// Logic copied from BuilderUtil.buildsoapMessage(...)
StringBuffer paramList = new StringBuffer();
AxisMessage axisMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
XmlSchemaElement xmlSchemaElement = axisMessage.getSchemaElement();
if (xmlSchemaElement != null) {
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
XmlSchemaParticle particle = complexType.getParticle();
if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();
while (iterator.hasNext()) {
XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
QName qName = innerElement.getQName();
if (qName == null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
break;
}
long minOccurs = innerElement.getMinOccurs();
boolean nillable = innerElement.isNillable();
String name = qName != null ? qName.getLocalPart() : innerElement.getName();
String type = innerElement.getSchemaTypeName().toString();
paramList.append("," + type + " " + name);
}
}
}
}
// remove first ","
String list = paramList.toString();
return list.replaceFirst(",", "");
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class ServiceJavascriptBuilder method isEmptyType.
private boolean isEmptyType(XmlSchemaType type, QName parentName) {
if (type instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
if (complexType.getParticle() == null) {
return true;
}
XmlSchemaSequence sequence = getTypeSequence(complexType, parentName);
if (sequence.getItems().isEmpty()) {
return true;
}
}
return false;
}
Aggregations