You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ds...@apache.org on 2006/09/29 07:52:03 UTC

svn commit: r451136 - /webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java

Author: dsosnoski
Date: Thu Sep 28 22:52:03 2006
New Revision: 451136

URL: http://svn.apache.org/viewvc?view=rev&rev=451136
Log:
Remove unused methods, add support for binding includes

Modified:
    webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java

Modified: webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=451136&r1=451135&r2=451136
==============================================================================
--- webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java (original)
+++ webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Thu Sep 28 22:52:03 2006
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -51,6 +52,7 @@
 import org.jibx.binding.model.FormatElement;
 import org.jibx.binding.model.IncludeElement;
 import org.jibx.binding.model.MappingElement;
+import org.jibx.binding.model.ModelVisitor;
 import org.jibx.binding.model.NamespaceElement;
 import org.jibx.binding.model.ValidationContext;
 import org.jibx.runtime.JiBXException;
@@ -109,13 +111,17 @@
         }
         
         // Read the JiBX binding definition into memory. The binding definition
-        // is not currently validated so as not to require the user to have all
+        // is only prevalidated so as not to require the user to have all
         // the referenced classes in the classpath, though this does make for
         // added work in finding the namespaces.
         try {
             ValidationContext vctx = BindingElement.newValidationContext();
             BindingElement binding =
                 BindingElement.readBinding(new FileInputStream(file), path, vctx);
+            binding.setBaseUrl(file.toURL());
+            vctx.setBindingRoot(binding);
+            IncludePrevalidationVisitor ipv = new IncludePrevalidationVisitor(vctx);
+            vctx.tourTree(binding, ipv);
             if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
                 throw new RuntimeException("invalid jibx binding definition file " + path);
             }
@@ -239,6 +245,8 @@
             throw new RuntimeException(e);
         } catch (AxisFault e) {
             throw new RuntimeException(e);
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);
         }
     }
     
@@ -539,102 +547,34 @@
         }
         return dns;
     }
-
-    /**
-     * Get map from qname to corresponding class name from binding definition.
-     * Only the global <mapping> elements in the binding definition are
-     * included, since these are the only ones accessible from the Axis2
-     * interface.
-     * 
-     * @param path binding definition file path
-     * @return map from qname to class name
-     */
-    public static Map getBindingMap(String path) {
-        
-        // make sure the binding definition file is present
-        File file = new File(path);
-        if (!file.exists()) {
-            throw new RuntimeException("jibx binding definition file " + path + " not found");
-        }
-        
-        // Read the JiBX binding definition into memory. The binding definition
-        // is not currently validated so as not to require the user to have all
-        // the referenced classes in the classpath, though this does make for
-        // added work in finding the namespaces.
-        try {
-            ValidationContext vctx = BindingElement.newValidationContext();
-            BindingElement binding =
-                BindingElement.readBinding(new FileInputStream(file), path, vctx);
-            if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
-                throw new RuntimeException("invalid jibx binding definition file " + path);
-            }
-            
-            // create map from qname to class for all top-level mappings
-            return defineBoundClasses(binding);
-            
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException(e);
-        } catch (JiBXException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Create mapping from qnames to classes for top level mappings in JiBX binding.
-     * 
-     * @param binding
-     * @return map from qname to class
-     */
-    private static Map defineBoundClasses(BindingElement binding) {
-        
-        // check default namespace set at top level of binding
-        String defaultns = findDefaultNS(binding.topChildIterator());
-        
-        // add all top level mapping definitions to map from qname to class
-        Map mappings = new HashMap();
-        for (Iterator iter = binding.topChildIterator(); iter.hasNext();) {
-            ElementBase child = (ElementBase)iter.next();
-            if (child.type() == ElementBase.MAPPING_ELEMENT) {
-                MappingElement mapping = (MappingElement)child;
-                String name = mapping.getName();
-                if (name != null) {
-                    String uri = mapping.getUri();
-                    if (uri == null) {
-                        uri = findDefaultNS(mapping.topChildIterator());
-                        if (uri == null) {
-                            uri = defaultns;
-                        }
-                    }
-                    mappings.put(new QName(uri, name), mapping.getClassName());
-                }
-            }
-        }
-        return mappings;
-    }
-
+    
     /**
-     * Find the default namespace within a list of JiBX binding model elements
-     * possibly including namespace definitions. Once a non-namespace definition
-     * element is seen in the list, this just returns (since the namespace
-     * definitions always come first in JiBX's binding format).
-     * 
-     * @param iter iterator for elements in list
-     * @return default namespace
+     * Inner class for handling prevalidation of include elements only. Unlike
+     * the normal JiBX binding definition prevalidation step, this visitor
+     * ignores everything except include elements.
      */
-    private static String findDefaultNS(Iterator iter) {
-        while (iter.hasNext()) {
-            ElementBase child = (ElementBase)iter.next();
-            if (child.type() == ElementBase.NAMESPACE_ELEMENT) {
-                NamespaceElement namespace = (NamespaceElement)child;
-                String defaultName = namespace.getDefaultName();
-                if ("elements".equals(defaultName) || "all".equals(defaultName)) {
-                    return namespace.getUri();
-                }
-            } else {
-               break;
+    private class IncludePrevalidationVisitor extends ModelVisitor
+    {
+        private final ValidationContext m_context;
+        
+        private IncludePrevalidationVisitor(ValidationContext vctx) {
+            m_context = vctx;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.jibx.binding.model.ModelVisitor#visit(org.jibx.binding.model.ElementBase)
+         */
+        public boolean visit(IncludeElement node) {
+            try {
+                node.prevalidate(m_context);
+            } catch (Throwable t) {
+                m_context.addFatal("Error during validation: " +
+                    t.getMessage());
+                t.printStackTrace();
+                return false;
             }
+            return true;
         }
-        return null;
     }
     
     private static class NamedParameterTypeMapper extends JavaTypeMapper



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org