Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 64829 invoked from network); 29 Sep 2006 05:52:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Sep 2006 05:52:07 -0000 Received: (qmail 33745 invoked by uid 500); 29 Sep 2006 05:52:07 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 33695 invoked by uid 500); 29 Sep 2006 05:52:06 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 33684 invoked by uid 500); 29 Sep 2006 05:52:06 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 33681 invoked by uid 99); 29 Sep 2006 05:52:06 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Sep 2006 22:52:06 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:50503] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id B5/26-08095-684BC154 for ; Thu, 28 Sep 2006 22:52:06 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 06A8D1A9846; Thu, 28 Sep 2006 22:52:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r451136 - /webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Date: Fri, 29 Sep 2006 05:52:03 -0000 To: axis2-cvs@ws.apache.org From: dsosnoski@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060929055204.06A8D1A9846@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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