Hi Glenn,

Thanks for the patches. I think the best place to post patches (in the
future) is bugzilla so that they don't get lost.

I took a quick look, can you explain a couple of things...

1. Why does Group#getSchema always return null?

2. Why do you want to prevent namespaces from being declared?

Thanks,

--Keith

Glenn Nielsen wrote:
> 
> I have attached a patch for two things:
> 
> 1.  It fixes a bug when generating source for a <group> when the group
>     is mapped to a different XML Schema namespace and java package.
>     The source generated would not compile due to the group not being
>     assigned to the correct java package.
> 
> 2.  A set method was added to the Marshaller to disable generation of
>     namespace declarations within an element.
> 
> Regards,
> 
> Glenn
> 
> ----------------------------------------------------------------------
> Glenn Nielsen             [EMAIL PROTECTED] | /* Spelin donut madder    |
> MOREnet System Programming               |  * if iz ina coment.      |
> Missouri Research and Education Network  |  */                       |
> ----------------------------------------------------------------------
> 
>   ------------------------------------------------------------------------
> Index: src/main/org/exolab/castor/builder/MemberFactory.java
> ===================================================================
> RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/MemberFactory.java,v
> retrieving revision 1.67
> diff -u -r1.67 MemberFactory.java
> --- src/main/org/exolab/castor/builder/MemberFactory.java       19 Apr 2002 18:40:36 
>-0000      1.67
> +++ src/main/org/exolab/castor/builder/MemberFactory.java       27 Apr 2002 17:35:00 
>-0000
> @@ -552,13 +552,17 @@
>          if (groupClass == null) {
>              // Java class name is group name or.
>              className = JavaNaming.toJavaClassName(groupName);
> +            if( group.getSchema() != null ) {
> +                className = SourceGenerator.getQualifiedClassName(
> +                    group.getSchema().getTargetNamespace(),className);
> +            }
>              xsType = new XSClass(new JClass(className));
>          }
>          else {
>              className = groupClass.getName();
>          }
> 
> -        String fieldName = JavaNaming.toJavaMemberName(className);
> +        String fieldName = JavaNaming.toJavaMemberName(groupName);
>          if (fieldName.charAt(0) != '_')
>              fieldName = "_"+fieldName;
> 
> Index: src/main/org/exolab/castor/builder/SourceFactory.java
> ===================================================================
> RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/SourceFactory.java,v
> retrieving revision 1.91
> diff -u -r1.91 SourceFactory.java
> --- src/main/org/exolab/castor/builder/SourceFactory.java       8 Apr 2002 22:28:51 
>-0000       1.91
> +++ src/main/org/exolab/castor/builder/SourceFactory.java       27 Apr 2002 17:35:01 
>-0000
> @@ -1586,6 +1586,7 @@
>                      if (tmp.getContentModelGroup() != null) {
>                            if (tmp.getName() != null) {
>                                modelgroup.setName(tmp.getName());
> +                              modelgroup.setSchema(tmp.getSchema());
>                                //create the field info for the element
>                                //that is referring to a model group in order
>                                //not to loose the Particle information
> Index: src/main/org/exolab/castor/xml/Marshaller.java
> ===================================================================
> RCS file: /cvs/castor/castor/src/main/org/exolab/castor/xml/Marshaller.java,v
> retrieving revision 1.105
> diff -u -r1.105 Marshaller.java
> --- src/main/org/exolab/castor/xml/Marshaller.java      23 Apr 2002 20:25:43 -0000   
>   1.105
> +++ src/main/org/exolab/castor/xml/Marshaller.java      27 Apr 2002 17:35:01 -0000
> @@ -81,8 +81,10 @@
>  //import java.io.Serializable;
>  import java.io.Writer;
>  import java.lang.reflect.Array;
>  import java.util.Enumeration;
>  import java.util.Hashtable;
>  import java.util.Vector;
> 
>  /**
> @@ -214,6 +216,11 @@
>      private MarshalListener _marshalListener = null;
> 
>      /**
> +     * Flag whether to marshall namespace declarations.
> +    **/
> +    private boolean _marshalNamespace = true;
> +
> +    /**
>       * The namespace stack
>      **/
>      private Namespaces _namespaces = null;
> @@ -1090,27 +1102,31 @@
>          //------------------/
> 
>          //-- namespace management
> +        String nsPrefix = null;
> +        String nsURI = null;
> 
> -        String nsPrefix = descriptor.getNameSpacePrefix();
> -        if (nsPrefix == null) nsPrefix = classDesc.getNameSpacePrefix();
> -
> -        String nsURI = descriptor.getNameSpaceURI();
> -        if (nsURI == null) nsURI = classDesc.getNameSpaceURI();
> -
> -        if ((nsURI == null) && (nsPrefix != null)) {
> -            nsURI = _namespaces.getNamespaceURI(nsPrefix);
> +        if (_marshalNamespace) {
> +            nsPrefix = descriptor.getNameSpacePrefix();
> +            if (nsPrefix == null) nsPrefix = classDesc.getNameSpacePrefix();
> +
> +            nsURI = descriptor.getNameSpaceURI();
> +            if (nsURI == null) nsURI = classDesc.getNameSpaceURI();
> +
> +            if ((nsURI == null) && (nsPrefix != null)) {
> +                nsURI = _namespaces.getNamespaceURI(nsPrefix);
> +            }
> +            else if ((nsPrefix == null) && (nsURI != null)) {
> +                nsPrefix = (String) _namespaces.getNamespacePrefix(nsURI);
> +            }
> +            //-- declare namespace at this element scope?
> +            if (nsURI != null) {
> +                if ((nsPrefix == null) && (!nsURI.equals(_defaultNamespace)))
> +                {
> +                    nsPrefix = DEFAULT_PREFIX + (++NAMESPACE_COUNTER);
> +                }
> +                declareNamespace(nsPrefix, nsURI);
> +            }
>          }
> -        else if ((nsPrefix == null) && (nsURI != null)) {
> -            nsPrefix = (String) _namespaces.getNamespacePrefix(nsURI);
> -        }
> -        //-- declare namespace at this element scope?
> -        if (nsURI != null) {
> -                   if ((nsPrefix == null) && (!nsURI.equals(_defaultNamespace)))
> -                   {
> -                       nsPrefix = DEFAULT_PREFIX + (++NAMESPACE_COUNTER);
> -                   }
> -                       declareNamespace(nsPrefix, nsURI);
> -               }
> 
>         //check if the value is a QName that needs to
>         //be resolved ({URI}value -> ns:value)
> @@ -1122,7 +1138,7 @@
> 
> 
>          //-- declare all necesssary namespaces
> -               _namespaces.declareAsAttributes(atts, true);
> +       _namespaces.declareAsAttributes(atts, true);
>          String qName = null;
>          if (nsPrefix != null) {
>              int len = nsPrefix.length();
> @@ -1235,6 +1251,15 @@
>                         marshal(item, elemDescriptor, handler);
>                  }
>              }
> 
>              else marshal(obj, elemDescriptor, handler);
>          }
> @@ -1339,6 +1364,16 @@
>      public void setDebug(boolean debug) {
>          this._debug = debug;
>      } //-- setDebug
> +
> +    /**
> +     * Sets the flag to turn on and off marshalling of namespace declarations
> +     * @param declarations the flag indicating whether or not to marshal
> +     * declarations
> +    **/
> +    public void setMarshalNamespace(boolean declarations) {
> +        this._marshalNamespace = declarations;
> +    } //-- setDebug
> +
> 
>      /**
>       * Sets the PrintWriter used for logging
> Index: src/main/org/exolab/castor/xml/schema/Group.java
> ===================================================================
> RCS file: /cvs/castor/castor/src/main/org/exolab/castor/xml/schema/Group.java,v
> retrieving revision 1.18
> diff -u -r1.18 Group.java
> --- src/main/org/exolab/castor/xml/schema/Group.java    3 Apr 2002 07:19:51 -0000    
>   1.18
> +++ src/main/org/exolab/castor/xml/schema/Group.java    27 Apr 2002 17:35:01 -0000
> @@ -474,4 +474,12 @@
>          _parent = parent;
>      } //-- setParent
> 
> -} //-- Group
> \ No newline at end of file
> +    /**
> +     * Returns the schema that contains this modelGroup definition
> +     */
> +    public Schema getSchema() {
> +       return null;
> +    }
> +
> +} //-- Group
> +
> Index: src/main/org/exolab/castor/xml/schema/ModelGroup.java
> ===================================================================
> RCS file: /cvs/castor/castor/src/main/org/exolab/castor/xml/schema/ModelGroup.java,v
> retrieving revision 1.10
> diff -u -r1.10 ModelGroup.java
> --- src/main/org/exolab/castor/xml/schema/ModelGroup.java       17 Oct 2001 19:06:28 
>-0000      1.10
> +++ src/main/org/exolab/castor/xml/schema/ModelGroup.java       27 Apr 2002 17:35:01 
>-0000
> @@ -201,4 +201,12 @@
>         return _schema;
>      }
> 
> -} //-- Group
> \ No newline at end of file
> +    /**
> +     * Sets the schema that contains this modelGroup definition
> +     */
> +    public void setSchema(Schema schema) {
> +       _schema = schema;
> +    }
> +
> +} //-- Group
> +

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to