[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-cvs
Subject:    [Jibx-cvs] core/build/src/org/jibx/ws/wsdl/tools Jibx2Wsdl.java, 1.5,
From:       Dennis Sosnoski <dsosnoski () users ! sourceforge ! net>
Date:       2010-01-20 11:27:21
Message-ID: E1NXYiX-0003US-E4 () sfp-cvsdas-3 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/jibx/core/build/src/org/jibx/ws/wsdl/tools
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv13402/build/src/org/jibx/ws/wsdl/tools


Modified Files:
	Jibx2Wsdl.java 
Log Message:
Add basic support for plain doc/lit (not wrapped) message generation, and support for \
using existing bindings and schemas for parameter and return values.

Index: Jibx2Wsdl.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/ws/wsdl/tools/Jibx2Wsdl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Jibx2Wsdl.java	4 Jan 2010 11:13:28 -0000	1.5
--- Jibx2Wsdl.java	20 Jan 2010 11:27:19 -0000	1.6
***************
*** 1,4 ****
  /*
!  * Copyright (c) 2007-2009, Dennis M. Sosnoski. All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without modification, \
                are permitted provided that the
--- 1,4 ----
  /*
!  * Copyright (c) 2007-2010, Dennis M. Sosnoski. All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without modification, \
                are permitted provided that the
***************
*** 25,30 ****
--- 25,32 ----
  import java.io.FileOutputStream;
  import java.io.IOException;
+ import java.net.URL;
  import java.util.ArrayList;
  import java.util.HashMap;
+ import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
***************
*** 32,39 ****
--- 34,44 ----
  import java.util.Set;
  
+ import org.apache.log4j.Logger;
  import org.jibx.binding.generator.BindGen;
  import org.jibx.binding.generator.BindingMappingDetail;
+ import org.jibx.binding.model.BindingElement;
  import org.jibx.binding.model.BindingHolder;
  import org.jibx.binding.model.CollectionElement;
+ import org.jibx.binding.model.ElementBase;
  import org.jibx.binding.model.MappingElement;
  import org.jibx.binding.model.MappingElementBase;
***************
*** 43,49 ****
  import org.jibx.runtime.JiBXException;
  import org.jibx.runtime.QName;
- import org.jibx.runtime.Utility;
  import org.jibx.schema.IComponent;
  import org.jibx.schema.SchemaHolder;
  import org.jibx.schema.elements.AnnotationElement;
  import org.jibx.schema.elements.ComplexTypeElement;
--- 48,59 ----
  import org.jibx.runtime.JiBXException;
  import org.jibx.runtime.QName;
  import org.jibx.schema.IComponent;
+ import org.jibx.schema.ISchemaResolver;
+ import org.jibx.schema.SchemaContextTracker;
  import org.jibx.schema.SchemaHolder;
+ import org.jibx.schema.SchemaVisitor;
+ import org.jibx.schema.TreeWalker;
+ import org.jibx.schema.UrlResolver;
+ import org.jibx.schema.elements.AnnotatedBase;
  import org.jibx.schema.elements.AnnotationElement;
  import org.jibx.schema.elements.ComplexTypeElement;
***************
*** 55,61 ****
--- 65,76 ----
  import org.jibx.schema.generator.SchemaGen;
  import org.jibx.schema.types.Count;
+ import org.jibx.schema.validation.ValidationContext;
+ import org.jibx.schema.validation.ValidationProblem;
+ import org.jibx.schema.validation.ValidationUtils;
+ import org.jibx.util.DummyClassLocator;
  import org.jibx.util.IClass;
  import org.jibx.util.IClassLocator;
  import org.jibx.util.InsertionOrderedSet;
+ import org.jibx.util.ResourceMatcher;
  import org.jibx.util.Types;
  import org.jibx.ws.wsdl.model.Definitions;
***************
*** 82,85 ****
--- 97,103 ----
  public class Jibx2Wsdl
  {
+     /** Logger for class. */
+     private static final Logger s_logger = \
Logger.getLogger(Jibx2Wsdl.class.getName()); +     
      /** Parameter information for generation. */
      private final WsdlGeneratorCommandLine m_generationParameters;
***************
*** 94,103 ****
      private final Map m_uriSchemaMap;
      
-     /** Map from fully qualified class name to schema type name. */
-     private Map m_classTypeMap;
-     
-     /** Map from class name to instance. This is used to keep track of JavaDoc \
                formatter instances. */
-     private final Map m_classInstances;
-     
      /**
       * Constructor.
--- 112,115 ----
***************
*** 111,115 ****
          m_schemaGenerator = new SchemaGen(parms.getLocator(), global, \
parms.getUriNames());  m_uriSchemaMap = new HashMap();
-         m_classInstances = new HashMap();
      }
      
--- 123,126 ----
***************
*** 133,144 ****
      
      /**
       * Build an element representing a parameter or return value.
       * 
       * @param parm
!      * @param typemap map from parameterized type to abstract mapping name
       * @param hold containing schema holder
       * @return constructed element
       */
!     private ElementElement buildValueElement(ValueCustom parm, Map typemap, \
SchemaHolder hold) {  
          // create the basic element definition
--- 144,174 ----
      
      /**
+      * Add reference to another schema. The reference may either be to a definition \
in a supplied schema (in which case +      * it'll be in the map) or in a generated \
schema (in which case the namespace is used to lookup the schema). +      * 
+      * @param qname referenced definition name
+      * @param namemap map from qualified name to holder for defining schema (only \
for predefined schemas) +      * @param holder schema making the reference
+      */
+     private void addSchemaReference(QName qname, Map namemap, SchemaHolder holder) \
{ +         if (qname != null && !IComponent.SCHEMA_NAMESPACE.equals(qname.getUri())) \
{ +             SchemaHolder target = (SchemaHolder)namemap.get(qname);
+             if (target == null) {
+                 target = (SchemaHolder)m_uriSchemaMap.get(qname.getUri());
+             }
+             holder.addReference(target);
+         }
+     }
+ 
+     /**
       * Build an element representing a parameter or return value.
       * 
       * @param parm
!      * @param typemap map from parameterized type to abstract mapping qualified \
                name
!      * @param namemap map from qualified name to holder for defining schema (only \
                for predefined schemas)
       * @param hold containing schema holder
       * @return constructed element
       */
!     private ElementElement buildValueElement(ValueCustom parm, Map typemap, Map \
namemap, SchemaHolder hold) {  
          // create the basic element definition
***************
*** 182,186 ****
              }
          }
!         if (!isref) {
              
              // set element type and name
--- 212,218 ----
              }
          }
!         if (isref) {
!             addSchemaReference(elem.getRef(), namemap, hold);
!         } else {
              
              // set element type and name
***************
*** 191,194 ****
--- 223,227 ----
              }
              elem.setName(ename);
+             addSchemaReference(tname, namemap, hold);
          }
          
***************
*** 214,251 ****
      
      /**
-      * Add reference defined by element to schema. This finds the namespace of the \
                type or element reference used by the
-      * provided element, and adds that namespace to the schema references.
-      * 
-      * @param elem
-      * @param holder
-      */
-     private void addSchemaReference(ElementElement elem, SchemaHolder holder) {
-         QName qname = elem.getType();
-         if (qname == null) {
-             qname = elem.getRef();
-         }
-         if (qname != null) {
-             String rns = qname.getUri();
-             if (!Utility.safeEquals(holder.getNamespace(), rns) && \
                !IComponent.SCHEMA_NAMESPACE.equals(rns)) {
-                 holder.addReference((SchemaHolder)m_uriSchemaMap.get(rns));
-             }
-         }
-     }
-     
-     /**
       * Build WSDL for service.
       * 
       * @param service
!      * @param typemap map from parameterized type to abstract mapping name
       * @return constructed WSDL definitions
       */
!     private Definitions buildWSDL(ServiceCustom service, Map typemap) {
          
          // initialize root object of definition
          String wns = service.getWsdlNamespace();
-         String sns = service.getNamespace();
-         String spfx = wns.equals(sns) ? "tns" : "sns";
          Definitions def = new Definitions(service.getPortTypeName(), \
                service.getBindingName(), service.getServiceName(),
!             service.getPortName(), "tns", wns, spfx, sns);
          def.setServiceLocation(service.getServiceAddress());
          
--- 247,267 ----
      
      /**
       * Build WSDL for service.
       * 
       * @param service
!      * @param ptypemap map from parameterized type to abstract mapping name
!      * @param classelems fully-qualified class name to element qualified name map
!      * @param elemschemas element qualified name to schema holder map
!      * @param classtypes fully-qualified class name to type qualified name map
!      * @param typeschemas type qualified name to schema holder map
       * @return constructed WSDL definitions
       */
!     private Definitions buildWSDL(ServiceCustom service, Map ptypemap, Map \
                classelems, Map elemschemas, Map classtypes,
!         Map typeschemas) {
          
          // initialize root object of definition
          String wns = service.getWsdlNamespace();
          Definitions def = new Definitions(service.getPortTypeName(), \
                service.getBindingName(), service.getServiceName(),
!             service.getPortName(), "tns", wns);
          def.setServiceLocation(service.getServiceAddress());
          
***************
*** 259,272 ****
          
          // find or create the schema element and namespace
!         SchemaHolder holder = (SchemaHolder)m_uriSchemaMap.get(sns);
!         if (holder == null) {
!             holder = new SchemaHolder(sns);
!         }
          SchemaElement schema = holder.getSchema();
-         def.getSchemas().add(schema);
          
          // process messages and operations used by service
          ArrayList ops = service.getOperations();
          Map fltmap = new HashMap();
          for (int i = 0; i < ops.size(); i++) {
              
--- 275,287 ----
          
          // find or create the schema element and namespace
!         String sns = service.getNamespace();
!         SchemaHolder holder = new SchemaHolder(sns);
          SchemaElement schema = holder.getSchema();
          
          // process messages and operations used by service
          ArrayList ops = service.getOperations();
          Map fltmap = new HashMap();
+         Set imports = new InsertionOrderedSet();
+         Map typemap = new HashMap(ptypemap);
          for (int i = 0; i < ops.size(); i++) {
              
***************
*** 279,325 ****
              
              // generate input message information
!             QName qname = new QName(sns, odef.getRequestWrapperName());
!             MessagePart part = new MessagePart("part", qname);
!             Message msg = new Message(odef.getRequestMessageName(), wns, part);
!             op.addInputMessage(msg);
!             def.addMessage(msg);
              
!             // add corresponding schema definition to schema
!             SequenceElement seq = new SequenceElement();
!             ArrayList parms = odef.getParameters();
!             for (int j = 0; j < parms.size(); j++) {
!                 ValueCustom parm = (ValueCustom)parms.get(j);
!                 ElementElement pelem = buildValueElement(parm, typemap, holder);
!                 seq.getParticleList().add(pelem);
!                 addSchemaReference(pelem, holder);
              }
-             ComplexTypeElement tdef = new ComplexTypeElement();
-             tdef.setContentDefinition(seq);
-             ElementElement elem = new ElementElement();
-             elem.setName(odef.getRequestWrapperName());
-             elem.setTypeDefinition(tdef);
-             schema.getTopLevelChildren().add(elem);
              
              // generate output message information
!             qname = new QName(sns, odef.getResponseWrapperName());
!             part = new MessagePart("part", qname);
!             msg = new Message(odef.getResponseMessageName(), wns, part);
!             op.addOutputMessage(msg);
!             def.addMessage(msg);
              
!             // add corresponding schema definition to schema
!             seq = new SequenceElement();
!             ValueCustom ret = odef.getReturn();
!             if (!"void".equals(ret.getWorkingType())) {
!                 ElementElement relem = buildValueElement(ret, typemap, holder);
!                 seq.getParticleList().add(relem);
!                 addSchemaReference(relem, holder);
              }
-             tdef = new ComplexTypeElement();
-             tdef.setContentDefinition(seq);
-             elem = new ElementElement();
-             elem.setName(odef.getResponseWrapperName());
-             elem.setTypeDefinition(tdef);
-             schema.getTopLevelChildren().add(elem);
              
              // process fault message(s) for operation
--- 294,422 ----
              
              // generate input message information
!             Message rqmsg = new Message(odef.getRequestMessageName(), wns);
!             op.addInputMessage(rqmsg);
!             def.addMessage(rqmsg);
!             QName rqelem = null;
!             if (m_generationParameters.isDocLit()) {
!                 
!                 // check if input parameter defined for method
!                 ArrayList parms = odef.getParameters();
!                 if (parms.size() > 0) {
!                     
!                     // check for existing element definition matching the parameter \
                type
!                     ValueCustom parm = (ValueCustom)parms.get(0);
!                     rqelem = (QName)classelems.get(parm.getWorkingType());
!                     if (rqelem == null) {
!                         
!                         // create new element for parameter
!                         ElementElement pelem = buildValueElement(parm, ptypemap, \
                typeschemas, holder);
!                         schema.getTopLevelChildren().add(pelem);
!                         rqelem = pelem.getQName();
!                         
!                     } else {
!                         
!                         // import and use existing element definition
!                         imports.add(elemschemas.get(rqelem));
!                         addSchemaReference(rqelem, elemschemas, holder);
!                         
!                     }
!                 }
!                 
!             } else {
!                 
!                 // construct a sequence for wrapped method parameters
!                 SequenceElement seq = new SequenceElement();
!                 ArrayList parms = odef.getParameters();
!                 for (int j = 0; j < parms.size(); j++) {
!                     ValueCustom parm = (ValueCustom)parms.get(j);
!                     String type = parm.getWorkingType();
!                     ElementElement pelem;
!                     if (!typemap.containsKey(type)) {
!                         
!                         // add predefined mapping type to known types and require \
                schema import
!                         QName tname = (QName)classtypes.get(type);
!                         if (tname != null) {
!                             typemap.put(type, tname);
!                             imports.add(typeschemas.get(tname));
!                         }
!                         
!                     }
!                     pelem = buildValueElement(parm, ptypemap, typeschemas, holder);
!                     seq.getParticleList().add(pelem);
!                 }
!                 
!                 // add corresponding schema definition to schema
!                 ComplexTypeElement tdef = new ComplexTypeElement();
!                 tdef.setContentDefinition(seq);
!                 ElementElement elem = new ElementElement();
!                 String wname = odef.getRequestWrapperName();
!                 elem.setName(wname);
!                 elem.setTypeDefinition(tdef);
!                 schema.getTopLevelChildren().add(elem);
!                 rqelem = new QName(sns, wname);
!                 
!             }
              
!             // add part definition to message (if present)
!             if (rqelem != null) {
!                 MessagePart part = new MessagePart("part", rqelem);
!                 rqmsg.getParts().add(part);
!                 def.addNamespace(rqelem.getUri());
              }
              
              // generate output message information
!             Message rsmsg = new Message(odef.getResponseMessageName(), wns);
!             op.addOutputMessage(rsmsg);
!             def.addMessage(rsmsg);
!             ValueCustom rtrn = odef.getReturn();
!             QName rselem = null;
!             if (m_generationParameters.isDocLit()) {
!                 
!                 // check if return value defined for method
!                 if (!"void".equals(rtrn.getWorkingType())) {
!                     
!                     // check for existing element definition matching the return \
                type
!                     rselem = (QName)classelems.get(rtrn.getWorkingType());
!                     if (rselem == null) {
!                         
!                         // create new element for return
!                         ElementElement relem = buildValueElement(rtrn, ptypemap, \
                typeschemas, holder);
!                         schema.getTopLevelChildren().add(relem);
!                         rselem = relem.getQName();
!                         
!                     } else {
!                         
!                         // import and use existing element definition
!                         imports.add(elemschemas.get(rselem));
!                         addSchemaReference(rqelem, elemschemas, holder);
!                         
!                     }
!                 }
!                 
!             } else {
!                 
!                 // add corresponding schema definition to schema
!                 SequenceElement seq = new SequenceElement();
!                 if (!"void".equals(rtrn.getWorkingType())) {
!                     ElementElement relem = buildValueElement(rtrn, ptypemap, \
                typeschemas, holder);
!                     seq.getParticleList().add(relem);
!                 }
!                 ComplexTypeElement tdef = new ComplexTypeElement();
!                 tdef.setContentDefinition(seq);
!                 ElementElement elem = new ElementElement();
!                 String wname = odef.getResponseWrapperName();
!                 elem.setName(wname);
!                 elem.setTypeDefinition(tdef);
!                 schema.getTopLevelChildren().add(elem);
!                 rqelem = new QName(sns, wname);
!                 
!             }
              
!             // add part definition to message (if present)
!             if (rselem != null) {
!                 MessagePart part = new MessagePart("part", rselem);
!                 rsmsg.getParts().add(part);
!                 def.addNamespace(rqelem.getUri());
              }
              
              // process fault message(s) for operation
***************
*** 329,341 ****
                  ThrowsCustom thrw = (ThrowsCustom)thrws.get(j);
                  String type = thrw.getType();
!                 msg = (Message)fltmap.get(type);
!                 if (msg == null) {
                      
                      // first time for this throwable, create the message
                      FaultCustom fault = wsdlcustom.forceFaultCustomization(type);
!                     qname = new QName(sns, fault.getElementName());
!                     part = new MessagePart("fault", qname);
!                     msg = new Message(fault.getFaultName(), wns, part);
!                     def.addMessage(msg);
                      
                      // make sure the corresponding mapping exists
--- 426,440 ----
                  ThrowsCustom thrw = (ThrowsCustom)thrws.get(j);
                  String type = thrw.getType();
!                 Message fmsg = (Message)fltmap.get(type);
!                 if (fmsg == null) {
                      
                      // first time for this throwable, create the message
                      FaultCustom fault = wsdlcustom.forceFaultCustomization(type);
!                     QName fqname = new QName(sns, fault.getElementName());
!                     MessagePart part = new MessagePart("fault", fqname);
!                     fmsg = new Message(fault.getFaultName(), wns);
!                     fmsg.getParts().add(part);
!                     def.addMessage(fmsg);
!                     def.addNamespace(sns);
                      
                      // make sure the corresponding mapping exists
***************
*** 346,354 ****
                      
                      // record that the fault has been defined
!                     fltmap.put(type, msg);
                  }
                  
                  // add fault to operation definition
!                 op.addFaultMessage(msg);
              }
              
--- 445,453 ----
                      
                      // record that the fault has been defined
!                     fltmap.put(type, rqmsg);
                  }
                  
                  // add fault to operation definition
!                 op.addFaultMessage(rqmsg);
              }
              
***************
*** 357,361 ****
              
          }
!         holder.finish();
          return def;
      }
--- 456,465 ----
              
          }
!         
!         // include embedded schema for message definitions only if needed
!         if (holder.getReferences().size() > 0 || schema.getSchemaChildren().size() \
>                 0) {
!             holder.finish();
!             def.getSchemas().add(schema);
!         }
          return def;
      }
***************
*** 365,373 ****
       * 
       * @param value
       * @param dataset set of types for binding
       */
!     private void accumulateData(ValueCustom value, Set dataset) {
          String type = value.getBoundType();
!         if (!dataset.contains(type) && !Types.isSimpleValue(type)) {
              String itype = value.getItemType();
              if (itype == null) {
--- 469,478 ----
       * 
       * @param value
+      * @param clasmap map with classes to be excluded as keys
       * @param dataset set of types for binding
       */
!     private void accumulateData(ValueCustom value, Map clasmap, Set dataset) {
          String type = value.getBoundType();
!         if (!dataset.contains(type) && !clasmap.containsKey(type) && \
!Types.isSimpleValue(type)) {  String itype = value.getItemType();
              if (itype == null) {
***************
*** 441,449 ****
       * @param classes service class list
       * @param extras list of extra classes for binding
       * @return list of WSDLs
       * @throws JiBXException
       * @throws IOException
       */
!     private List generate(List classes, List extras) throws JiBXException, \
IOException {  
          // add any service classes not already present in customizations
--- 546,559 ----
       * @param classes service class list
       * @param extras list of extra classes for binding
+      * @param classelems fully-qualified class name to element qualified name map
+      * @param elemschemas element qualified name to schema element map
+      * @param classtypes fully-qualified class name to type qualified name map
+      * @param typeschemas type qualified name to schema element map
       * @return list of WSDLs
       * @throws JiBXException
       * @throws IOException
       */
!     private List generate(List classes, List extras, Map classelems, Map \
                elemschemas, Map classtypes, Map typeschemas)
!     throws JiBXException, IOException {
          
          // add any service classes not already present in customizations
***************
*** 456,460 ****
          }
          
!         // accumulate the data classes used by all service operations
          // TODO: throws class handling, with multiple services per WSDL
          InsertionOrderedSet abstrs = new InsertionOrderedSet();
--- 566,570 ----
          }
          
!         // accumulate unmapped data classes used by all service operations
          // TODO: throws class handling, with multiple services per WSDL
          InsertionOrderedSet abstrs = new InsertionOrderedSet();
***************
*** 462,465 ****
--- 572,576 ----
          ArrayList qnames = new ArrayList();
          List services = wsdlcustom.getServices();
+         boolean doclit = m_generationParameters.isDocLit();
          for (Iterator iter = services.iterator(); iter.hasNext();) {
              ServiceCustom service = (ServiceCustom)iter.next();
***************
*** 468,475 ****
                  OperationCustom op = (OperationCustom)iter1.next();
                  List parms = op.getParameters();
                  for (Iterator iter2 = parms.iterator(); iter2.hasNext();) {
!                     accumulateData((ValueCustom)iter2.next(), abstrs);
                  }
-                 accumulateData(op.getReturn(), abstrs);
                  ArrayList thrws = op.getThrows();
                  for (int i = 0; i < thrws.size(); i++) {
--- 579,598 ----
                  OperationCustom op = (OperationCustom)iter1.next();
                  List parms = op.getParameters();
+                 if (doclit && parms.size() > 1) {
+                     System.err.println("Multiple parmameters not allowed for \
doc/lit: method " + op.getMethodName()); +                 }
                  for (Iterator iter2 = parms.iterator(); iter2.hasNext();) {
!                     ValueCustom parm = (ValueCustom)iter2.next();
!                     if (doclit) {
!                         accumulateData(parm, classelems, concrs);
!                     } else {
!                         accumulateData(parm, classtypes, abstrs);
!                     }
!                 }
!                 if (doclit) {
!                     accumulateData(op.getReturn(), classelems, concrs);
!                 } else {
!                     accumulateData(op.getReturn(), classtypes, abstrs);
                  }
                  ArrayList thrws = op.getThrows();
                  for (int i = 0; i < thrws.size(); i++) {
***************
*** 552,561 ****
          ArrayList wsdls = new ArrayList();
          for (Iterator iter = services.iterator(); iter.hasNext();) {
!             wsdls.add(buildWSDL((ServiceCustom)iter.next(), typemap));
          }
          return wsdls;
-         
      }
!     
      /**
       * Run the WSDL generation using command line parameters.
--- 675,784 ----
          ArrayList wsdls = new ArrayList();
          for (Iterator iter = services.iterator(); iter.hasNext();) {
!             wsdls.add(buildWSDL((ServiceCustom)iter.next(), typemap, classelems, \
elemschemas, classtypes, typeschemas));  }
          return wsdls;
      }
! 
!     /**
!      * Accumulate all mapping definitions, including those found in included \
                bindings. For each named abstract mapping
!      * found, the class name is associated with the type name in the type map; for \
                each concrete mapping found, the
!      * class name is associated with the element name in the element map. Included \
                bindings are handled with recursive
!      * calls.
!      *
!      * @param binding binding definition root
!      * @param elemmap map from fully-qualified class name to element qualified name
!      * @param typemap map from fully-qualified class name to type qualified name
!      */
!     private static void accumulateBindingDefinitions(BindingElement binding, Map \
                elemmap, Map typemap) {
!         ArrayList childs = binding.topChildren();
!         for (int i = 0; i < childs.size(); i++) {
!             ElementBase element = (ElementBase)childs.get(i);
!             if (element.type() == ElementBase.INCLUDE_ELEMENT) {
!                 
!                 // use recursive call to add nested definitions in included binding
!                 accumulateBindingDefinitions(((org.jibx.binding.model.IncludeElement)element).getBinding(), \
                elemmap,
!                     typemap);
!                 
!             } else if (element.type() == ElementBase.MAPPING_ELEMENT) {
!                 
!                 // handle mapping as type if abstract with type name, or as element \
                if concrete
!                 MappingElementBase mapping = (MappingElementBase)element;
!                 String cname = mapping.getClassName();
!                 if (mapping.isAbstract()) {
!                     QName qname = mapping.getTypeQName();
!                     if (qname != null) {
!                         typemap.put(cname, qname);
!                         if (s_logger.isDebugEnabled()) {
!                             s_logger.debug("Added class " + cname + " with type " + \
                qname);
!                         }
!                     }
!                 } else {
!                     QName qname = new QName(mapping.getNamespace().getUri(), \
                mapping.getName());
!                     elemmap.put(cname, qname);
!                     if (s_logger.isDebugEnabled()) {
!                         s_logger.debug("Added class " + cname + " with element " + \
                qname);
!                     }
!                 }
!                 
!             }
!         }
!     }
! 
!     /**
!      * Load and validate binding and process all mapping definitions, including \
                those in included bindings.
!      *
!      * @param url binding definition path
!      * @param elemmap map from element qualified name to class data
!      * @param typemap map from type qualified name to class data
!      * @return binding
!      * @throws JiBXException
!      * @throws IOException
!      */
!     public static BindingElement processPregeneratedBinding(URL url, Map elemmap, \
                Map typemap)
!         throws JiBXException, IOException {
!         
!         // get binding definition file name from path
!         String name = "";
!         String path = url.getPath();
!         if (path != null) {
!             name = path;
!             int split = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\'));
!             if (split > 0) {
!                 name = name.substring(split+1);
!             }
!             split = name.lastIndexOf('.');
!             name = name.substring(0, split);
!         }
!         
!         // construct object model for binding
!         org.jibx.binding.model.ValidationContext vctx =
!             new org.jibx.binding.model.ValidationContext(new DummyClassLocator());
!         BindingElement binding = BindingElement.readBinding(url.openStream(), name, \
                null, true,
!             vctx);
!         binding.setBaseUrl(url);
!         vctx.setBindingRoot(binding);
!         
!         // validate the binding definition
!         binding.runValidation(vctx);
!         
!         // list validation errors
!         ArrayList probs = vctx.getProblems();
!         if (probs.size() > 0) {
!             for (int i = 0; i < probs.size(); i++) {
!                 org.jibx.binding.model.ValidationProblem prob =
!                     (org.jibx.binding.model.ValidationProblem)probs.get(i);
!                 System.out.print(prob.getSeverity() >=
!                     ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: ");
!                 System.out.println(prob.getDescription());
!             }
!             if (vctx.getErrorCount() > 0 || vctx.getFatalCount() > 0) {
!                 throw new JiBXException("Errors in binding");
!             }
!         }
!         
!         // add all the mapping and format definitions in binding to qualified name \
                maps
!         accumulateBindingDefinitions(binding, elemmap, typemap);
!         return binding;
!     }    
      /**
       * Run the WSDL generation using command line parameters.
***************
*** 569,572 ****
--- 792,867 ----
          if (args.length > 0 && parms.processArgs(args)) {
              
+             // build set of schemas provided on command line
+             final Set resolves = new HashSet();
+             List errors = ResourceMatcher.matchPaths(new File("."), null, \
parms.getUseSchemas(), +                 new ResourceMatcher.ReportMatch() {
+                     public void foundMatch(String path, URL url) {
+                         resolves.add(new UrlResolver(path, url));
+                     }
+                 });
+             if (errors.size() > 0) {
+                 for (Iterator iter = errors.iterator(); iter.hasNext();) {
+                     System.err.println(iter.next());
+                 }
+                 System.exit(1);
+             }
+             
+             // load and validate schemas
+             ValidationContext vctx = new ValidationContext();
+             ValidationUtils.load(resolves, null, vctx);
+             if (vctx.reportProblems()) {
+                 System.exit(2);
+             }
+             
+             // build maps from qualified names to schema holders
+             final Map elemschemas = new HashMap();
+             final Map typeschemas = new HashMap();
+             TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
+             for (Iterator iter = resolves.iterator(); iter.hasNext();) {
+                 SchemaElement schema = \
vctx.getSchemaById(((ISchemaResolver)iter.next()).getId()); +                 final \
SchemaHolder holder = new SchemaHolder(schema); +                 SchemaVisitor \
visitor = new SchemaVisitor() { +                     
+                     public boolean visit(AnnotatedBase node) {
+                         return false;
+                     }
+                     
+                     public boolean visit(ComplexTypeElement node) {
+                         typeschemas.put(node.getQName(), holder);
+                         return false;
+                     }
+                     
+                     public boolean visit(ElementElement node) {
+                         elemschemas.put(node.getQName(), holder);
+                         return false;
+                     }
+                     
+                 };
+                 wlkr.walkElement(schema, visitor);
+             }
+             
+             // build set of binding definitions provided on command line
+             final Set bindings = new HashSet();
+             errors = ResourceMatcher.matchPaths(new File("."), null, \
parms.getUseBindings(), +                 new ResourceMatcher.ReportMatch() {
+                     public void foundMatch(String path, URL url) {
+                         bindings.add(url);
+                     }
+                 });
+             if (errors.size() > 0) {
+                 for (Iterator iter = errors.iterator(); iter.hasNext();) {
+                     System.err.println(iter.next());
+                 }
+                 System.exit(3);
+             }
+             
+             // build maps of type and element mappings from bindings
+             Map classelems = new HashMap();
+             Map classtypes = new HashMap();
+             for (Iterator iter = bindings.iterator(); iter.hasNext();) {
+                 URL url = (URL)iter.next();
+                 processPregeneratedBinding(url, classelems, classtypes);
+             }
+             
              // generate services, bindings, and WSDLs
              Jibx2Wsdl inst = new Jibx2Wsdl(parms);
***************
*** 579,583 ****
                  }
              }
!             List wsdls = inst.generate(parms.getExtraArgs(), extras);
              if (wsdls != null) {
                  
--- 874,878 ----
                  }
              }
!             List wsdls = inst.generate(parms.getExtraArgs(), extras, classelems, \
elemschemas, classtypes, typeschemas);  if (wsdls != null) {
                  


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Jibx-cvs mailing list
Jibx-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic