You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/10/25 19:10:56 UTC
svn commit: r588283 [7/18] - in /incubator/cxf/branches/jliu: ./ api/
api/src/main/java/org/apache/cxf/databinding/
api/src/main/java/org/apache/cxf/io/
api/src/main/java/org/apache/cxf/message/
api/src/main/java/org/apache/cxf/phase/ api/src/main/java...
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java Thu Oct 25 10:09:20 2007
@@ -18,10 +18,10 @@
*/
package org.apache.cxf.transport;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Endpoint;
@@ -44,9 +44,9 @@
public static final String ENDPOINTS = "multipleEndpointObserver.endpoints";
protected Bus bus;
- protected List<Interceptor> bindingInterceptors = new ArrayList<Interceptor>();
- protected List<Interceptor> routingInterceptors = new ArrayList<Interceptor>();
- private Set<Endpoint> endpoints = new HashSet<Endpoint>();
+ protected List<Interceptor> bindingInterceptors = new CopyOnWriteArrayList<Interceptor>();
+ protected List<Interceptor> routingInterceptors = new CopyOnWriteArrayList<Interceptor>();
+ private Set<Endpoint> endpoints = new CopyOnWriteArraySet<Endpoint>();
public MultipleEndpointObserver(Bus bus) {
super();
@@ -106,24 +106,12 @@
return bindingInterceptors;
}
- public void setBindingInterceptors(List<Interceptor> bindingInterceptors) {
- this.bindingInterceptors = bindingInterceptors;
- }
-
public List<Interceptor> getRoutingInterceptors() {
return routingInterceptors;
}
- public void setRoutingInterceptors(List<Interceptor> routingInterceptors) {
- this.routingInterceptors = routingInterceptors;
- }
-
public Set<Endpoint> getEndpoints() {
return endpoints;
}
- public void setEndpoints(Set<Endpoint> endpoints) {
- this.endpoints = endpoints;
- }
-
}
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java Thu Oct 25 10:09:20 2007
@@ -19,8 +19,8 @@
package org.apache.cxf.transport.http;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -34,19 +34,27 @@
List<QueryHandler> queryHandlers;
Bus bus;
+
+ public QueryHandlerRegistryImpl() {
+ }
+ public QueryHandlerRegistryImpl(Bus b, List<QueryHandler> handlers) {
+ bus = b;
+ queryHandlers = new CopyOnWriteArrayList<QueryHandler>(handlers);
+ }
+
+
@PostConstruct
public void register() {
+ if (queryHandlers == null) {
+ queryHandlers = new CopyOnWriteArrayList<QueryHandler>();
+ if (bus != null) {
+ queryHandlers.add(new WSDLQueryHandler(bus));
+ }
+ }
if (null != bus) {
bus.setExtension(this, QueryHandlerRegistry.class);
}
}
-
- @PostConstruct
- public void init() {
- queryHandlers = new ArrayList<QueryHandler>();
- registerHandler(new WSDLQueryHandler(bus));
- }
-
public List<QueryHandler> getHandlers() {
return queryHandlers;
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Thu Oct 25 10:09:20 2007
@@ -24,8 +24,10 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -50,6 +52,7 @@
import org.apache.cxf.Bus;
+import org.apache.cxf.catalog.OASISCatalogManager;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
@@ -80,13 +83,20 @@
public boolean isRecognizedQuery(String baseUri, String ctx,
EndpointInfo endpointInfo, boolean contextMatchExact) {
if (baseUri != null
- && (baseUri.toLowerCase().contains("?wsdl")
- || baseUri.toLowerCase().contains("?xsd="))) {
- if (contextMatchExact) {
- return endpointInfo.getAddress().contains(ctx);
- } else {
- // contextMatchStrategy will be "stem"
- return endpointInfo.getAddress().contains(getStem(baseUri));
+ && (baseUri.contains("?")
+ && (baseUri.toLowerCase().contains("wsdl")
+ || baseUri.toLowerCase().contains("xsd=")))) {
+
+ int idx = baseUri.indexOf("?");
+ Map<String, String> map = parseQueryString(baseUri.substring(idx + 1));
+ if (map.containsKey("wsdl")
+ || map.containsKey("xsd")) {
+ if (contextMatchExact) {
+ return endpointInfo.getAddress().contains(ctx);
+ } else {
+ // contextMatchStrategy will be "stem"
+ return endpointInfo.getAddress().contains(getStem(baseUri.substring(0, idx)));
+ }
}
}
return false;
@@ -95,20 +105,11 @@
public void writeResponse(String baseUri, String ctxUri,
EndpointInfo endpointInfo, OutputStream os) {
try {
- int idx = baseUri.toLowerCase().indexOf("?wsdl");
- String base = null;
- String wsdl = "";
- String xsd = null;
- if (idx != -1) {
- base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?wsdl"));
- wsdl = baseUri.substring(baseUri.toLowerCase().indexOf("?wsdl") + 5);
- if (wsdl.length() > 0) {
- wsdl = wsdl.substring(1);
- }
- } else {
- base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?xsd="));
- xsd = baseUri.substring(baseUri.toLowerCase().indexOf("?xsd=") + 5);
- }
+ int idx = baseUri.toLowerCase().indexOf("?");
+ Map<String, String> params = parseQueryString(baseUri.substring(idx + 1));
+ String base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?"));
+ String wsdl = params.get("wsdl");
+ String xsd = params.get("xsd");
Map<String, Definition> mp = CastUtils.cast((Map)endpointInfo.getService()
.getProperty(WSDLQueryHandler.class.getName()));
@@ -131,7 +132,7 @@
+ ".Schemas"));
}
- if (!mp.containsKey(wsdl)) {
+ if (!mp.containsKey("")) {
Definition def = new ServiceWSDLBuilder(bus, endpointInfo.getService()).build();
mp.put("", def);
updateDefinition(def, mp, smp, base, endpointInfo);
@@ -141,6 +142,12 @@
Document doc;
if (xsd == null) {
Definition def = mp.get(wsdl);
+ if (def == null) {
+ String wsdl2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+ wsdl,
+ base);
+ def = mp.get(wsdl2);
+ }
WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
.getWSDLFactory().newWSDLWriter();
@@ -148,8 +155,21 @@
doc = wsdlWriter.getDocument(def);
} else {
SchemaReference si = smp.get(xsd);
- ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(si.getReferencedSchema()
- .getDocumentBaseURI(),
+ if (si == null) {
+ String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+ xsd,
+ base);
+ si = smp.get(xsd2);
+ }
+
+ String uri = si.getReferencedSchema().getDocumentBaseURI();
+ uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+ uri,
+ si.getReferencedSchema().getDocumentBaseURI());
+ if (uri == null) {
+ uri = si.getReferencedSchema().getDocumentBaseURI();
+ }
+ ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
bus);
InputSource src = rml.getBaseInputSource();
@@ -207,20 +227,46 @@
}
}
+
+ static String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String base) {
+ String resolvedSchemaLocation = null;
+ try {
+ resolvedSchemaLocation = catalogs.getCatalog().resolveSystem(start);
+ if (resolvedSchemaLocation == null) {
+ resolvedSchemaLocation = catalogs.getCatalog().resolveURI(start);
+ }
+ if (resolvedSchemaLocation == null) {
+ resolvedSchemaLocation = catalogs.getCatalog().resolvePublic(start, base);
+ }
+ } catch (Exception ex) {
+ //ignore
+ }
+ return resolvedSchemaLocation;
+ }
protected void updateDefinition(Definition def, Map<String, Definition> done,
Map<String, SchemaReference> doneSchemas,
String base, EndpointInfo ei) {
+ OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);
+
Collection<List> imports = CastUtils.cast((Collection<?>)def.getImports().values());
for (List lst : imports) {
List<Import> impLst = CastUtils.cast(lst);
for (Import imp : impLst) {
String start = imp.getLocationURI();
- try {
- //check to see if it's aleady in a URL format. If so, leave it.
- new URL(start);
- } catch (MalformedURLException e) {
+ String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+
+ if (resolvedSchemaLocation == null) {
+ try {
+ //check to see if it's aleady in a URL format. If so, leave it.
+ new URL(start);
+ } catch (MalformedURLException e) {
+ done.put(start, imp.getDefinition());
+ updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
+ }
+ } else {
done.put(start, imp.getDefinition());
+ done.put(resolvedSchemaLocation, imp.getDefinition());
updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
}
}
@@ -245,17 +291,25 @@
protected void updateSchemaImports(Schema schema,
Map<String, SchemaReference> doneSchemas,
String base) {
+ OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);
Collection<List> imports = CastUtils.cast((Collection<?>)schema.getImports().values());
for (List lst : imports) {
List<SchemaImport> impLst = CastUtils.cast(lst);
for (SchemaImport imp : impLst) {
String start = imp.getSchemaLocationURI();
if (start != null && !doneSchemas.containsKey(start)) {
- try {
- //check to see if it's aleady in a URL format. If so, leave it.
- new URL(start);
- } catch (MalformedURLException e) {
+ String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+ if (resolvedSchemaLocation == null) {
+ try {
+ //check to see if it's aleady in a URL format. If so, leave it.
+ new URL(start);
+ } catch (MalformedURLException e) {
+ doneSchemas.put(start, imp);
+ updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
+ }
+ } else {
doneSchemas.put(start, imp);
+ doneSchemas.put(resolvedSchemaLocation, imp);
updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
}
}
@@ -264,12 +318,23 @@
List<SchemaReference> includes = CastUtils.cast(schema.getIncludes());
for (SchemaReference included : includes) {
String start = included.getSchemaLocationURI();
- if (start != null && !doneSchemas.containsKey(start)) {
- try {
- //check to see if it's aleady in a URL format. If so, leave it.
- new URL(start);
- } catch (MalformedURLException e) {
+
+ if (start != null) {
+ String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+ if (resolvedSchemaLocation == null) {
+ if (!doneSchemas.containsKey(start)) {
+ try {
+ //check to see if it's aleady in a URL format. If so, leave it.
+ new URL(start);
+ } catch (MalformedURLException e) {
+ doneSchemas.put(start, included);
+ updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
+ }
+ }
+ } else if (!doneSchemas.containsKey(start)
+ || !doneSchemas.containsKey(resolvedSchemaLocation)) {
doneSchemas.put(start, included);
+ doneSchemas.put(resolvedSchemaLocation, included);
updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
}
}
@@ -289,10 +354,30 @@
} catch (MalformedURLException e) {
LOG.log(Level.WARNING, "URL creation failed: ", e);
}
- String port = String.valueOf(url.getPort());
- baseURI = baseURI.substring(baseURI.indexOf(port) + port.length(), baseURI.lastIndexOf("/"));
-
+ if (url != null) {
+ baseURI = url.getPath();
+ int idx = baseURI.lastIndexOf('/');
+ if (idx != -1) {
+ baseURI = baseURI.substring(0, idx);
+ }
+ }
return baseURI;
+ }
+
+ static Map<String, String> parseQueryString(String s) {
+ Map<String, String> ht = new HashMap<String, String>();
+ StringTokenizer st = new StringTokenizer(s, "&");
+ while (st.hasMoreTokens()) {
+ String pair = (String)st.nextToken();
+ int pos = pair.indexOf('=');
+ if (pos == -1) {
+ ht.put(pair.toLowerCase(), "");
+ } else {
+ ht.put(pair.substring(0, pos).toLowerCase(),
+ pair.substring(pos + 1));
+ }
+ }
+ return ht;
}
}
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java Thu Oct 25 10:09:20 2007
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.wsdl11;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -35,6 +36,8 @@
Bus bus;
String wsdlUrl;
InputSource last;
+ String baseUri;
+ boolean fromParent;
public ResourceManagerWSDLLocator(String wsdlUrl,
WSDLLocator parent,
@@ -53,13 +56,21 @@
public void close() {
- if (last != null) {
- parent.close();
+ if (!fromParent) {
+ try {
+ if (last.getByteStream() != null) {
+ last.getByteStream().close();
+ }
+ } catch (IOException e) {
+ //ignore
+ }
}
+ parent.close();
}
public InputSource getBaseInputSource() {
InputSource is = parent.getBaseInputSource();
+ fromParent = true;
if (is == null) {
InputStream ins = bus.getExtension(ResourceManager.class).getResourceAsStream(wsdlUrl);
is = new InputSource(ins);
@@ -71,29 +82,35 @@
is.setSystemId(url.toString());
is.setPublicId(url.toString());
}
- last = is;
+ fromParent = false;
+ baseUri = is.getPublicId();
} else {
- last = null;
+ baseUri = is.getSystemId();
}
+ last = is;
return is;
}
public String getBaseURI() {
- getBaseInputSource();
if (last == null) {
- return parent.getBaseURI();
+ getBaseInputSource();
+ try {
+ if (last.getByteStream() != null) {
+ last.getByteStream().close();
+ }
+ } catch (IOException e) {
+ //ignore
+ }
}
- return last.getPublicId();
+ return baseUri;
}
public InputSource getImportInputSource(String parentLocation, String importLocation) {
- // TODO Auto-generated method stub
return parent.getImportInputSource(parentLocation, importLocation);
}
public String getLatestImportURI() {
- // TODO Auto-generated method stub
return parent.getLatestImportURI();
}
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Thu Oct 25 10:09:20 2007
@@ -52,11 +52,11 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+
import com.ibm.wsdl.extensions.schema.SchemaImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.AbstractMessageContainer;
import org.apache.cxf.service.model.AbstractPropertiesHolder;
import org.apache.cxf.service.model.BindingFaultInfo;
@@ -72,9 +72,16 @@
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.cxf.wsdl.WSDLManager;
-import org.apache.ws.commons.schema.XmlSchemaSerializer;
-import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
+/**
+ * Consume a set of service definitions and produce a WSDL model. The ServiceInfo objects
+ * contain the bindings, operations, and ports, plus XMLSchema schemas.
+ *
+ * Each wsdl:definition has to have a single target namespace. The first service in the list
+ * defines the TNS of the overall WSDL. If a subsequent service has a divergent TNS, then
+ * the code creates a new definition element (i.e., Definition object), and imports it into
+ * the top-level object.
+ */
public final class ServiceWSDLBuilder {
private final Map<String, String> ns2prefix;
@@ -85,25 +92,64 @@
private int xsdCount;
private final Bus bus;
+ /**
+ * Sets up the builder on a bus with a list of services.
+ * @param b the bus.
+ * @param services the services.
+ */
public ServiceWSDLBuilder(Bus b, List<ServiceInfo> services) {
this.services = services;
bus = b;
ns2prefix = new HashMap<String, String>();
}
+
+ /**
+ * For callers who prefer varargs, an inline list of ServiceInfo objects instead of
+ * a List. Primarily used for tests or other callers with only one service in hand.
+ * @param b the bus.
+ * @param services the services.
+ */
public ServiceWSDLBuilder(Bus b, ServiceInfo ... services) {
this(b, Arrays.asList(services));
}
+
+ /**
+ * Set whether to emit references to imported schema files.
+ * This is only effective for {@link #build(Map)}, which is passed additional schemas for
+ * import. {@link #build()} resets this flag to false.
+ * @param b true to use imports.
+ */
public void setUseSchemaImports(boolean b) {
useSchemaImports = b;
}
+
+ /**
+ * Base filename for imported files.
+ * @param s pathname.
+ */
public void setBaseFileName(String s) {
baseFileName = s;
}
+ /**
+ * Create the WSDL Definition object and return it. This function will never create
+ * imports to schemas.
+ * @return the WSDL definition.
+ * @throws WSDLException
+ */
public Definition build() throws WSDLException {
useSchemaImports = false;
return build(null);
}
+
+ /**
+ * Create the WSDL Definition object and return it. This function respects the
+ * setting of {@link #setUseSchemaImports(boolean)}.
+ * @param imports A set of schema imports to either reference as imports or read and
+ * then inline.
+ * @return the WSDL definition
+ * @throws WSDLException
+ */
public Definition build(Map<String, SchemaInfo> imports) throws WSDLException {
try {
definition = services.get(0).getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class);
@@ -113,6 +159,7 @@
if (definition == null) {
ServiceInfo si = services.get(0);
definition = newDefinition(si.getName(), si.getTargetNamespace());
+ addNamespace(WSDLConstants.CONVENTIONAL_TNS_PREFIX, si.getTargetNamespace(), definition);
addExtensibiltyElements(definition, getWSDL11Extensors(si));
Collection<PortType> portTypes = new HashSet<PortType>();
@@ -127,7 +174,7 @@
wsdlImport.setNamespaceURI(tns);
wsdlImport.setLocationURI(service.getInterface().getName().getLocalPart() + ".wsdl");
definition.addImport(wsdlImport);
- addNamespace(tns);
+ addNamespace(getPrefix(tns), tns, definition);
}
portTypes.add(buildPortType(service.getInterface(), portTypeDef));
@@ -157,7 +204,12 @@
return d;
}
-
+ /**
+ * Return a list of ExtensibilityElements for a particular component, such as a BindingFaultInfo.
+ * This perhaps should be protected.
+ * @param holder The item containing the extensibility elements.
+ * @return the extensibility elements.
+ */
public List<ExtensibilityElement> getWSDL11Extensors(AbstractPropertiesHolder holder) {
return holder.getExtensors(ExtensibilityElement.class);
}
@@ -182,37 +234,15 @@
try {
doc = XMLUtils.newDocument();
} catch (ParserConfigurationException e) {
- //should not happen
+ throw new RuntimeException("DOM configuration problem", e);
}
- Element nd = XMLUtils.createElementNS(doc, new QName("http://www.w3.org/2001/XMLSchema",
+ Element nd = XMLUtils.createElementNS(doc, new QName(WSDLConstants.NU_SCHEMA_XSD,
"schema"));
- nd.setAttribute("xmlns", "http://www.w3.org/2001/XMLSchema");
+ nd.setAttribute("xmlns", WSDLConstants.NU_SCHEMA_XSD);
doc.appendChild(nd);
for (SchemaInfo schemaInfo : schemas) {
- if (schemaInfo.getSchema() != null) {
- Document[] docs;
- try {
- docs = XmlSchemaSerializer.serializeSchema(schemaInfo.getSchema(), false);
- } catch (XmlSchemaSerializerException e1) {
- throw new ServiceConstructionException(e1);
- }
- Element e = docs[0].getDocumentElement();
- // XXX A problem can occur with the ibm jdk when the XmlSchema
- // object is serialized. The xmlns declaration gets incorrectly
- // set to the same value as the targetNamespace attribute.
- // The aegis databinding tests demonstrate this particularly.
- if (e.getPrefix() == null
- && !WSDLConstants.NU_SCHEMA_XSD.equals(e.getAttributeNS(WSDLConstants.NU_XMLNS,
- WSDLConstants.NP_XMLNS))) {
- e.setAttributeNS(WSDLConstants.NU_XMLNS,
- WSDLConstants.NP_XMLNS,
- WSDLConstants.NU_SCHEMA_XSD);
- }
- schemaInfo.setElement(e);
- }
-
if (!useSchemaImports) {
SchemaImpl schemaImpl = new SchemaImpl();
schemaImpl.setRequired(true);
@@ -223,7 +253,7 @@
//imports
String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
Element imp = XMLUtils.createElementNS(doc,
- new QName("http://www.w3.org/2001/XMLSchema",
+ new QName(WSDLConstants.NU_SCHEMA_XSD,
"import"));
imp.setAttribute("schemaLocation", name);
imp.setAttribute("namespace", schemaInfo.getNamespaceURI());
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLDefinitionBuilder.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLDefinitionBuilder.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLDefinitionBuilder.java Thu Oct 25 10:09:20 2007
@@ -51,6 +51,7 @@
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.wsdl.JAXBExtensionHelper;
import org.apache.cxf.wsdl.WSDLBuilder;
+import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.cxf.wsdl.WSDLExtensibilityPlugin;
public class WSDLDefinitionBuilder implements WSDLBuilder<Definition> {
@@ -79,7 +80,7 @@
try {
wsdlFactory = WSDLFactory.newInstance();
registry = wsdlFactory.newPopulatedExtensionRegistry();
- QName header = new QName("http://schemas.xmlsoap.org/wsdl/soap/", "header");
+ QName header = new QName(WSDLConstants.WSDL11_NAMESPACE, "header");
registry.registerDeserializer(MIMEPart.class,
header,
new SOAPHeaderSerializer());
@@ -186,8 +187,8 @@
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Registering extension: " + elementType + " for parent: " + parentType);
}
- JAXBExtensionHelper.addExtensions(registry, parentType, elementType, getClass()
- .getClassLoader());
+ JAXBExtensionHelper.addExtensions(registry, parentType, elementType,
+ Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException ex) {
LOG.log(Level.WARNING, "EXTENSION_ADD_FAILED_MSG", ex);
} catch (JAXBException ex) {
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java Thu Oct 25 10:09:20 2007
@@ -51,6 +51,13 @@
String resolvedLocation = null;
if (catalogResolver != null) {
resolvedLocation = catalogResolver.resolveSystem(target);
+
+ if (resolvedLocation == null) {
+ resolvedLocation = catalogResolver.resolveURI(target);
+ }
+ if (resolvedLocation == null) {
+ resolvedLocation = catalogResolver.resolvePublic(target, base);
+ }
}
if (resolvedLocation == null) {
return this.resolver.resolve(target, base);
@@ -63,7 +70,7 @@
}
public InputSource getBaseInputSource() {
- InputSource result = resolve(baseUri, null);
+ InputSource result = resolve(baseUri, null);
baseUri = resolver.getURI();
return result;
}
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java Thu Oct 25 10:09:20 2007
@@ -206,8 +206,9 @@
private void registerInitialExtensions() throws BusException {
Properties initialExtensions = null;
try {
- initialExtensions = PropertiesLoaderUtils.loadAllProperties(EXTENSIONS_RESOURCE, Thread
- .currentThread().getContextClassLoader());
+ initialExtensions = PropertiesLoaderUtils.loadAllProperties(EXTENSIONS_RESOURCE,
+ Thread.currentThread()
+ .getContextClassLoader());
} catch (IOException ex) {
throw new BusException(ex);
}
@@ -220,8 +221,9 @@
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Registering extension: " + elementType + " for parent: " + parentType);
}
- JAXBExtensionHelper.addExtensions(registry, parentType, elementType, getClass()
- .getClassLoader());
+ JAXBExtensionHelper.addExtensions(registry, parentType, elementType,
+ Thread.currentThread()
+ .getContextClassLoader());
} catch (ClassNotFoundException ex) {
LOG.log(Level.WARNING, "EXTENSION_ADD_FAILED_MSG", ex);
} catch (JAXBException ex) {
Modified: incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java Thu Oct 25 10:09:20 2007
@@ -62,6 +62,7 @@
import org.apache.cxf.catalog.CatalogXmlSchemaURIResolver;
import org.apache.cxf.catalog.OASISCatalogManager;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.FixedExtensionDeserializer;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.service.model.AbstractMessageContainer;
import org.apache.cxf.service.model.AbstractPropertiesHolder;
@@ -273,6 +274,8 @@
private XmlSchemaCollection getSchemas(Definition def, ServiceInfo serviceInfo) {
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
serviceInfo.setXmlSchemaCollection(schemaCol);
+ schemaCol.getExtReg().setDefaultExtensionDeserializer(
+ new FixedExtensionDeserializer());
List<Definition> defList = new ArrayList<Definition>();
parseImports(def, defList);
@@ -616,7 +619,7 @@
checkForWrapped(opInfo, false);
}
- public static void checkForWrapped(OperationInfo opInfo, boolean allowRefs) {
+ public static void checkForWrapped(OperationInfo opInfo, boolean relaxed) {
MessageInfo inputMessage = opInfo.getInput();
MessageInfo outputMessage = opInfo.getOutput();
boolean passedRule = true;
@@ -647,8 +650,10 @@
} else {
QName inputElementName = inputPart.getElementQName();
inputEl = schemas.getElementByQName(inputElementName);
- if (inputEl == null || !opInfo.getName().getLocalPart().equals(inputElementName.getLocalPart())) {
+ if (inputEl == null) {
passedRule = false;
+ } else if (!opInfo.getName().getLocalPart().equals(inputElementName.getLocalPart())) {
+ passedRule = relaxed;
}
}
@@ -687,7 +692,7 @@
xsct = (XmlSchemaComplexType)inputEl.getSchemaType();
if (hasAttributes(xsct)
|| !isWrappableSequence(xsct, inputEl.getQName().getNamespaceURI(),
- unwrappedInput, allowRefs)) {
+ unwrappedInput, relaxed)) {
passedRule = false;
}
} else {
@@ -703,9 +708,12 @@
if (outputEl != null && outputEl.getSchemaType() instanceof XmlSchemaComplexType) {
xsct = (XmlSchemaComplexType)outputEl.getSchemaType();
+ if (xsct.isAbstract()) {
+ passedRule = false;
+ }
if (hasAttributes(xsct)
|| !isWrappableSequence(xsct, outputEl.getQName().getNamespaceURI(), unwrappedOutput,
- allowRefs)) {
+ relaxed)) {
passedRule = false;
}
} else {
Modified: incubator/cxf/branches/jliu/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/resources/META-INF/cxf/cxf.xml?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/resources/META-INF/cxf/cxf.xml Thu Oct 25 10:09:20 2007
@@ -37,6 +37,9 @@
</constructor-arg>
<property name="bus" ref="cxf"/>
</bean>
+ <bean id="org.apache.cxf.configuration.Configurer"
+ class="org.apache.cxf.configuration.spring.ConfigurerImpl">
+ </bean>
<bean id="org.apache.cxf.binding.BindingFactoryManager" class="org.apache.cxf.binding.BindingFactoryManagerImpl">
<constructor-arg>
@@ -93,7 +96,14 @@
<bean id="org.apache.cxf.transports.http.QueryHandlerRegistry" class="org.apache.cxf.transport.http.QueryHandlerRegistryImpl">
- <property name="bus" ref="cxf"/>
+ <constructor-arg ref="cxf"/>
+ <constructor-arg>
+ <list>
+ <bean class="org.apache.cxf.transport.http.WSDLQueryHandler">
+ <constructor-arg ref="cxf"/>
+ </bean>
+ </list>
+ </constructor-arg>
</bean>
<bean id="org.apache.cxf.endpoint.EndpointResolverRegistry" class="org.apache.cxf.endpoint.EndpointResolverRegistryImpl">
Modified: incubator/cxf/branches/jliu/rt/core/src/main/resources/schemas/core.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/main/resources/schemas/core.xsd?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/main/resources/schemas/core.xsd (original)
+++ incubator/cxf/branches/jliu/rt/core/src/main/resources/schemas/core.xsd Thu Oct 25 10:09:20 2007
@@ -45,6 +45,7 @@
</xsd:annotation>
<xsd:complexType>
<xsd:sequence />
+ <xsd:attribute name="limit" type="xsd:int" use="optional" default="102400"/>
</xsd:complexType>
</xsd:element>
Modified: incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java Thu Oct 25 10:09:20 2007
@@ -19,6 +19,7 @@
package org.apache.cxf.transport;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import org.apache.cxf.io.CachedOutputStream;
@@ -45,10 +46,12 @@
String result = initTestData(65);
cos.write(result.getBytes());
//assert tmp file is generated
- assertTrue(cos.getTempFile().exists());
+ File tempFile = cos.getTempFile();
+ assertNotNull(tempFile);
+ assertTrue(tempFile.exists());
cos.close();
//assert tmp file is deleted after close the CachedOutputStream
- assertFalse(cos.getTempFile().exists());
+ assertFalse(tempFile.exists());
}
String initTestData(int packetSize) {
Modified: incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java Thu Oct 25 10:09:20 2007
@@ -42,6 +42,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.transport.DestinationFactory;
@@ -57,7 +58,7 @@
public class ServiceWSDLBuilderTest extends Assert {
- private static final Logger LOG = Logger.getLogger(ServiceWSDLBuilderTest.class.getName());
+ private static final Logger LOG = LogUtils.getLogger(ServiceWSDLBuilderTest.class);
private static final String WSDL_PATH = "hello_world.wsdl";
private Definition def;
Modified: incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java (original)
+++ incubator/cxf/branches/jliu/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java Thu Oct 25 10:09:20 2007
@@ -44,6 +44,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.service.model.BindingFaultInfo;
@@ -71,7 +72,7 @@
public class WSDLServiceBuilderTest extends Assert {
// TODO: reuse the wsdl in testutils and add the parameter order into one of the wsdl
- private static final Logger LOG = Logger.getLogger(WSDLServiceBuilderTest.class.getName());
+ private static final Logger LOG = LogUtils.getLogger(WSDLServiceBuilderTest.class);
private static final String WSDL_PATH = "hello_world.wsdl";
private static final String BARE_WSDL_PATH = "hello_world_bare.wsdl";
private static final String IMPORT_WSDL_PATH = "hello_world_schema_import.wsdl";
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/pom.xml?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/pom.xml (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/pom.xml Thu Oct 25 10:09:20 2007
@@ -73,6 +73,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-testsupport</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java Thu Oct 25 10:09:20 2007
@@ -31,18 +31,24 @@
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.w3c.dom.Node;
+
import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
+import org.apache.cxf.aegis.type.Configuration;
import org.apache.cxf.aegis.type.DefaultTypeMappingRegistry;
import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.TypeCreator;
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.cxf.aegis.type.TypeMappingRegistry;
import org.apache.cxf.aegis.type.TypeUtil;
import org.apache.cxf.aegis.type.basic.BeanType;
-import org.apache.cxf.aegis.util.XmlConstants;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.util.SOAPConstants;
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.databinding.source.AbstractDataBinding;
import org.apache.cxf.frontend.MethodDispatcher;
import org.apache.cxf.frontend.SimpleMethodDispatcher;
import org.apache.cxf.service.Service;
@@ -51,9 +57,11 @@
import org.apache.cxf.service.model.FaultInfo;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
-import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.wsdl.WSDLConstants;
+import org.apache.cxf.wsdl11.WSDLServiceBuilder;
import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAnnotated;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.utils.NamespaceMap;
import org.jdom.Attribute;
@@ -64,11 +72,11 @@
import org.jdom.output.DOMOutputter;
/**
- * Handles DataBidning functions for Aegis.
+ * Handles DataBinding functions for Aegis.
* <p>
- * NOTE: There is an assumed 1:1 mapping between an AegisDatabidning and a Service!
+ * NOTE: There is an assumed 1:1 mapping between an AegisDatabinding and a Service!
*/
-public class AegisDatabinding implements DataBinding {
+public class AegisDatabinding extends AbstractDataBinding implements DataBinding {
public static final String CURRENT_MESSAGE_PART = "currentMessagePart";
public static final String TYPE_MAPPING_KEY = "type.mapping";
@@ -85,7 +93,9 @@
private Map<MessagePartInfo, Type> part2Type;
private List overrideTypes;
private Service service;
-
+ // allow applications to express an opinion about the namespace prefixes.
+ private Map<String, String> namespaceMap;
+
public AegisDatabinding() {
super();
this.typeMappingRegistry = new DefaultTypeMappingRegistry(true);
@@ -95,7 +105,7 @@
@SuppressWarnings("unchecked")
public <T> DataReader<T> createReader(Class<T> cls) {
if (cls.equals(XMLStreamReader.class)) {
- return (DataReader<T>)new XMLStreamDataReader(this);
+ return (DataReader<T>) new XMLStreamDataReader(this);
} else {
throw new UnsupportedOperationException();
}
@@ -105,6 +115,8 @@
public <T> DataWriter<T> createWriter(Class<T> cls) {
if (cls.equals(XMLStreamWriter.class)) {
return (DataWriter<T>)new XMLStreamDataWriter(this);
+ } else if (cls.equals(Node.class)) {
+ return (DataWriter<T>) new ElementDataWriter(this);
} else {
throw new UnsupportedOperationException();
}
@@ -115,7 +127,7 @@
}
public Class<?>[] getSupportedWriterFormats() {
- return new Class[] {XMLStreamWriter.class};
+ return new Class[] {XMLStreamWriter.class, Node.class};
}
public TypeMappingRegistry getTypeMappingRegistry() {
@@ -130,7 +142,7 @@
this.service = s;
QName serviceName = s.getServiceInfos().get(0).getName();
- TypeMapping serviceTM = typeMappingRegistry.createTypeMapping(XmlConstants.XSD, true);
+ TypeMapping serviceTM = typeMappingRegistry.createTypeMapping(SOAPConstants.XSD, true);
typeMappingRegistry.register(serviceName.getNamespaceURI(), serviceTM);
s.put(TypeMapping.class.getName(), serviceTM);
@@ -158,6 +170,15 @@
}
createSchemas(s, deps);
+ for (ServiceInfo info : s.getServiceInfos()) {
+ for (OperationInfo opInfo : info.getInterface().getOperations()) {
+ if (opInfo.isUnwrappedCapable()) {
+ initializeOperationTypes(info, opInfo.getUnwrappedOperation());
+ } else {
+ initializeOperationTypes(info, opInfo);
+ }
+ }
+ }
}
List<Type> getAdditionalTypes(Service s, TypeMapping tm) {
@@ -210,6 +231,23 @@
throw e;
}
}
+ private void initializeOperationTypes(ServiceInfo s, OperationInfo opInfo) {
+ try {
+ initializeMessageTypes(s, opInfo.getInput(), IN_PARAM);
+
+ if (opInfo.hasOutput()) {
+ initializeMessageTypes(s, opInfo.getOutput(), OUT_PARAM);
+ }
+
+ for (FaultInfo info : opInfo.getFaults()) {
+ initializeMessageTypes(s, info, FAULT_PARAM);
+ }
+
+ } catch (DatabindingException e) {
+ e.prepend("Error initializing parameters for operation " + opInfo.getName());
+ throw e;
+ }
+ }
protected void initializeMessage(Service s, TypeMapping serviceTM,
AbstractMessageContainer container,
@@ -234,6 +272,21 @@
}
}
+ protected void initializeMessageTypes(ServiceInfo s,
+ AbstractMessageContainer container,
+ int partType) {
+ XmlSchemaCollection col = s.getXmlSchemaCollection();
+ for (Iterator itr = container.getMessageParts().iterator(); itr.hasNext();) {
+ MessagePartInfo part = (MessagePartInfo)itr.next();
+ if (part.isElement()) {
+ XmlSchemaAnnotated tp = col.getElementByQName(part.getElementQName());
+ part.setXmlSchema(tp);
+ } else {
+ XmlSchemaAnnotated tp = col.getTypeByQName(part.getTypeQName());
+ part.setXmlSchema(tp);
+ }
+ }
+ }
private void addDependencies(Set<Type> deps, Type type) {
Set<Type> typeDeps = type.getDependencies();
if (typeDeps != null) {
@@ -258,11 +311,44 @@
}
types.add(t);
}
+ for (ServiceInfo si : s.getServiceInfos()) {
+ XmlSchemaCollection col = (XmlSchemaCollection)si
+ .getProperty(WSDLServiceBuilder.WSDL_SCHEMA_LIST);
+
+ if (col != null) {
+ // someone has already filled in the types
+ continue;
+ }
+
+ col = new XmlSchemaCollection();
+ si.setProperty(WSDLServiceBuilder.WSDL_SCHEMA_LIST, col);
+ si.setXmlSchemaCollection(col);
+ }
for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
- Element e = new Element("schema", "xsd", XmlConstants.XSD);
+ String xsdPrefix = SOAPConstants.XSD_PREFIX;
+ if (namespaceMap != null && namespaceMap.containsKey(SOAPConstants.XSD)) {
+ xsdPrefix = namespaceMap.get(SOAPConstants.XSD);
+ }
+
+ Element e = new Element("schema", xsdPrefix, SOAPConstants.XSD);
+
+ e.setAttribute(new Attribute(WSDLConstants.ATTR_TNS, entry.getKey()));
+
+ if (null != namespaceMap) { // did application hand us some additional namespaces?
+ for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
+ // user gives us namespace->prefix mapping.
+ e.addNamespaceDeclaration(Namespace.getNamespace(mapping.getValue(),
+ mapping.getKey()));
+ }
+ }
- e.setAttribute(new Attribute("targetNamespace", entry.getKey()));
+ // if the user didn't pick something else, assign 'tns' as the prefix.
+ if (namespaceMap == null || !namespaceMap.containsKey(entry.getKey())) {
+ // Schemas are more readable if there is a specific prefix for the TNS.
+ e.addNamespaceDeclaration(Namespace.getNamespace(WSDLConstants.CONVENTIONAL_TNS_PREFIX,
+ entry.getKey()));
+ }
e.setAttribute(new Attribute("elementFormDefault", "qualified"));
e.setAttribute(new Attribute("attributeFormDefault", "qualified"));
@@ -275,31 +361,31 @@
}
try {
- XmlSchemaCollection col = new XmlSchemaCollection();
NamespaceMap nsMap = new NamespaceMap();
- nsMap.add("xsd", "http://www.w3.org/2001/XMLSchema");
-
+
+ nsMap.add(xsdPrefix, SOAPConstants.XSD);
+
+ // We prefer explicit prefixes over those generated in the types.
+ // This loop may have intended to support prefixes from individual aegis files,
+ // but that isn't a good idea.
for (Iterator itr = e.getAdditionalNamespaces().iterator(); itr.hasNext();) {
Namespace n = (Namespace) itr.next();
- nsMap.add(n.getPrefix(), n.getURI());
+ if (!nsMap.containsValue(n.getURI())) {
+ nsMap.add(n.getPrefix(), n.getURI());
+ }
}
-
- col.setNamespaceContext(nsMap);
org.w3c.dom.Document schema = new DOMOutputter().output(new Document(e));
for (ServiceInfo si : s.getServiceInfos()) {
- SchemaInfo info = new SchemaInfo(si, entry.getKey());
-
- info.setElement(schema.getDocumentElement());
-
- XmlSchema xmlSchema = col.read(schema.getDocumentElement());
+ XmlSchemaCollection col = (XmlSchemaCollection)si
+ .getProperty(WSDLServiceBuilder.WSDL_SCHEMA_LIST);
+ col.setNamespaceContext(nsMap);
+ XmlSchema xmlSchema = addSchemaDocument(si, col, schema, entry.getKey());
+ // Work around bug in JDOM DOMOutputter which fails to correctly
+ // assign namespaces to attributes. If JDOM worked right,
+ // the collection object would get the prefixes for itself.
xmlSchema.setNamespaceContext(nsMap);
- info.setSchema(xmlSchema);
-
- info.setSystemId(entry.getKey());
-
- si.addSchema(info);
}
} catch (JDOMException e1) {
throw new ServiceConstructionException(e1);
@@ -328,7 +414,7 @@
return name;
}
-
+
private Type getParameterType(Service s, TypeMapping tm, MessagePartInfo param, int paramtype) {
Type type = tm.getType(param.getTypeQName());
@@ -341,23 +427,37 @@
if (paramtype == OUT_PARAM) {
offset = 1;
}
+
+ TypeCreator typeCreator = tm.getTypeCreator();
if (type == null) {
OperationInfo op = param.getMessageInfo().getOperation();
Method m = getMethod(s, op);
+ TypeClassInfo info;
if (paramtype != FAULT_PARAM && m != null) {
-
- /*
- * Note: we are not registering the type here, because it is an
- * anonymous type. Potentially there could be many schema types
- * with this name. For example, there could be many ns:in0
- * paramters.
- */
- type = tm.getTypeCreator().createType(m, param.getIndex() - offset);
+ info = typeCreator.createClassInfo(m, param.getIndex() - offset);
} else {
- type = tm.getTypeCreator().createType(param.getTypeClass());
+ info = typeCreator.createBasicClassInfo(param.getTypeClass());
+ }
+ if (param.getMessageInfo().getOperation().isUnwrapped()
+ && param.getTypeClass().isArray()) {
+ //The service factory expects arrays going into the wrapper to be
+ //mapped to the array component type and will then add
+ //min=0/max=unbounded. That doesn't work for Aegis where we
+ //already created a wrapper ArrayType so we'll let it know we want the default.
+ param.setProperty("minOccurs", "1");
+ param.setProperty("maxOccurs", "1");
+ param.setProperty("nillable", Boolean.TRUE);
+ }
+ if (info.getMappedName() != null) {
+ param.setConcreteName(info.getMappedName());
+ param.setName(info.getMappedName());
+ }
+ type = typeCreator.createTypeForClass(info);
+ // We have to register the type if we want minOccurs and such to work.
+ if (info.nonDefaultAttributes()) {
+ tm.register(type);
}
-
type.setTypeMapping(tm);
part2Type.put(param, type);
@@ -383,5 +483,52 @@
public Service getService() {
return service;
}
-
+
+ /**
+ * @return Returns the namespaceMap.
+ */
+ public Map<String, String> getNamespaceMap() {
+ return namespaceMap;
+ }
+
+ /**
+ * @param namespaceMap The namespaceMap to set.
+ */
+ public void setNamespaceMap(Map<String, String> namespaceMap) {
+ // make some checks. This is a map from namespace to prefix, but we want unique prefixes.
+ if (namespaceMap != null) {
+ Set<String> prefixesSoFar = new HashSet<String>();
+ for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
+ if (prefixesSoFar.contains(mapping.getValue())) {
+ throw new IllegalArgumentException("Duplicate prefix " + mapping.getValue());
+ }
+ }
+ }
+ this.namespaceMap = namespaceMap;
+ }
+
+ /**
+ * Provide explicit mappings to ReflectionServiceFactory.
+ * {@inheritDoc}
+ * */
+ public Map<String, String> getDeclaredNamespaceMappings() {
+ return this.namespaceMap;
+ }
+
+ /**
+ * Return the type mapping configuration associated with this databinding object.
+ * The configuration is retrieved from the type mapping registry.
+ * @return Returns the configuration.
+ */
+ public Configuration getConfiguration() {
+ return typeMappingRegistry.getConfiguration();
+ }
+
+ /**
+ * Set the configuration for this databinding object.
+ * @param configuration The configuration to set.
+ */
+ public void setConfiguration(Configuration configuration) {
+ typeMappingRegistry.setConfiguration(configuration);
+ }
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java Thu Oct 25 10:09:20 2007
@@ -94,6 +94,7 @@
MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
if (type.isNillable() && type.isWriteOuter() && obj == null) {
w2.writeXsiNil();
+ w2.close();
return;
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java Thu Oct 25 10:09:20 2007
@@ -96,7 +96,7 @@
return info;
}
- protected Type createTypeForClass(TypeClassInfo info) {
+ public Type createTypeForClass(TypeClassInfo info) {
Class javaType = info.getTypeClass();
Type result = null;
boolean newType = true;
@@ -249,7 +249,7 @@
}
protected Type getOrCreateMapValueType(TypeClassInfo info) {
- return nextCreator.getOrCreateMapKeyType(info);
+ return nextCreator.getOrCreateMapValueType(info);
}
protected Type createMapType(TypeClassInfo info, Type keyType, Type valueType) {
@@ -306,6 +306,19 @@
String first = type.getSchemaType().getLocalPart().substring(0, 1);
String last = type.getSchemaType().getLocalPart().substring(1);
String localName = "ArrayOf" + first.toUpperCase() + last;
+ if (info.nonDefaultAttributes()) {
+ localName += "-";
+ if (info.getMaxOccurs() >= 0) {
+ localName += info.maxOccurs;
+ }
+ localName += "-";
+ if (info.getMinOccurs() >= 0) {
+ localName += info.minOccurs;
+ }
+ if (info.isFlat()) {
+ localName += "Flat";
+ }
+ }
return new QName(ns, localName);
}
@@ -368,6 +381,9 @@
this.typeConfiguration = tpConfiguration;
}
+ /**
+ * Object to carry information for a type, such as that from an XML mapping file.
+ */
public static class TypeClassInfo {
Class typeClass;
@@ -376,7 +392,8 @@
Object genericType;
Object keyType;
-
+ Object valueType;
+
QName mappedName;
QName typeName;
@@ -388,6 +405,10 @@
long minOccurs = -1;
long maxOccurs = -1;
boolean flat;
+
+ public boolean nonDefaultAttributes() {
+ return minOccurs != -1 || maxOccurs != -1 || flat;
+ }
public String getDescription() {
return description;
@@ -475,6 +496,19 @@
public void setFlat(boolean flat) {
this.flat = flat;
+ }
+
+ @Override
+ public String toString() {
+ return "TypeClassInfo " + getDescription();
+ }
+
+ public Object getValueType() {
+ return valueType;
+ }
+
+ public void setValueType(Object valueType) {
+ this.valueType = valueType;
}
}
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeCreator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeCreator.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeCreator.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeCreator.java Thu Oct 25 10:09:20 2007
@@ -37,6 +37,7 @@
@Override
public TypeClassInfo createClassInfo(Method m, int index) {
TypeClassInfo info = new TypeClassInfo();
+ info.setDescription("method " + m.getName() + " parameter " + index);
if (index >= 0) {
info.setTypeClass(m.getParameterTypes()[index]);
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java Thu Oct 25 10:09:20 2007
@@ -67,9 +67,9 @@
import org.apache.cxf.aegis.type.xml.JDOMElementType;
import org.apache.cxf.aegis.type.xml.SourceType;
import org.apache.cxf.aegis.type.xml.XMLStreamReaderType;
-import org.apache.cxf.aegis.util.XmlConstants;
import org.apache.cxf.binding.soap.Soap11;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.util.SOAPConstants;
import org.jdom.Element;
/**
@@ -78,37 +78,38 @@
* @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
* @since Feb 22, 2004
*/
-public final class DefaultTypeMappingRegistry implements TypeMappingRegistry {
- static final QName XSD_STRING = new QName(XmlConstants.XSD, "string", XmlConstants.XSD_PREFIX);
- static final QName XSD_LONG = new QName(XmlConstants.XSD, "long", XmlConstants.XSD_PREFIX);
- static final QName XSD_FLOAT = new QName(XmlConstants.XSD, "float", XmlConstants.XSD_PREFIX);
- static final QName XSD_DOUBLE = new QName(XmlConstants.XSD, "double", XmlConstants.XSD_PREFIX);
- static final QName XSD_INT = new QName(XmlConstants.XSD, "int", XmlConstants.XSD_PREFIX);
- static final QName XSD_SHORT = new QName(XmlConstants.XSD, "short", XmlConstants.XSD_PREFIX);
- static final QName XSD_BOOLEAN = new QName(XmlConstants.XSD,
- "boolean", XmlConstants.XSD_PREFIX);
- static final QName XSD_DATETIME = new QName(XmlConstants.XSD, "dateTime",
- XmlConstants.XSD_PREFIX);
- static final QName XSD_TIME = new QName(XmlConstants.XSD, "dateTime", XmlConstants.XSD_PREFIX);
- static final QName XSD_BASE64 = new QName(XmlConstants.XSD, "base64Binary",
- XmlConstants.XSD_PREFIX);
- static final QName XSD_DECIMAL = new QName(XmlConstants.XSD,
- "decimal", XmlConstants.XSD_PREFIX);
- static final QName XSD_INTEGER = new QName(XmlConstants.XSD,
- "integer", XmlConstants.XSD_PREFIX);
- static final QName XSD_URI = new QName(XmlConstants.XSD, "anyURI", XmlConstants.XSD_PREFIX);
- static final QName XSD_ANY = new QName(XmlConstants.XSD, "anyType", XmlConstants.XSD_PREFIX);
-
- static final QName XSD_DATE = new QName(XmlConstants.XSD, "date", XmlConstants.XSD_PREFIX);
- static final QName XSD_DURATION = new QName(XmlConstants.XSD, "duration",
- XmlConstants.XSD_PREFIX);
- static final QName XSD_G_YEAR_MONTH = new QName(XmlConstants.XSD, "gYearMonth",
- XmlConstants.XSD_PREFIX);
- static final QName XSD_G_MONTH_DAY = new QName(XmlConstants.XSD, "gMonthDay",
- XmlConstants.XSD_PREFIX);
- static final QName XSD_G_YEAR = new QName(XmlConstants.XSD, "gYear", XmlConstants.XSD_PREFIX);
- static final QName XSD_G_MONTH = new QName(XmlConstants.XSD, "gMonth", XmlConstants.XSD_PREFIX);
- static final QName XSD_G_DAY = new QName(XmlConstants.XSD, "gDay", XmlConstants.XSD_PREFIX);
+public final class DefaultTypeMappingRegistry extends AbstractTypeMappingRegistry
+ implements TypeMappingRegistry {
+ static final QName XSD_STRING = new QName(SOAPConstants.XSD, "string", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_LONG = new QName(SOAPConstants.XSD, "long", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_FLOAT = new QName(SOAPConstants.XSD, "float", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_DOUBLE = new QName(SOAPConstants.XSD, "double", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_INT = new QName(SOAPConstants.XSD, "int", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_SHORT = new QName(SOAPConstants.XSD, "short", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_BOOLEAN = new QName(SOAPConstants.XSD,
+ "boolean", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_DATETIME = new QName(SOAPConstants.XSD, "dateTime",
+ SOAPConstants.XSD_PREFIX);
+ static final QName XSD_TIME = new QName(SOAPConstants.XSD, "dateTime", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_BASE64 = new QName(SOAPConstants.XSD, "base64Binary",
+ SOAPConstants.XSD_PREFIX);
+ static final QName XSD_DECIMAL = new QName(SOAPConstants.XSD,
+ "decimal", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_INTEGER = new QName(SOAPConstants.XSD,
+ "integer", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_URI = new QName(SOAPConstants.XSD, "anyURI", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_ANY = new QName(SOAPConstants.XSD, "anyType", SOAPConstants.XSD_PREFIX);
+
+ static final QName XSD_DATE = new QName(SOAPConstants.XSD, "date", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_DURATION = new QName(SOAPConstants.XSD, "duration",
+ SOAPConstants.XSD_PREFIX);
+ static final QName XSD_G_YEAR_MONTH = new QName(SOAPConstants.XSD, "gYearMonth",
+ SOAPConstants.XSD_PREFIX);
+ static final QName XSD_G_MONTH_DAY = new QName(SOAPConstants.XSD, "gMonthDay",
+ SOAPConstants.XSD_PREFIX);
+ static final QName XSD_G_YEAR = new QName(SOAPConstants.XSD, "gYear", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_G_MONTH = new QName(SOAPConstants.XSD, "gMonth", SOAPConstants.XSD_PREFIX);
+ static final QName XSD_G_DAY = new QName(SOAPConstants.XSD, "gDay", SOAPConstants.XSD_PREFIX);
static final String ENCODED_NS = Soap11.getInstance().getSoapEncodingStyle();
static final QName ENCODED_STRING = new QName(ENCODED_NS, "string");
@@ -133,8 +134,6 @@
private TypeCreator typeCreator;
- private Configuration typeConfiguration;
-
public DefaultTypeMappingRegistry() {
this(false);
}
@@ -147,7 +146,6 @@
registry = Collections.synchronizedMap(new HashMap<String, TypeMapping>());
this.typeCreator = typeCreator;
- this.typeConfiguration = new Configuration();
if (createDefault) {
createDefaultMappings();
@@ -346,7 +344,7 @@
register(ENCODED_NS, soapTM);
- register(XmlConstants.XSD, tm);
+ register(SOAPConstants.XSD, tm);
registerDefault(tm);
return tm;
@@ -435,13 +433,4 @@
tm.register(class1, name, type);
}
-
- public Configuration getConfiguration() {
- return typeConfiguration;
- }
-
- public void setConfiguration(Configuration tpConfiguration) {
- this.typeConfiguration = tpConfiguration;
- }
-
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeCreator.java Thu Oct 25 10:09:20 2007
@@ -24,6 +24,8 @@
import javax.xml.namespace.QName;
+import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
+
/**
* @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
*/
@@ -50,4 +52,24 @@
void setParent(TypeCreator creator);
void setTypeMapping(TypeMapping typeMapping);
+ /** Retrieve the classInfo for a method. Needed to get parameters right.
+ *
+ * @param m Method object
+ * @param index index in the parameter list
+ * @return info
+ */
+ TypeClassInfo createClassInfo(Method m, int index);
+ /**
+ * Retrieve the class info for a class. Needed to get parameters right.
+ * @param itemClass
+ * @return info
+ */
+ TypeClassInfo createBasicClassInfo(Class<?> itemClass);
+
+ /**
+ * Turn a TypeClassInfo into a type.
+ * @param info
+ * @return
+ */
+ Type createTypeForClass(TypeClassInfo info);
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMappingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMappingRegistry.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMappingRegistry.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMappingRegistry.java Thu Oct 25 10:09:20 2007
@@ -114,4 +114,14 @@
* TypeMappingRegistry.
*/
void clear();
+
+ /**
+ * Set the type configuration for this type mapping registry.
+ * @param configuration
+ */
+ void setConfiguration(Configuration configuration);
+ /**
+ * @return the configuration.
+ */
+ Configuration getConfiguration();
}
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java Thu Oct 25 10:09:20 2007
@@ -25,7 +25,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.aegis.Context;
import org.apache.cxf.aegis.util.NamespaceHelper;
-import org.apache.cxf.aegis.util.XmlConstants;
+import org.apache.cxf.common.util.SOAPConstants;
/**
* Static methods/constants for Aegis.
@@ -44,7 +44,7 @@
return type;
}
- String overrideType = xsr.getAttributeValue(XmlConstants.XSI_NS, "type");
+ String overrideType = xsr.getAttributeValue(SOAPConstants.XSI_NS, "type");
if (overrideType != null) {
QName overrideTypeName = NamespaceHelper.createQName(xsr.getNamespaceContext(), overrideType);
if (!overrideTypeName.equals(type.getSchemaType())) {
Modified: incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java?rev=588283&r1=588282&r2=588283&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java (original)
+++ incubator/cxf/branches/jliu/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java Thu Oct 25 10:09:20 2007
@@ -19,16 +19,29 @@
package org.apache.cxf.aegis.type;
import java.beans.PropertyDescriptor;
+import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -36,12 +49,12 @@
import org.apache.cxf.aegis.type.basic.BeanType;
import org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo;
import org.apache.cxf.aegis.util.NamespaceHelper;
-import org.apache.cxf.aegis.util.jdom.StaxBuilder;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
+import org.jdom.input.DOMBuilder;
import org.jdom.xpath.XPath;
/**
@@ -79,7 +92,6 @@
* uniquely identify it. So in the example above, the mapping specifies will
* apply to both method 1 and method 2, since the parameter at index 0 is not
* specified.
- *
*/
public class XMLTypeCreator extends AbstractTypeCreator {
private static final Log LOG = LogFactory.getLog(XMLTypeCreator.class);
@@ -91,9 +103,84 @@
stopClasses.add(Throwable.class);
}
+ private static DocumentBuilderFactory aegisDocumentBuilderFactory;
+ private static Schema aegisSchema;
// cache of classes to documents
private Map<String, Document> documents = new HashMap<String, Document>();
+ static {
+ String path = "/META-INF/cxf/aegis.xsd";
+ InputStream is = XMLTypeCreator.class.getResourceAsStream(path);
+ if (is != null) {
+ try {
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ aegisSchema = schemaFactory.newSchema(new StreamSource(is));
+ is.close();
+
+ aegisDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
+ aegisDocumentBuilderFactory.setSchema(aegisSchema);
+ } catch (IOException ie) {
+ LOG.error("Error reading Aegis schema", ie);
+ } catch (FactoryConfigurationError e) {
+ LOG.error("Error reading Aegis schema", e);
+ } catch (SAXException e) {
+ LOG.error("Error reading Aegis schema", e);
+ }
+ }
+ }
+
+ private Document readAegisFile(InputStream is, final String path) throws IOException {
+ DocumentBuilder documentBuilder;
+ try {
+ documentBuilder = aegisDocumentBuilderFactory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ LOG.error("Unable to create a document builder, e");
+ throw new RuntimeException("Unable to create a document builder, e");
+ }
+ org.w3c.dom.Document doc;
+ documentBuilder.setErrorHandler(new ErrorHandler() {
+
+ private String errorMessage(SAXParseException exception) {
+ return MessageFormat.format("{0} at {1} line {2} column {3}.",
+ new Object[] {exception.getMessage(), path,
+ Integer.valueOf(exception.getLineNumber()),
+ Integer.valueOf(exception.getColumnNumber())});
+ }
+
+ private void throwDatabindingException(String message) {
+ //DatabindingException is quirky. This dance is required to get the full message
+ //to where it belongs.
+ DatabindingException e = new DatabindingException(message);
+ e.setMessage(message);
+ throw e;
+ }
+
+ public void error(SAXParseException exception) throws SAXException {
+ String message = errorMessage(exception);
+ LOG.error(message, exception);
+ throwDatabindingException(message);
+
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ String message = errorMessage(exception);
+ LOG.error(message, exception);
+ throwDatabindingException(message);
+ }
+ public void warning(SAXParseException exception) throws SAXException {
+ LOG.info(errorMessage(exception), exception);
+ }
+ });
+
+ try {
+ doc = documentBuilder.parse(is);
+ } catch (SAXException e) {
+ LOG.error("Error parsing Aegis file.", e); // can't happen due to
+ // above.
+ return null;
+ }
+ return new DOMBuilder().build(doc);
+ }
protected Document getDocument(Class clazz) {
if (clazz == null) {
@@ -111,13 +198,13 @@
}
LOG.debug("Found mapping file : " + path);
try {
- doc = new StaxBuilder().build(is);
+ doc = readAegisFile(is, path);
documents.put(clazz.getName(), doc);
return doc;
- } catch (XMLStreamException e) {
+ } catch (IOException e) {
LOG.error("Error loading file " + path, e);
+ return null;
}
- return null;
}
@Override
@@ -163,6 +250,7 @@
TypeClassInfo info = new TypeClassInfo();
info.setTypeClass(pd.getReadMethod().getReturnType());
+ info.setDescription("property " + pd);
readMetadata(info, mapping, propertyEl);
return info;
@@ -292,10 +380,19 @@
}
// find the elements that apply to the specified method
- TypeClassInfo info = new TypeClassInfo();
+ TypeClassInfo info = nextCreator.createClassInfo(m, index); // start
+ // with the
+ // java5
+ // (or whatever) version.
+ if (info == null) {
+ info = new TypeClassInfo();
+ }
+
+ info.setDescription("method " + m.getName() + " parameter " + index);
if (index >= 0) {
if (index >= m.getParameterTypes().length) {
- throw new DatabindingException("Method " + m
+ throw new DatabindingException("Method "
+ + m
+ " does not have a parameter at index "
+ index);
}
@@ -305,14 +402,14 @@
+ "']/parameter[@index='" + index + "']/parent::*");
if (nodes.size() == 0) {
// no mapping for this method
- return nextCreator.createClassInfo(m, index);
+ return info;
}
// pick the best matching node
Element bestMatch = getBestMatch(mapping, m, nodes);
if (bestMatch == null) {
// no mapping for this method
- return nextCreator.createClassInfo(m, index);
+ return info;
}
info.setTypeClass(m.getParameterTypes()[index]);
// info.setAnnotations(m.getParameterAnnotations()[index]);
@@ -322,12 +419,12 @@
List<Element> nodes = getMatches(mapping, "./method[@name='" + m.getName()
+ "']/return-type/parent::*");
if (nodes.size() == 0) {
- return nextCreator.createClassInfo(m, index);
+ return info;
}
Element bestMatch = getBestMatch(mapping, m, nodes);
if (bestMatch == null) {
// no mapping for this method
- return nextCreator.createClassInfo(m, index);
+ return info;
}
info.setTypeClass(m.getReturnType());
// info.setAnnotations(m.getAnnotations());
@@ -343,6 +440,7 @@
info.setMappedName(createQName(parameter, parameter.getAttributeValue("mappedName")));
setComponentType(info, mapping, parameter);
setKeyType(info, mapping, parameter);
+ setValueType(info, mapping, parameter);
setType(info, parameter);
String min = parameter.getAttributeValue("minOccurs");
@@ -403,7 +501,7 @@
protected Type getOrCreateMapValueType(TypeClassInfo info) {
Type type = null;
if (info.getGenericType() != null) {
- type = createTypeFromGeneric(info.getGenericType());
+ type = createTypeFromGeneric(info.getValueType());
}
if (type == null) {
@@ -430,6 +528,7 @@
}
TypeClassInfo componentInfo = new TypeClassInfo();
+ componentInfo.setDescription("generic component " + componentInfo.getDescription());
readMetadata(componentInfo, mapping, propertyEl);
String className = propertyEl.getAttributeValue("class");
if (className == null) {
@@ -471,6 +570,13 @@
}
}
+ private void setValueType(TypeClassInfo info, Element mapping, Element parameter) {
+ String componentType = parameter.getAttributeValue("valueType");
+ if (componentType != null) {
+ info.setValueType(loadGeneric(info, mapping, componentType));
+ }
+ }
+
private Element getBestMatch(Element mapping, Method method, List<Element> availableNodes) {
// first find all the matching method names
List<Element> nodes = getMatches(mapping, "./method[@name='" + method.getName() + "']");
@@ -497,13 +603,13 @@
// first we check if the parameter index is specified
Element match = getMatch(element, "parameter[@index='" + i + "']");
if (match != null
- // we check if the type is specified and matches
+ // we check if the type is specified and matches
&& match.getAttributeValue("class") != null
// if it doesn't match, then we can definitely rule out
// this result
&& !match.getAttributeValue("class").equals(parameterType.getName())) {
-
- iterator.remove();
+
+ iterator.remove();
}
}
}