use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method initializeWrappedSchema.
protected void initializeWrappedSchema(ServiceInfo serviceInfo) {
for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
if (op.getUnwrappedOperation() != null) {
if (op.hasInput()) {
MessagePartInfo fmpi = op.getInput().getFirstMessagePart();
if (fmpi.getTypeClass() == null) {
QName wrapperBeanName = fmpi.getElementQName();
XmlSchemaElement e = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
e = s.getElementByQName(wrapperBeanName);
if (e != null) {
fmpi.setXmlSchema(e);
break;
}
}
if (e == null) {
createWrappedSchema(serviceInfo, op.getInput(), op.getUnwrappedOperation().getInput(), wrapperBeanName);
}
}
for (MessagePartInfo mpi : op.getInput().getMessageParts()) {
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
mpi.setElement(true);
mpi.setElementQName(qn);
checkForElement(serviceInfo, mpi);
}
}
}
if (op.hasOutput()) {
MessagePartInfo fmpi = op.getOutput().getFirstMessagePart();
if (fmpi.getTypeClass() == null) {
QName wrapperBeanName = fmpi.getElementQName();
XmlSchemaElement e = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
e = s.getElementByQName(wrapperBeanName);
if (e != null) {
break;
}
}
if (e == null) {
createWrappedSchema(serviceInfo, op.getOutput(), op.getUnwrappedOperation().getOutput(), wrapperBeanName);
}
}
for (MessagePartInfo mpi : op.getOutput().getMessageParts()) {
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
mpi.setElement(true);
mpi.setElementQName(qn);
checkForElement(serviceInfo, mpi);
}
}
}
}
}
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method createBareMessage.
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {
MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();
final List<MessagePartInfo> messageParts = message.getMessageParts();
if (messageParts.isEmpty()) {
return;
}
Method method = (Method) opInfo.getProperty(METHOD);
int paraNumber = 0;
for (MessagePartInfo mpi : messageParts) {
SchemaInfo schemaInfo = null;
XmlSchema schema = null;
QName qname = (QName) mpi.getProperty(ELEMENT_NAME);
if (messageParts.size() == 1 && qname == null) {
qname = !isOut ? getInParameterName(opInfo, method, -1) : getOutParameterName(opInfo, method, -1);
if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
qname = isOut ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname.getNamespaceURI(), method.getName());
}
} else if (isOut && messageParts.size() > 1 && qname == null) {
while (!isOutParam(method, paraNumber)) {
paraNumber++;
}
qname = getOutParameterName(opInfo, method, paraNumber);
} else if (qname == null) {
qname = getInParameterName(opInfo, method, paraNumber);
}
for (SchemaInfo s : serviceInfo.getSchemas()) {
if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
schemaInfo = s;
break;
}
}
if (schemaInfo == null) {
schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
schema = schemaInfo.getSchema();
} else {
schema = schemaInfo.getSchema();
if (schema != null && schema.getElementByName(qname) != null) {
mpi.setElement(true);
mpi.setElementQName(qname);
mpi.setXmlSchema(schema.getElementByName(qname));
paraNumber++;
continue;
}
}
// cached element is now invalid
schemaInfo.setElement(null);
XmlSchemaElement el = new XmlSchemaElement(schema, true);
el.setName(qname.getLocalPart());
el.setNillable(true);
if (mpi.isElement()) {
XmlSchemaElement oldEl = (XmlSchemaElement) mpi.getXmlSchema();
if (null != oldEl && !oldEl.getQName().equals(qname)) {
el.setSchemaTypeName(oldEl.getSchemaTypeName());
el.setSchemaType(oldEl.getSchemaType());
if (oldEl.getSchemaTypeName() != null) {
addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
}
}
mpi.setElement(true);
mpi.setXmlSchema(el);
mpi.setElementQName(qname);
mpi.setConcreteName(qname);
continue;
}
if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG, method.getDeclaringClass().getName(), method.getName(), mpi.getName()));
}
if (mpi.getTypeQName() != null) {
el.setSchemaTypeName(mpi.getTypeQName());
} else {
el.setSchemaType((XmlSchemaType) mpi.getXmlSchema());
}
mpi.setXmlSchema(el);
mpi.setConcreteName(qname);
if (mpi.getTypeQName() != null) {
addImport(schema, mpi.getTypeQName().getNamespaceURI());
}
mpi.setElement(true);
mpi.setElementQName(qname);
paraNumber++;
}
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method fillInSchemaCrossreferences.
/**
* Code elsewhere in this function will fill in the name of the type of an
* element but not the reference to the type. This function fills in the
* type references. This does not set the type reference for elements that
* are declared as refs to other elements. It is a giant pain to find them,
* since they are not (generally) root elements and the code would have to
* traverse all the types to find all of them. Users should look them up
* through the collection, that's what it is for.
*/
private void fillInSchemaCrossreferences() {
Service service = getService();
for (ServiceInfo serviceInfo : service.getServiceInfos()) {
SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
// type.
for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements();
for (XmlSchemaElement element : elementsTable.values()) {
if (element.getSchemaType() == null) {
QName typeName = element.getSchemaTypeName();
if (typeName != null) {
XmlSchemaType type = schemaCollection.getTypeByQName(typeName);
if (type == null) {
Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element.getQName(), typeName, service.getName());
LOG.severe(message.toString());
} else {
element.setSchemaType(type);
}
}
}
}
}
}
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class AegisDatabinding method createSchemas.
private void createSchemas(Service s, Set<AegisType> deps) {
Map<String, Set<AegisType>> tns2Type = new HashMap<>();
for (AegisType t : deps) {
String ns = t.getSchemaType().getNamespaceURI();
Set<AegisType> types = tns2Type.get(ns);
if (types == null) {
types = new HashSet<>();
tns2Type.put(ns, types);
}
types.add(t);
}
for (ServiceInfo si : s.getServiceInfos()) {
SchemaCollection col = si.getXmlSchemaCollection();
if (col.getXmlSchemas().length > 1) {
// someone has already filled in the types
continue;
}
}
Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
for (ServiceInfo si : s.getServiceInfos()) {
// these two must be recalculated per-service-info!
boolean needXmimeSchema = false;
boolean needTypesSchema = false;
for (Map.Entry<String, Set<AegisType>> entry : tns2Type.entrySet()) {
String schemaNamespaceUri = entry.getKey();
if (Constants.URI_2001_SCHEMA_XSD.equals(schemaNamespaceUri)) {
continue;
}
if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schemaNamespaceUri)) {
// we handle this separately.
continue;
}
if (AbstractXOPType.XML_MIME_NS.equals(schemaNamespaceUri)) {
// similiarly.
continue;
}
SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
XmlSchema schema = schemaInfo.getSchema();
NamespaceMap xmlsNamespaceMap = new NamespaceMap();
// user-requested prefix mappings.
if (namespaceMap != null) {
for (Map.Entry<String, String> e : namespaceMap.entrySet()) {
xmlsNamespaceMap.add(e.getValue(), e.getKey());
}
}
// tns: is conventional, and besides we have unit tests that are hardcoded to it.
if (!xmlsNamespaceMap.containsKey(WSDLConstants.CONVENTIONAL_TNS_PREFIX) && // if some wants something other than TNS, they get it.
!xmlsNamespaceMap.containsValue(entry.getKey())) {
xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry.getKey());
}
// ditto for xsd: instead of just namespace= for the schema schema.
if (!xmlsNamespaceMap.containsKey("xsd") && !xmlsNamespaceMap.containsValue(Constants.URI_2001_SCHEMA_XSD)) {
xmlsNamespaceMap.add("xsd", Constants.URI_2001_SCHEMA_XSD);
}
schema.setNamespaceContext(xmlsNamespaceMap);
schema.setTargetNamespace(entry.getKey());
schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
schema.setAttributeFormDefault(XmlSchemaForm.QUALIFIED);
for (AegisType t : entry.getValue()) {
try {
t.writeSchema(schema);
} catch (XmlSchemaException ex) {
QName name = t.getSchemaType();
String expected = " Schema for namespace '" + name.getNamespaceURI() + "' already contains type '" + name.getLocalPart() + "'";
String message = ex.getMessage();
if (expected.equals(message)) {
continue;
}
throw ex;
}
}
if (schemaImportsXmime(schema)) {
needXmimeSchema = true;
}
if (AegisContext.schemaImportsUtilityTypes(schema)) {
needTypesSchema = true;
}
}
if (needXmimeSchema) {
XmlSchema schema = aegisContext.addXmimeSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
schemaInfo.setSchema(schema);
si.addSchema(schemaInfo);
}
if (needTypesSchema) {
XmlSchema schema = aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
schemaInfo.setSchema(schema);
si.addSchema(schemaInfo);
}
// it's quite likely that the code in Aegis missed at least one ...
si.getXmlSchemaCollection().addCrossImports();
}
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ServiceModelUtilTest method testGetSchema.
@Test
public void testGetSchema() throws Exception {
BindingInfo bindingInfo = null;
bindingInfo = serviceInfo.getBindings().iterator().next();
QName name = new QName(serviceInfo.getName().getNamespaceURI(), "inHeader");
BindingOperationInfo inHeader = bindingInfo.getOperation(name);
BindingMessageInfo input = inHeader.getInput();
assertNotNull(input);
assertEquals(input.getMessageInfo().getName().getLocalPart(), "inHeaderRequest");
assertEquals(input.getMessageInfo().getName().getNamespaceURI(), "http://org.apache.cxf/headers");
assertEquals(input.getMessageInfo().getMessageParts().size(), 2);
assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getLocalPart(), "inHeader");
assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getNamespaceURI(), "http://org.apache.cxf/headers");
assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getLocalPart(), "passenger");
assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getNamespaceURI(), "http://mycompany.example.com/employees");
assertTrue(input.getMessageInfo().getMessageParts().get(1).isElement());
MessagePartInfo messagePartInfo = input.getMessageInfo().getMessageParts().get(0);
SchemaInfo schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
assertEquals(schemaInfo.getNamespaceURI(), "http://org.apache.cxf/headers");
messagePartInfo = input.getMessageInfo().getMessageParts().get(1);
schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
assertEquals(schemaInfo.getNamespaceURI(), "http://mycompany.example.com/employees");
}
Aggregations