cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1185862 - in /cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools: JibxSchemaHelper.java JibxSchemaResolver.java JibxToolingDataBinding.java
Date Tue, 18 Oct 2011 21:06:24 GMT
Author: dkulp
Date: Tue Oct 18 21:06:23 2011
New Revision: 1185862

URL: http://svn.apache.org/viewvc?rev=1185862&view=rev
Log:
Fix some issues in the jibx tooling (and workaround issues in Jibx
itself)

Modified:
    cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaHelper.java
    cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaResolver.java
    cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxToolingDataBinding.java

Modified: cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaHelper.java?rev=1185862&r1=1185861&r2=1185862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaHelper.java
(original)
+++ cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaHelper.java
Tue Oct 18 21:06:23 2011
@@ -42,11 +42,11 @@ import org.apache.cxf.catalog.CatalogXml
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.ws.commons.schema.XmlSchema;
-import org.jibx.schema.ISchemaResolver;
 
 public class JibxSchemaHelper {
 
     private final Map<String, Element> schemaList;
+    private List<JibxSchemaResolver> resolvers;
     private final Map<String, String> catalogResolved = new HashMap<String, String>();
     private final Bus bus;
 
@@ -56,10 +56,11 @@ public class JibxSchemaHelper {
     }
 
     public void getSchemas(final Definition def, final SchemaCollection schemaCol,
-                           List<ISchemaResolver> resolvers) {
+                           List<JibxSchemaResolver> r) {
+        this.resolvers = r;
         List<Definition> defList = new ArrayList<Definition>();
         parseImports(def, defList);
-        extractSchema(def, schemaCol, resolvers);
+        extractSchema(def, schemaCol);
         // added
         getSchemaList(def);
 
@@ -67,7 +68,7 @@ public class JibxSchemaHelper {
         done.put(def, def);
         for (Definition def2 : defList) {
             if (!done.containsKey(def2)) {
-                extractSchema(def2, schemaCol, resolvers);
+                extractSchema(def2, schemaCol);
                 // added
                 getSchemaList(def2);
                 done.put(def2, def2);
@@ -75,7 +76,7 @@ public class JibxSchemaHelper {
         }
     }
 
-    private void extractSchema(Definition def, SchemaCollection schemaCol, List<ISchemaResolver>
resolvers) {
+    private void extractSchema(Definition def, SchemaCollection schemaCol) {
         Types typesElement = def.getTypes();
         if (typesElement != null) {
             int schemaCount = 1;
@@ -119,7 +120,8 @@ public class JibxSchemaHelper {
                         XmlSchema xmlSchema = schemaCol.read(schemaElem, systemId);
                         catalogResolved.putAll(schemaResolver.getResolvedMap());
 
-                        JibxSchemaResolver resolver = new JibxSchemaResolver(systemId, xmlSchema,
schemaCol);
+                        JibxSchemaResolver resolver 
+                            = new JibxSchemaResolver(systemId, xmlSchema, schemaCol, schemaElem);
                         resolvers.add(resolver);
 
                         // SchemaInfo schemaInfo = new SchemaInfo(xmlSchema.getTargetNamespace());
@@ -167,8 +169,15 @@ public class JibxSchemaHelper {
     private void addSchema(String docBaseURI, Schema schema) {
         // String docBaseURI = schema.getDocumentBaseURI();
         Element schemaEle = schema.getElement();
-        if (schemaList.get(docBaseURI) == null) {
-            schemaList.put(docBaseURI, schemaEle);
+        String name = docBaseURI;
+        for (JibxSchemaResolver r : resolvers) {
+            if (schemaEle == r.getElement()) {
+                name = r.getId();
+            }
+        }
+        
+        if (schemaList.get(name) == null) {
+            schemaList.put(name, schemaEle);
         } else if (schemaList.get(docBaseURI) != null && schemaList.containsValue(schemaEle))
{
             // do nothing
         } else {

Modified: cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaResolver.java?rev=1185862&r1=1185861&r2=1185862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaResolver.java
(original)
+++ cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxSchemaResolver.java
Tue Oct 18 21:06:23 2011
@@ -25,6 +25,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
+import org.w3c.dom.Element;
+
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.common.xmlschema.SchemaCollection;
@@ -39,13 +41,15 @@ public class JibxSchemaResolver implemen
     private String id;
     private String name;
     private XmlSchema schema;
+    private Element element;
     private SchemaCollection collection;
 
-    public JibxSchemaResolver(String id, XmlSchema schema, SchemaCollection collection) {
+    public JibxSchemaResolver(String id, XmlSchema schema, SchemaCollection collection, Element
element) {
         this.id = id;
         setName(id);
         this.schema = schema;
         this.collection = collection;
+        this.element = element;
     }
 
     public InputStream getContent() throws IOException {
@@ -57,13 +61,18 @@ public class JibxSchemaResolver implemen
     public String getId() {
         return id;
     }
+    
+    public Element getElement() {
+        return element;
+    }
 
     private void setName(String uri) {
-        this.name = uri.substring(uri.lastIndexOf('/') + 1);
+        this.name =  uri;
+        //this.name = uri.substring(uri.lastIndexOf('/') + 1);
     }
     
     public String getName() {
-        return name; // Fot the time being
+        return name;
     }
 
     public ISchemaResolver resolve(String loc, String tns) throws IOException {
@@ -81,6 +90,6 @@ public class JibxSchemaResolver implemen
         } catch (Exception e) {
             // do nothing
         }
-        return new JibxSchemaResolver(uri, read, schemaCol);
+        return new JibxSchemaResolver(uri, read, schemaCol, null);
     }
 }

Modified: cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxToolingDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxToolingDataBinding.java?rev=1185862&r1=1185861&r2=1185862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxToolingDataBinding.java
(original)
+++ cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/tools/JibxToolingDataBinding.java
Tue Oct 18 21:06:23 2011
@@ -52,11 +52,15 @@ import org.apache.cxf.tools.wsdlto.core.
 import org.jibx.binding.Compile;
 import org.jibx.binding.Utility;
 import org.jibx.binding.model.BindingElement;
+import org.jibx.binding.model.BindingHolder;
+import org.jibx.binding.model.BindingOrganizer;
 import org.jibx.binding.model.BindingUtils;
 import org.jibx.binding.model.MappingElement;
+import org.jibx.binding.model.ModelVisitor;
+import org.jibx.binding.model.NamespaceElement;
+import org.jibx.binding.model.TreeContext;
 import org.jibx.binding.model.ValueElement;
 import org.jibx.runtime.JiBXException;
-import org.jibx.schema.ISchemaResolver;
 import org.jibx.schema.codegen.CodeGen;
 import org.jibx.schema.codegen.PackageHolder;
 import org.jibx.schema.codegen.PackageOrganizer;
@@ -64,12 +68,13 @@ import org.jibx.schema.codegen.StringObj
 import org.jibx.schema.codegen.custom.SchemaCustom;
 import org.jibx.schema.codegen.custom.SchemasetCustom;
 import org.jibx.schema.validation.ProblemMultiHandler;
+import org.jibx.util.DummyClassLocator;
 
 public class JibxToolingDataBinding implements DataBindingProfile {
 
     private JibxToolingProblemHandler problemHandler = new JibxToolingProblemHandler();
     private Map<String, Element> schemaMap = new HashMap<String, Element>();
-    private List<ISchemaResolver> resolvers = new ArrayList<ISchemaResolver>();
+    private List<JibxSchemaResolver> resolvers = new ArrayList<JibxSchemaResolver>();
 
     private Map<org.jibx.runtime.QName, MappingElement> types = new HashMap<org.jibx.runtime.QName,
                                                                             MappingElement>();
@@ -161,14 +166,43 @@ public class JibxToolingDataBinding impl
                 codegen.compile();
             }
 
-            BindingElement rootBinding = codegen.getRootBinding();
-            BindingUtils.getDefinitions(rootBinding, types, elements, null);
+            BindingUtils.getDefinitions(codegen.getRootBinding(), types, elements, null);
+            
+            Iterator it = codegen.getBindingOrganizer().iterateBindings();
+            while (it.hasNext()) {
+                BindingHolder o = (BindingHolder)it.next();
+                getDefinitions(o, types, elements);
+            }
 
         } catch (Exception e) {
             problemHandler.handleSevere("", e);
         }
     }
-
+    public static void getDefinitions(final BindingHolder holder, 
+                                      final Map<org.jibx.runtime.QName, MappingElement>
types, 
+                                      final Map<org.jibx.runtime.QName, MappingElement>
elems) {
+        TreeContext ctx = new TreeContext(new DummyClassLocator());
+        ModelVisitor visitor = new ModelVisitor() {
+            public boolean visit(MappingElement mapping) {
+                org.jibx.runtime.QName qname = mapping.getTypeQName();
+                if (qname != null) {
+                    types.put(qname, mapping);
+                }
+                String name = mapping.getName();
+                if (name != null) {
+                    NamespaceElement ns = mapping.getNamespace();
+                    if (ns == null) {
+                        qname = new org.jibx.runtime.QName(holder.getElementDefaultNamespace(),
name);
+                    } else {
+                        qname = new org.jibx.runtime.QName(mapping.getNamespace().getUri(),
name);
+                    }
+                    elems.put(qname, mapping);
+                }
+                return false;
+            }
+        };
+        ctx.tourTree(holder.getBinding(), visitor);
+    }
     public String getType(QName qn, boolean element) {
         MappingElement mappingElement = element ? elements.get(jibxQName(qn)) : types.get(jibxQName(qn));
         return (mappingElement == null) ? null : mappingElement.getClassName();
@@ -197,7 +231,7 @@ public class JibxToolingDataBinding impl
     }
 
     private static void loadWsdl(String wsdlUrl, Map<String, Element> schemaMap,
-                                 List<ISchemaResolver> resolvers) throws WSDLException
{
+                                 List<JibxSchemaResolver> resolvers) throws WSDLException
{
         WSDLFactory factory = WSDLFactory.newInstance();
         WSDLReader reader = factory.newWSDLReader();
         Definition parentDef = reader.readWSDL(wsdlUrl);
@@ -236,13 +270,17 @@ public class JibxToolingDataBinding impl
             SchemaCustom schemaCustom = new SchemaCustom(customRoot);
             schemaCustom.setName(schemaId);
             schemaCustom.setForceTypes(Boolean.TRUE);
+            schemaCustom.setNamespace(smap.get(schemaId).getAttribute("targetNamespace"));
             customRoot.getChildren().add(schemaCustom);
         }
-        for (ISchemaResolver r : resolvers) {
-            SchemaCustom schemaCustom = new SchemaCustom(customRoot);
-            schemaCustom.setName(r.getName());
-            schemaCustom.setForceTypes(Boolean.TRUE);
-            customRoot.getChildren().add(schemaCustom);                    
+        for (JibxSchemaResolver r : resolvers) {
+            if (!schemaIds.contains(r.getId())) {
+                SchemaCustom schemaCustom = new SchemaCustom(customRoot);
+                schemaCustom.setName(r.getName());
+                schemaCustom.setNamespace(r.getElement().getAttribute("targetNamespace"));
+                schemaCustom.setForceTypes(Boolean.TRUE);
+                customRoot.getChildren().add(schemaCustom);
+            }
         }
         return customRoot;
     }
@@ -292,11 +330,16 @@ public class JibxToolingDataBinding impl
         private BindingElement rootBinding;
         private File compilePath;
         private PackageOrganizer packageOrganizer;
+        private BindingOrganizer bindingOrganizer;
 
         public void setProblemHandler(ProblemMultiHandler problemHandler) {
             this.problemHandler = problemHandler;
         }
 
+        public BindingOrganizer getBindingOrganizer() {
+            return bindingOrganizer;
+        }
+
         public void setCustomRoot(SchemasetCustom customRoot) {
             this.customRoot = customRoot;
         }
@@ -394,6 +437,7 @@ public class JibxToolingDataBinding impl
         }
 
         private void setPostGenerateInfo(CodeGen codegen) {
+            this.bindingOrganizer = codegen.getBindingDirectory();
             this.rootBinding = codegen.getRootBinding();
             this.packageOrganizer = codegen.getPackageDirectory();
         }



Mime
View raw message