use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.
the class ReflectionServiceFactoryBean method buildServiceFromClass.
protected void buildServiceFromClass() {
Object o = getBus().getProperty("requireExplicitContractLocation");
if (o != null && ("true".equals(o) || Boolean.TRUE.equals(o))) {
throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG, getServiceClass().getName()));
}
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
}
populateFromClass = true;
if (Proxy.isProxyClass(this.getServiceClass())) {
LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
}
sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());
ServiceInfo serviceInfo = new ServiceInfo();
SchemaCollection col = serviceInfo.getXmlSchemaCollection();
col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
ServiceImpl service = new ServiceImpl(serviceInfo);
setService(service);
setServiceProperties();
serviceInfo.setName(getServiceQName());
serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());
sendEvent(Event.SERVICE_SET, getService());
createInterface(serviceInfo);
Set<?> wrapperClasses = this.getExtraClass();
for (ServiceInfo si : getService().getServiceInfos()) {
if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
si.setProperty(EXTRA_CLASS, wrapperClasses);
}
}
initializeDataBindings();
boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
if (isWrapped) {
initializeWrappedSchema(serviceInfo);
}
for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
Method m = (Method) opInfo.getProperty(METHOD);
if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
createBareMessage(serviceInfo, opInfo, false);
}
if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
createBareMessage(serviceInfo, opInfo, true);
}
if (opInfo.hasFaults()) {
// check to make sure the faults are elements
for (FaultInfo fault : opInfo.getFaults()) {
QName qn = (QName) fault.getProperty("elementName");
MessagePartInfo part = fault.getFirstMessagePart();
if (!part.isElement()) {
part.setElement(true);
part.setElementQName(qn);
checkForElement(serviceInfo, part);
}
}
}
}
if (LOG.isLoggable(Level.FINE) || isValidate()) {
ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
validator.walk();
String validationComplaints = validator.getComplaints();
if (!"".equals(validationComplaints)) {
if (isValidate()) {
LOG.warning(validationComplaints);
} else {
LOG.fine(validationComplaints);
}
}
}
}
use of org.apache.cxf.common.xmlschema.SchemaCollection 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.common.xmlschema.SchemaCollection in project cxf by apache.
the class AegisDatabinding method initializeMessageTypes.
protected void initializeMessageTypes(ServiceInfo s, AbstractMessageContainer container, int partType) {
if (container == null) {
return;
}
SchemaCollection col = s.getXmlSchemaCollection();
for (MessagePartInfo part : container.getMessageParts()) {
if (part.getXmlSchema() == null) {
if (part.isElement()) {
XmlSchemaAnnotated tp = col.getElementByQName(part.getElementQName());
part.setXmlSchema(tp);
} else {
XmlSchemaAnnotated tp = col.getTypeByQName(part.getTypeQName());
part.setXmlSchema(tp);
}
}
}
}
Aggregations