Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/DescriptorSourceFactory.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/DescriptorSourceFactory.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/DescriptorSourceFactory.java	(working copy)
@@ -1,582 +0,0 @@
-/**
- * Redistribution and use of this software and associated documentation
- * ("Software"), with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * 1. Redistributions of source code must retain copyright
- *    statements and notices.  Redistributions must also contain a
- *    copy of this document.
- *
- * 2. Redistributions in binary form must reproduce the
- *    above copyright notice, this list of conditions and the
- *    following disclaimer in the documentation and/or other
- *    materials provided with the distribution.
- *
- * 3. The name "Exolab" must not be used to endorse or promote
- *    products derived from this Software without prior written
- *    permission of Intalio, Inc.  For written permission,
- *    please contact info@exolab.org.
- *
- * 4. Products derived from this Software may not be called "Exolab"
- *    nor may "Exolab" appear in their names without prior written
- *    permission of Intalio, Inc. Exolab is a registered
- *    trademark of Intalio, Inc.
- *
- * 5. Due credit should be given to the Exolab Project
- *    (http://www.exolab.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Copyright 1999-2004 (C) Intalio, Inc. All Rights Reserved.
- *
- * This file was originally developed by Keith Visco during the
- * course of employment at Intalio Inc.
- * All portions of this file developed by Keith Visco after Jan 19 2005 are
- * Copyright (C) 2005 Keith Visco. All Rights Reserverd.
- *
- * $Id$
- */
-
-package org.exolab.castor.builder;
-
-import org.exolab.castor.builder.info.ClassInfo;
-import org.exolab.castor.builder.info.CollectionInfo;
-import org.exolab.castor.builder.info.FieldInfo;
-import org.exolab.castor.builder.info.XMLInfo;
-import org.exolab.castor.builder.types.XSClass;
-import org.exolab.castor.builder.types.XSList;
-import org.exolab.castor.builder.types.XSType;
-import org.exolab.castor.builder.util.DescriptorJClass;
-import org.exolab.javasource.JClass;
-import org.exolab.javasource.JConstructor;
-import org.exolab.javasource.JField;
-import org.exolab.javasource.JModifiers;
-import org.exolab.javasource.JSourceCode;
-import org.exolab.javasource.JType;
-
-/**
- * A factory for creating the source code of descriptor classes
- *
- * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
- * @version $Revision$ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $
- */
-public class DescriptorSourceFactory {
-
-    /**
-     * GeneralizedFieldHandler
-     */
-    private static final JClass GENERALIZED_FIELD_HANDLER_CLASS =
-        new JClass("org.exolab.castor.mapping.GeneralizedFieldHandler");
-
-    private static final String DESCRIPTOR_NAME      = "Descriptor";
-    private static final String FIELD_VALIDATOR_NAME = "fieldValidator";
-
-    /**
-     * The BuilderConfiguration instance
-     */
-    private BuilderConfiguration _config = null;
-
-    /**
-     * Factory for creating XMLFieldHandler instances embedded in descriptors
-     */
-    private XMLFieldHandlerFactory _xmlFieldHandlerFactory;
-
-    /**
-     * Creates a new DescriptorSourceFactory with the given configuration
-     *
-     * @param config the BuilderConfiguration instance
-     */
-    public DescriptorSourceFactory(final BuilderConfiguration config) {
-        if (config == null) {
-            String err = "The argument 'config' must not be null.";
-            throw new IllegalArgumentException(err);
-        }
-        _config = config;
-        _xmlFieldHandlerFactory = new XMLFieldHandlerFactory(config);
-    } //-- DescriptorSourceFactory
-
-    /**
-     * Creates the Source code of a MarshalInfo for a given XML Schema element
-     * declaration
-     *
-     * @param classInfo
-     *            the XML Schema element declaration
-     * @return the JClass representing the MarshalInfo source code
-     */
-    public JClass createSource(final ClassInfo classInfo) {
-        JSourceCode jsc            = null;
-        JClass jClass              = classInfo.getJClass();
-        String className           = jClass.getName();
-        String localClassName      = jClass.getLocalName();
-        DescriptorJClass classDesc = new DescriptorJClass(_config, className + DESCRIPTOR_NAME, jClass);
-
-        //-- get handle to default constuctor
-        JConstructor cons = classDesc.getConstructor(0);
-        jsc = cons.getSourceCode();
-
-        //-- Set namespace prefix
-        String nsPrefix = classInfo.getNamespacePrefix();
-        if ((nsPrefix != null) && (nsPrefix.length() > 0)) {
-            jsc.add("nsPrefix = \"");
-            jsc.append(nsPrefix);
-            jsc.append("\";");
-        }
-
-        //-- Set namespace URI
-        String nsURI = classInfo.getNamespaceURI();
-        if ((nsURI != null) && (nsURI.length() > 0)) {
-            jsc.add("nsURI = \"");
-            jsc.append(nsURI);
-            jsc.append("\";");
-        }
-
-        //-- set XML Name
-        String xmlName = classInfo.getNodeName();
-        if (xmlName != null) {
-            jsc.add("xmlName = \"");
-            jsc.append(xmlName);
-            jsc.append("\";");
-        }
-
-        //-- set Element Definition flag
-        boolean elementDefinition = classInfo.isElementDefinition();
-        jsc.add("elementDefinition = ");
-        jsc.append(new Boolean(elementDefinition).toString());
-        jsc.append(";");
-
-        //-- set grouping compositor
-        if (classInfo.isChoice()) {
-            jsc.add("");
-            jsc.add("//-- set grouping compositor");
-            jsc.add("setCompositorAsChoice();");
-        } else if (classInfo.isSequence()) {
-            jsc.add("");
-            jsc.add("//-- set grouping compositor");
-            jsc.add("setCompositorAsSequence();");
-        }
-
-        //-- To prevent compiler warnings...make sure
-        //-- we don't declare temp variables if field count is 0;
-        if (classInfo.getFieldCount() == 0) {
-            return classDesc;
-        }
-
-        //-- declare temp variables
-        jsc.add("org.exolab.castor.xml.util.XMLFieldDescriptorImpl  desc           = null;");
-        jsc.add("org.exolab.castor.mapping.FieldHandler             handler        = null;");
-        jsc.add("org.exolab.castor.xml.FieldValidator               fieldValidator = null;");
-
-        //-- handle  content
-        if (classInfo.allowContent()) {
-            createDescriptor(classDesc, classInfo.getTextField(), localClassName, null, jsc);
-        }
-
-        ClassInfo   base = classInfo.getBaseClass();
-        FieldInfo[] atts = classInfo.getAttributeFields();
-
-        //--------------------------------/
-        //- Create attribute descriptors -/
-        //--------------------------------/
-
-        jsc.add("//-- initialize attribute descriptors");
-        jsc.add("");
-
-        for (int i = 0; i < atts.length; i++) {
-            FieldInfo member = atts[i];
-            //-- skip transient members
-            if (member.isTransient()) {
-                continue;
-            }
-
-            if (base != null) {
-                String baseNodeName = member.getNodeName();
-                if (baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION)) {
-                    createDescriptor(classDesc, member, localClassName, nsURI, jsc);
-                } else {
-                    if (base.getAttributeField(baseNodeName) != null) {
-                        createRestrictedDescriptor(member, jsc);
-                    } else {
-                        createDescriptor(classDesc, member, localClassName,
-                                nsURI, jsc);
-                    }
-                }
-            } else {
-                createDescriptor(classDesc, member, localClassName, nsURI, jsc);
-            }
-        }
-
-        //------------------------------/
-        //- Create element descriptors -/
-        //------------------------------/
-        FieldInfo[] elements = classInfo.getElementFields();
-
-        jsc.add("//-- initialize element descriptors");
-        jsc.add("");
-
-        for (int i = 0; i < elements.length; i++) {
-            FieldInfo member = elements[i];
-            //-- skip transient members
-            if (member.isTransient()) {
-                continue;
-            }
-
-            if (base != null) {
-                String baseNodeName = member.getNodeName();
-                if (baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION)) {
-                    createDescriptor(classDesc, member, localClassName, nsURI, jsc);
-                } else {
-                    if (base.getElementField(baseNodeName) != null) {
-                        createRestrictedDescriptor(member, jsc);
-                    } else {
-                        createDescriptor(classDesc, member, localClassName,
-                                nsURI, jsc);
-                    }
-                }
-            } else {
-                createDescriptor(classDesc, member, localClassName, nsURI, jsc);
-            }
-        }
-
-        return classDesc;
-    } //-- createSource
-
-    //-------------------/
-    //- Private Methods -/
-    //-------------------/
-
-    /**
-     * Create special code for handling a member that is a restriction.
-     * This will only change the Validation Code
-     * @param member the restricted member for which we generate the restriction handling.
-     * @param jsc the source code to which we append the validation code.
-     */
-    private static void createRestrictedDescriptor(final FieldInfo member, final JSourceCode jsc) {
-        jsc.add("desc = (org.exolab.castor.xml.util.XMLFieldDescriptorImpl) getFieldDescriptor(\"");
-        jsc.append(member.getNodeName());
-        jsc.append("\"");
-        jsc.append(", nsURI");
-        if (member.getNodeType() == XMLInfo.ELEMENT_TYPE) {
-            jsc.append(", org.exolab.castor.xml.NodeType.Element);");
-        } else if (member.getNodeType() == XMLInfo.ATTRIBUTE_TYPE) {
-            jsc.append(", org.exolab.castor.xml.NodeType.Attribute);");
-        } else {
-            jsc.append("org.exolab.castor.xml.NodeType.Text);");
-        }
-        //--modify the validation code
-        validationCode(member, jsc);
-    }
-
-    /**
-     * Creates a specific descriptor for a given member (whether an attribute or
-     * an element) represented by a given Class name.
-     *
-     * @param classDesc
-     *            JClass-equivalent descriptor for this Descriptor class
-     * @param member
-     *            the member for which to create a descriptor
-     * @param localClassName
-     *            unqualified (no package) name of this class
-     * @param nsURI
-     *            namespace URI
-     * @param jsc
-     *            the source code to which we'll add this descriptor
-     */
-    private void createDescriptor(final DescriptorJClass classDesc, final FieldInfo member,
-                                  final String localClassName, String nsURI,
-                                  final JSourceCode jsc) {
-
-        XSType xsType       = member.getSchemaType();
-        boolean any         = false;
-        boolean isElement   = (member.getNodeType() == XMLInfo.ELEMENT_TYPE);
-        boolean isAttribute = (member.getNodeType() == XMLInfo.ATTRIBUTE_TYPE);
-        boolean isText      = (member.getNodeType() == XMLInfo.TEXT_TYPE);
-
-        jsc.add("//-- ");
-        jsc.append(member.getName());
-
-        //-- a hack, I know, I will change later (kv)
-        if (member.getName().equals("_anyObject")) {
-            any = true;
-        }
-
-        if (xsType.getType() == XSType.COLLECTION) {
-            //Attributes can handle COLLECTION type for NMTOKENS or IDREFS for instance
-            xsType = ((CollectionInfo) member).getContent().getSchemaType();
-        }
-
-        //-- Resolve how the node name parameter to the XMLFieldDescriptorImpl constructor is supplied
-        String nodeName = member.getNodeName();
-        String nodeNameParam = null;
-        if ((nodeName != null) && (!isText)) {
-            //-- By default the node name parameter is a literal string
-            nodeNameParam = "\"" + nodeName + "\"";
-            if (_config.classDescFieldNames()) {
-                //-- The node name parameter is a reference to a public static final
-                nodeNameParam = member.getNodeName().toUpperCase();
-                //-- Expose node name as public static final (reused by XMLFieldDescriptorImpl)
-                JModifiers publicStaticFinal = new JModifiers();
-                publicStaticFinal.makePublic();
-                publicStaticFinal.setStatic(true);
-                publicStaticFinal.setFinal(true);
-                JField jField = new JField(SGTypes.String, nodeNameParam);
-                jField.setModifiers(publicStaticFinal);
-                jField.setInitString("\"" + nodeName + "\"");
-                classDesc.addMember(jField);
-            }
-        }
-
-        //-- Generate code to new XMLFieldDescriptorImpl instance
-        jsc.add("desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(");
-        jsc.append(classType(xsType.getJType()));
-        jsc.append(", \"");
-        jsc.append(member.getName());
-        jsc.append("\", ");
-        if (nodeNameParam != null) {
-            jsc.append(nodeNameParam);
-        } else if (isText) {
-            jsc.append("\"PCDATA\"");
-        } else {
-            jsc.append("(java.lang.String)null");
-        }
-
-        if (isElement) {
-            jsc.append(", org.exolab.castor.xml.NodeType.Element);");
-        } else if (isAttribute) {
-            jsc.append(", org.exolab.castor.xml.NodeType.Attribute);");
-        } else if (isText) {
-            jsc.append(", org.exolab.castor.xml.NodeType.Text);");
-        }
-
-        switch (xsType.getType()) {
-            case XSType.STRING_TYPE :
-                jsc.add("desc.setImmutable(true);");
-                break;
-                //only for attributes
-            case XSType.IDREF_TYPE :
-                jsc.add("desc.setReference(true);");
-                break;
-            case XSType.ID_TYPE :
-                jsc.add("this.identity = desc;");
-                break;
-            case XSType.QNAME_TYPE :
-                jsc.add("desc.setSchemaType(\"QName\");");
-                /***********************/
-            default :
-                break;
-        } //switch
-
-        //-- handler access methods
-        if (member.getXMLFieldHandler() != null) {
-            String handler = member.getXMLFieldHandler();
-            jsc.add("handler = new " + handler + "();");
-            jsc.add("//-- test for generalized field handler");
-            jsc.add("if (handler instanceof ");
-            jsc.append(GENERALIZED_FIELD_HANDLER_CLASS.getName());
-            jsc.append(")");
-            jsc.add("{");
-            jsc.indent();
-            jsc.add("//-- save reference to user-specified handler");
-            jsc.add(GENERALIZED_FIELD_HANDLER_CLASS.getName());
-            jsc.append(" gfh = (");
-            jsc.append(GENERALIZED_FIELD_HANDLER_CLASS.getName());
-            jsc.append(")handler;");
-            _xmlFieldHandlerFactory.createXMLFieldHandler(member, xsType, localClassName, jsc, true);
-            jsc.add("gfh.setFieldHandler(handler);");
-            jsc.add("handler = gfh;");
-            jsc.unindent();
-            jsc.add("}");
-        } else {
-            _xmlFieldHandlerFactory.createXMLFieldHandler(member, xsType, localClassName, jsc, false);
-            addSpecialHandlerLogic(member, xsType, jsc);
-        }
-
-        jsc.add("desc.setHandler(handler);");
-
-        //-- container
-        if (member.isContainer()) {
-            jsc.add("desc.setContainer(true);");
-            String className = xsType.getName(); //set the class descriptor
-            //Try to prevent endless loop. Note: we only compare the localClassName.
-            //If the packages are different an error can happen here
-            if (className.equals(localClassName)) {
-                jsc.add("desc.setClassDescriptor(this);");
-            } else {
-                jsc.add("desc.setClassDescriptor(new " + className + DESCRIPTOR_NAME + "());");
-            }
-        }
-
-        //-- Handle namespaces
-        //-- FieldInfo namespace has higher priority than ClassInfo namespace.
-        nsURI = member.getNamespaceURI();
-        if (nsURI != null) {
-            jsc.add("desc.setNameSpaceURI(\"");
-            jsc.append(nsURI);
-            jsc.append("\");");
-        }
-
-        if (any && member.getNamespaceURI() == null) {
-            nsURI = null;
-        }
-
-        //-- required
-        if (member.isRequired()) {
-            jsc.add("desc.setRequired(true);");
-        }
-
-        //-- nillable
-        if (member.isNillable()) {
-           jsc.add("desc.setNillable(true);");
-        }
-
-        //-- if any it can match all the names
-        if (any) {
-            jsc.add("desc.setMatches(\"*\");");
-        }
-
-        //-- mark as multi or single valued for elements
-        if (isElement || isAttribute) {
-            jsc.add("desc.setMultivalued(" + member.isMultivalued());
-            jsc.append(");");
-        }
-
-        jsc.add("addFieldDescriptor(desc);");
-        jsc.add("");
-
-        //-- Add Validation Code
-        validationCode(member, jsc);
-    } //--CreateDescriptor
-
-    /**
-     * Adds additional logic or wrappers around the core handler for special
-     * types such as dates, enumerated types, collections, etc.
-     *
-     * @param member the member for which extra special handler logic may be created
-     * @param xsType the field type for which extra special handler logic may be created
-     * @param jsc the java source code to which this will be written
-     */
-    private void addSpecialHandlerLogic(final FieldInfo member, final XSType xsType,
-                                        final JSourceCode jsc) {
-        if (xsType.isEnumerated()) {
-            jsc.add("handler = new org.exolab.castor.xml.handlers.EnumFieldHandler(");
-            jsc.append(classType(xsType.getJType()));
-            jsc.append(", handler);");
-            jsc.add("desc.setImmutable(true);");
-        } else if (xsType.getType() == XSType.DATETIME_TYPE) {
-            jsc.add("handler = new org.exolab.castor.xml.handlers.DateFieldHandler(");
-            jsc.append("handler);");
-            jsc.add("desc.setImmutable(true);");
-        } else if (xsType.getType() == XSType.DECIMAL_TYPE) {
-            jsc.add("desc.setImmutable(true);");
-        } else if (member.getSchemaType().getType() == XSType.COLLECTION) {
-            //-- Handle special Collection Types such as NMTOKENS and IDREFS
-            switch (xsType.getType()) {
-                case XSType.NMTOKEN_TYPE:
-                case XSType.NMTOKENS_TYPE:
-                    //-- use CollectionFieldHandler
-                    jsc.add("handler = new org.exolab.castor.xml.handlers.CollectionFieldHandler(");
-                    jsc.append("handler, new org.exolab.castor.xml.validators.NameValidator(");
-                    jsc.append("org.exolab.castor.xml.validators.NameValidator.NMTOKEN));");
-                    break;
-                case XSType.QNAME_TYPE:
-                    //-- use CollectionFieldHandler
-                    jsc.add("handler = new org.exolab.castor.xml.handlers.CollectionFieldHandler(");
-                    jsc.append("handler, null);");
-                    break;
-                case XSType.IDREF_TYPE:
-                case XSType.IDREFS_TYPE:
-                    //-- uses special code in UnmarshalHandler
-                    //-- see UnmarshalHandler#processIDREF
-                    jsc.add("desc.setMultivalued(");
-                    jsc.append("" + member.isMultivalued());
-                    jsc.append(");");
-                    break;
-                default:
-                    break;
-            }
-        }
-    } //-- addSpecialHandlerLogic
-
-    /**
-     * Creates the validation code for a given member. This code will be
-     * appended to the given JSourceCode.
-     *
-     * @param member
-     *            the member for which to create the validation code.
-     * @param jsc
-     *            the JSourceCode to fill in.
-     */
-    private static void validationCode(final FieldInfo member, final JSourceCode jsc) {
-        if (member == null || jsc == null) {
-            return;
-        }
-
-        jsc.add("//-- validation code for: ");
-        jsc.append(member.getName());
-        String validator = member.getValidator();
-        if (validator != null && validator.length() > 0) {
-            jsc.add("fieldValidator = new " + validator + "();");
-        } else {
-            jsc.add("fieldValidator = new org.exolab.castor.xml.FieldValidator();");
-
-            //-- a hack, I know, I will change later
-            if (member.getName().equals("_anyObject")) {
-                jsc.add("desc.setValidator(fieldValidator);");
-                return;
-            }
-
-            XSType xsType = member.getSchemaType();
-            //--handle collections
-            if ((xsType.getType() == XSType.COLLECTION)) {
-                XSList xsList = (XSList) xsType;
-
-                jsc.add("fieldValidator.setMinOccurs(");
-                jsc.append(Integer.toString(xsList.getMinimumSize()));
-                jsc.append(");");
-                if (xsList.getMaximumSize() > 0) {
-                    jsc.add("fieldValidator.setMaxOccurs(");
-                    jsc.append(Integer.toString(xsList.getMaximumSize()));
-                    jsc.append(");");
-                }
-
-                xsType = ((CollectionInfo) member).getContent().getSchemaType();
-                //special handling for NMTOKEN
-                if (xsType.getType() == XSType.NMTOKEN_TYPE) {
-                    return;
-                }
-            } else if (member.isRequired()) {
-                jsc.add("fieldValidator.setMinOccurs(1);");
-            }
-
-            jsc.add("{ //-- local scope");
-            jsc.indent();
-            xsType.validationCode(jsc, member.getFixedValue(), FIELD_VALIDATOR_NAME);
-            jsc.unindent();
-            jsc.add("}");
-        }
-        jsc.add("desc.setValidator(fieldValidator);");
-    }
-
-    /**
-     * Returns the Class type (as a String) for the given XSType.
-     * @param jType the JType whose Class type will be returned
-     * @return the Class type (as a String) for the given XSType.
-     */
-    private static String classType(final JType jType) {
-        if (jType.isPrimitive()) {
-            return jType.getWrapperName() + ".TYPE";
-        }
-        return jType.toString() + ".class";
-    } //-- classType
-
-} //-- DescriptorSourceFactory
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SingleClassGenerator.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SingleClassGenerator.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SingleClassGenerator.java	(working copy)
@@ -55,6 +55,7 @@
 import java.util.Enumeration;
 import java.util.Properties;
 
+import org.exolab.castor.builder.descriptors.DescriptorSourceFactory;
 import org.exolab.castor.builder.conflictresolution.ClassNameCRStrategy;
 import org.exolab.castor.builder.conflictresolution.ClassNameCRStrategyRegistry;
 import org.exolab.castor.builder.info.ClassInfo;
@@ -106,7 +107,7 @@
     private final SourceGenerator _sourceGenerator;
 
     /**
-     * The class name conflict error handling strategy to use for 
+     * The class name conflict error handling strategy to use for
      * resolving class name conflicts.
      */
     private ClassNameCRStrategy _conflictStrategy;
@@ -122,8 +123,8 @@
      * @param sourceGenerator A SourceGenerator instance
      * @param conflictStrategyType Type of the {@link ClassNameCRStrategy} instance to be used.
      */
-    public SingleClassGenerator(final ConsoleDialog dialog, 
-            final SourceGenerator sourceGenerator, 
+    public SingleClassGenerator(final ConsoleDialog dialog,
+            final SourceGenerator sourceGenerator,
             final String conflictStrategyType) {
         this._dialog = dialog;
         this._sourceGenerator = sourceGenerator;
@@ -131,8 +132,8 @@
         this._header.appendComment(DEFAULT_HEADER);
         this._descSourceFactory = new DescriptorSourceFactory(_sourceGenerator);
         this._mappingSourceFactory = new MappingFileSourceFactory(_sourceGenerator);
-        
-        this._classNameConflictResolutionStrategyRegistry = 
+
+        this._classNameConflictResolutionStrategyRegistry =
             new ClassNameCRStrategyRegistry(sourceGenerator.getProperty(BuilderConfiguration.Property.NAME_CONFLICT_STRATEGIES, ""));
         createNameConflictStrategy(conflictStrategyType);
     }
@@ -273,7 +274,7 @@
         //-- Have we already processed a class with this name?
         JClass conflict = state.getProcessed(jClass.getName());
         if (conflict != null && !state.getSuppressNonFatalWarnings()) {
-            SGStateInfo stateAfterResolution = 
+            SGStateInfo stateAfterResolution =
                 _conflictStrategy.dealWithClassNameConflict(state, classInfo, conflict);
             return stateAfterResolution.getStatusCode() != SGStateInfo.STOP_STATUS;
         }
@@ -442,7 +443,7 @@
     /**
      * Sets the desired {@link ClassNameCRStrategy} instance type to be used
      * for name conflict resolution.
-     * @param nameConflictStrategy the desired {@link ClassNameCRStrategy} instance type 
+     * @param nameConflictStrategy the desired {@link ClassNameCRStrategy} instance type
      */
     public void setNameConflictStrategy(String nameConflictStrategy) {
         createNameConflictStrategy(nameConflictStrategy);
@@ -453,8 +454,8 @@
      * {@link ClassNameConflictResolutionStrategyFactory}.
      * @param nameConflictStrategy The desired {@link ClassNameCRStrategy} type.
      */
-    private void createNameConflictStrategy(String nameConflictStrategy) { 
-        this._conflictStrategy = 
+    private void createNameConflictStrategy(String nameConflictStrategy) {
+        this._conflictStrategy =
             _classNameConflictResolutionStrategyRegistry.getClassNameConflictResolutionStrategy(nameConflictStrategy);
         this._conflictStrategy.setConsoleDialog(_dialog);
         this._conflictStrategy.setSingleClassGenerator(this);
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceFactory.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceFactory.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceFactory.java	(working copy)
@@ -648,8 +648,8 @@
      *            the current SGStateInfo (cannot be null).
      * @return the JClass representation of the given Simpletype
      */
-    public JClass createSourceCode(final ExtendedBinding binding, 
-            final SimpleType simpleType, 
+    public JClass createSourceCode(final ExtendedBinding binding,
+            final SimpleType simpleType,
             final SGStateInfo sgState) {
         if (SimpleTypesFactory.isBuiltInType(simpleType.getTypeCode())) {
             String err = "You cannot construct a ClassInfo for a built-in SimpleType.";
@@ -716,7 +716,7 @@
             comp.setBinding(binding);
         }
         comp.setView(simpleType);
-        
+
         String packageName = comp.getJavaPackage();
         if ((packageName == null) || (packageName.length() == 0)) {
             packageName = sgState._packageName;
@@ -726,13 +726,13 @@
             enumeration = true;
             //-- Fix packageName TODO: this is a hack I know, we should change this
             if ((packageName != null) && (packageName.length() > 0)) {
-                packageName = packageName + ".types";
+                packageName = packageName + "." + SourceGeneratorConstants.TYPES_PACKAGE;
             } else {
-                packageName = "types";
+                packageName = SourceGeneratorConstants.TYPES_PACKAGE;
             }
         }
 
-        String boundClassName = comp.getJavaClassName(); 
+        String boundClassName = comp.getJavaClassName();
         if ((boundClassName != null) && (boundClassName.length() > 0)) {
             className = boundClassName;
             typeName = boundClassName;
@@ -1503,8 +1503,8 @@
      * @param complexType the given complex type.
      * @param state the given FactoryState
      */
-    private void processAttributes(final ExtendedBinding binding, 
-            final ComplexType complexType, 
+    private void processAttributes(final ExtendedBinding binding,
+            final ComplexType complexType,
             final FactoryState state) {
         if (complexType == null) {
             return;
@@ -1525,7 +1525,7 @@
             SimpleType sType = attr.getSimpleType();
 
             // look for simpleType def in base type(s)
-            XMLType baseXMLType = complexType.getBaseType(); 
+            XMLType baseXMLType = complexType.getBaseType();
             while (sType == null) {
                 // If no simple type found: Get the same attribute of the base type.
                 // If base type is not complex, forget it; break out of loop now.
@@ -1533,11 +1533,11 @@
                     break;
                 }
 
-                // There's a base complexType; get the attribute with the same name 
+                // There's a base complexType; get the attribute with the same name
                 // as this attribute (=attr) from it
                 final ComplexType baseComplexType = (ComplexType) baseXMLType;
                 AttributeDecl baseAttribute = baseComplexType.getAttributeDecl(attr.getName());
-                
+
                 if (baseAttribute != null) {
                     // See if this one has a simple-type...
                     sType = baseAttribute.getSimpleType();
@@ -1545,7 +1545,7 @@
                         attr.setSimpleType(sType);
                         break;
                     }
-                } 
+                }
 
                 // ... if not, go another step higher in the class hierarchy
                 baseXMLType = baseXMLType.getBaseType();
@@ -1825,8 +1825,8 @@
      *            our current state
      * @see #processEnumerationAsBaseType
      */
-    private void processEnumeration(final ExtendedBinding binding, 
-            final SimpleType simpleType, 
+    private void processEnumeration(final ExtendedBinding binding,
+            final SimpleType simpleType,
             final FactoryState state) {
         // Added by robertlaferla at comcast dot net 01/21/2004
         if (_config.useEnumeratedTypeInterface()) {
@@ -1870,7 +1870,7 @@
         _enumerationFactory.processEnumerationAsBaseType(binding, simpleType, state);
     } //-- processEnumerationAsBaseType
 
-    
+
 
     /**
      * Adds a given FieldInfo to the JClass and ClassInfo stored in the given
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceGeneratorConstants.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceGeneratorConstants.java	(revision 0)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceGeneratorConstants.java	(revision 0)
@@ -0,0 +1,13 @@
+package org.exolab.castor.builder;
+
+/**
+ * Defines contants used throughout source generation.
+ * @author ekuns
+ *
+ */
+public interface SourceGeneratorConstants {
+
+    /** Enumerations are placed into this special package relative to the generated source. */
+    String TYPES_PACKAGE = "types";
+
+}
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/TypeConversion.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/TypeConversion.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/TypeConversion.java	(working copy)
@@ -42,7 +42,6 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.builder;
 
 import java.util.Enumeration;
@@ -97,6 +96,7 @@
 import org.exolab.castor.xml.schema.Structure;
 import org.exolab.castor.xml.schema.Union;
 import org.exolab.javasource.JClass;
+import org.exolab.javasource.JType;
 
 /**
  * A class used to convert XML Schema SimpleTypes into the appropriate XSType.
@@ -106,21 +106,14 @@
  */
 public class TypeConversion {
 
-    /**
-     * Jakarta's common-logging logger
-     */
+    /** Jakarta's common-logging logger. */
     private static final Log LOG = LogFactory.getLog(TypeConversion.class);
 
-    /**
-     * Default package name for simple type (enumerations).
-     */
-    private static final String TYPES_PACKAGE = "types";
-
-    /** Configuration for our source generator */
-    private BuilderConfiguration _config = null;
+    /** Configuration for our source generator. */
+    private final BuilderConfiguration _config;
 
     /**
-     * Creates a new TypeConversion instance
+     * Creates a new TypeConversion instance.
      *
      * @param config the BuilderConfiguration instance (must not be null).
      */
@@ -156,7 +149,8 @@
      *            true if source code is to be generated for Java 5
      * @return the XSType which represets the given Simpletype
      */
-    public XSType convertType(final SimpleType simpleType, final String packageName, final boolean useJava50) {
+    public XSType convertType(final SimpleType simpleType, final String packageName,
+                              final boolean useJava50) {
          return convertType(simpleType, _config.usePrimitiveWrapper(), packageName, useJava50);
     }
 
@@ -176,7 +170,7 @@
      * @return the XSType which represets the given Simpletype
      */
     public XSType convertType(final SimpleType simpleType, final boolean useWrapper,
-                              String packageName, final boolean useJava50) {
+                              final String packageName, final boolean useJava50) {
         if (simpleType == null) {
             return null;
         }
@@ -200,7 +194,7 @@
             return new XSClass(new JClass(className));
         }
 
-        xsType = findXSType(simpleType, packageName);
+        xsType = findXSTypeForEnumeration(simpleType, packageName);
         if (xsType != null) {
             return xsType;
         }
@@ -206,7 +200,6 @@
         }
 
         // If we don't have the XSType yet, we have to look at the Type Code
-        String warning;
 
         switch (base.getTypeCode()) {
             case SimpleTypesFactory.ID_TYPE:             //-- ID
@@ -370,36 +363,9 @@
                 xsQName.setFacets(simpleType);
                 return xsQName;
             case SimpleTypesFactory.STRING_TYPE:               //-- string
-                //-- Enumeration ?
-                if (simpleType.hasFacet(Facet.ENUMERATION)) {
-                    String typeName = simpleType.getName();
-                    //-- anonymous type
-                    if (typeName == null) {
-                        Structure parent = simpleType.getParent();
-                        if (parent instanceof ElementDecl) {
-                            typeName = ((ElementDecl) parent).getName();
-                        } else if (parent instanceof AttributeDecl) {
-                            typeName = ((AttributeDecl) parent).getName();
-                        }
-                        typeName = typeName + "Type";
-                    }
-                    String className = JavaNaming.toJavaClassName(typeName);
-
-                    if (packageName == null) {
-                        String ns = simpleType.getSchema().getTargetNamespace();
-                        packageName = _config.lookupPackageByNamespace(ns);
-                    }
-                    if (packageName  != null && packageName .length() > 0) {
-                        packageName  = packageName  + '.' + TYPES_PACKAGE;
-                    } else {
-                        packageName  = TYPES_PACKAGE;
-                    }
-
-                    className = packageName  + '.' + className;
-                    xsType = new XSClass(new JClass(className));
-                    xsType.setAsEnumerated(true);
-                    //- End Enumeration
-                } else {
+                xsType = findXSTypeForEnumeration(simpleType, packageName);
+                if (xsType == null) {
+                    // Not an enumerated String type
                     XSString xsString = new XSString();
                     if (!simpleType.isBuiltInType()) {
                         xsString.setFacets(simpleType);
@@ -436,9 +402,8 @@
                     name = simpleType.getBuiltInBaseType().getName();
                 }
 
-                warning = "Warning: The W3C datatype '" + name + "' "
-                          + "is not currently supported by Castor Source Generator.";
-                System.out.println(warning);
+                LOG.warn("Warning: The W3C datatype '" + name + "' "
+                        + "is not currently supported by Castor Source Generator.");
                 String className = JavaNaming.toJavaClassName(name);
                 xsType = new XSClass(new JClass(className));
                 break;
@@ -448,7 +413,7 @@
     } //-- convertType
 
     /**
-     * Returns the XSType that corresponds to the given javaType
+     * Returns the XSType that corresponds to the given javaType.
      * @param javaType name of the Java type for which to look up the XSType
      * @return XSType that corresponds to the given javaType
      */
@@ -511,33 +476,13 @@
     }
 
     /**
-     * Returns the common type for the Union, or null if no common type exists
-     * among the members of the Union.
-     *
-     * @param union
-     *            the Union to return the common type for
-     * @return the common SimpleType for the Union.
+     * Returns an XSType for an enumerated type.  For non-enumerated types,
+     * returns null.
+     * @param simpleType the SimpleType being inspected
+     * @param packageName current package name
+     * @return an XSType for an enumerated type, null for a non-enumerated type.
      */
-    private static SimpleType findCommonType(final Union union) {
-        SimpleType common = null;
-        Enumeration enumeration = union.getMemberTypes();
-        while (enumeration.hasMoreElements()) {
-            SimpleType type = (SimpleType) enumeration.nextElement();
-            type = type.getBuiltInBaseType();
-            if (common == null) {
-                common = type;
-            } else {
-                common = compare(common, type);
-                //-- no common types
-                if (common == null) {
-                    break;
-                }
-            }
-        }
-        return common;
-    } //-- findCommonType
-
-    private XSType findXSType(final SimpleType simpleType, final String packageName) {
+    private XSType findXSTypeForEnumeration(final SimpleType simpleType, final String packageName) {
         if (!simpleType.hasFacet(Facet.ENUMERATION)) {
             return null;
         }
@@ -558,6 +503,7 @@
 
         String className = JavaNaming.toJavaClassName(typeName);
 
+        // Get the appropriate package name for this type
         String typePackageName = packageName;
         if (typePackageName == null) {
             String ns = simpleType.getSchema().getTargetNamespace();
@@ -563,13 +509,15 @@
             String ns = simpleType.getSchema().getTargetNamespace();
             typePackageName = _config.lookupPackageByNamespace(ns);
         }
+
         if (typePackageName != null && typePackageName.length() > 0) {
-            typePackageName = typePackageName  + '.' + TYPES_PACKAGE;
+            typePackageName = typePackageName  + '.' + SourceGeneratorConstants.TYPES_PACKAGE;
         } else {
-            typePackageName = TYPES_PACKAGE;
+            typePackageName = SourceGeneratorConstants.TYPES_PACKAGE;
         }
 
         className = typePackageName  + '.' + className;
+
         xsType = new XSClass(new JClass(className));
         xsType.setAsEnumerated(true);
 
@@ -577,8 +525,36 @@
     }
 
     /**
-     * Compares the two SimpleTypes. The common ancestor of both types will be
-     * returned, otherwise null is returned if the types are not compatible.
+     * Returns the common type for the Union, or null if no common type exists
+     * among the members of the Union.
+     *
+     * @param union
+     *            the Union to return the common type for
+     * @return the common SimpleType for the Union.
+     */
+    private static SimpleType findCommonType(final Union union) {
+        SimpleType common = null;
+        Enumeration enumeration = union.getMemberTypes();
+        while (enumeration.hasMoreElements()) {
+            SimpleType type = (SimpleType) enumeration.nextElement();
+            type = type.getBuiltInBaseType();
+            if (common == null) {
+                common = type;
+            } else {
+                common = findCommonType(common, type);
+                //-- no common types
+                if (common == null) {
+                    break;
+                }
+            }
+        }
+        return common;
+    } //-- findCommonType
+
+    /**
+     * Compares the two SimpleTypes. The lowest common ancestor of both types
+     * will be returned, otherwise null is returned if the types are not
+     * compatible.
      *
      * @param aType
      *            the first type to compare
@@ -584,10 +560,10 @@
      *            the first type to compare
      * @param bType
      *            the second type to compare
-     * @return the common anscestor of both types if there is one, null if the
+     * @return the common ancestor of both types if there is one, null if the
      *         types are not compatible.
      */
-    private static SimpleType compare(final SimpleType aType, final SimpleType bType) {
+    private static SimpleType findCommonType(final SimpleType aType, final SimpleType bType) {
         int type1 = aType.getTypeCode();
         int type2 = bType.getTypeCode();
 
@@ -595,20 +571,13 @@
             return aType;
         }
 
-        //-- add comparison code
-        if (isNumeric(aType)) {
-            if (isNumeric(bType)) {
-                //-- compare numbers
-                //-- TODO: *To be added*
-            }
-        } else if (isString(aType)) {
-            if (isString(bType)) {
-                //-- compare string types
-                //-- TODO: *To be added*
-            }
+        if (isNumeric(aType) && isNumeric(bType)) {
+            //-- TODO: Finish this so we can implement Unions
+        } else if (isString(aType) && isString(bType)) {
+            //-- TODO: Finish this so we can implement Unions
         }
-        //-- Just return string for now, as all simpleTypes can
-        //-- fit into a string
+
+        //-- Just return string for now, as all simpleTypes can fit into a string
         Schema schema = aType.getSchema();
         return schema.getSimpleType("string", schema.getSchemaNamespace());
     }
@@ -665,15 +634,18 @@
         }
     } //-- isString
 
-    static class TypeNames {
-        protected static final String BOOLEAN_PRIMITIVE = "boolean";
-        protected static final String BOOLEAN_OBJECT    = "java.lang.Boolean";
-        protected static final String BYTE_PRIMITIVE    = "byte";
-        protected static final String BYTE_OBJECT       = "java.lang.Byte";
+    /**
+     * Constants.
+     */
+    protected static class TypeNames {
+        protected static final String BOOLEAN_PRIMITIVE = JType.BOOLEAN.getName();
+        protected static final String BOOLEAN_OBJECT    = JType.BOOLEAN.getWrapperName();
+        protected static final String BYTE_PRIMITIVE    = JType.BYTE.getName();
+        protected static final String BYTE_OBJECT       = JType.BYTE.getWrapperName();
         protected static final String DATE              = "java.util.Date";
         protected static final String CASTOR_DATE       = "org.exolab.castor.types.Date";
         protected static final String CASTOR_TIME       = "org.exolab.castor.types.Time";
-        protected static final String CASTOR_DURATION   = "org.exolab.castor.types.Guration";
+        protected static final String CASTOR_DURATION   = "org.exolab.castor.types.Duration";
         protected static final String CASTOR_GMONTH     = "org.exolab.castor.types.GMonth";
         protected static final String CASTOR_GMONTHDAY  = "org.exolab.castor.types.GMonthDay";
         protected static final String CASTOR_GYEAR      = "org.exolab.castor.types.GYear";
@@ -680,14 +652,14 @@
         protected static final String CASTOR_GYEARMONTH = "org.exolab.castor.types.GYearMonth";
         protected static final String CASTOR_GDAY       = "org.exolab.castor.types.GDay";
         protected static final String DECIMAL           = "java.math.BigDecimal";
-        protected static final String DOUBLE_PRIMITIVE  = "double";
-        protected static final String DOUBLE_OBJECT     = "java.lang.Double";
-        protected static final String FLOAT_PRIMITIVE   = "float";
-        protected static final String FLOAT_OBJECT      = "java.lang.Float";
-        protected static final String INT               = "int";
-        protected static final String INTEGER           = "java.lang.Integer";
-        protected static final String SHORT_PRIMITIVE   = "short";
-        protected static final String SHORT_OBJECT      = "java.lang.Short";
+        protected static final String DOUBLE_PRIMITIVE  = JType.DOUBLE.getName();
+        protected static final String DOUBLE_OBJECT     = JType.DOUBLE.getWrapperName();
+        protected static final String FLOAT_PRIMITIVE   = JType.FLOAT.getName();
+        protected static final String FLOAT_OBJECT      = JType.FLOAT.getWrapperName();
+        protected static final String INT               = JType.INT.getName();
+        protected static final String INTEGER           = JType.INT.getWrapperName();
+        protected static final String SHORT_PRIMITIVE   = JType.SHORT.getName();
+        protected static final String SHORT_OBJECT      = JType.SHORT.getWrapperName();
         protected static final String STRING            = "java.lang.String";
     }
 
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java	(working copy)
@@ -34,7 +34,7 @@
  * @version $Revision: 6469 $ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $
  */
 public class XMLFieldHandlerFactory {
-    
+
     /**
      * The XML code generator configuration.
      */
@@ -50,7 +50,7 @@
 
     /**
      * Creates the XMLFieldHandler for the given FieldInfo.
-     * 
+     *
      * @param member
      *            the member for which to create an XMLFieldHandler
      * @param xsType
@@ -62,7 +62,7 @@
      * @param forGeneralizedHandler
      *            Whether to generate a generalized field handler
      */
-    void createXMLFieldHandler(final FieldInfo member,
+    public void createXMLFieldHandler(final FieldInfo member,
             final XSType xsType, final String localClassName,
             final JSourceCode jsc, final boolean forGeneralizedHandler) {
 
@@ -92,7 +92,7 @@
 
         createNewInstanceMethod(member, xsType, jsc,
                 forGeneralizedHandler, any, isEnumerated);
-        
+
         jsc.unindent();
         jsc.add("};");
     } // --end of XMLFieldHandler
@@ -99,7 +99,7 @@
 
     /**
      * Creates the getValue() method of the corresponsing XMLFieldHandler.
-     * 
+     *
      * @param member
      *            The member element.
      * @param xsType
@@ -148,7 +148,7 @@
 
     /**
      * Creates the setValue() method of the corresponsing XMLFieldHandler.
-     * 
+     *
      * @param member
      *            The member element.
      * @param xsType
@@ -168,12 +168,12 @@
      * @param isContent
      *            Whether to create a setValue() method for XML content.
      */
-    private void createSetValueMethod(final FieldInfo member, 
-            final XSType xsType, 
-            final String localClassName, 
-            final JSourceCode jsc, 
-            boolean any, 
-            boolean isAttribute, 
+    private void createSetValueMethod(final FieldInfo member,
+            final XSType xsType,
+            final String localClassName,
+            final JSourceCode jsc,
+            boolean any,
+            boolean isAttribute,
             boolean isContent) {
         if (_config.useJava50()) {
             jsc.add("@Override");
@@ -253,7 +253,7 @@
 
     /**
      * Creates the resetValue() method of the corresponsing XMLFieldHandler.
-     * 
+     *
      * @param member
      *            The member element.
      * @param jsc
@@ -261,8 +261,8 @@
      * @param localClassName
      *            Name of the object instance as used locally
      */
-    private void createResetMethod(final FieldInfo member, 
-            final String localClassName, 
+    private void createResetMethod(final FieldInfo member,
+            final String localClassName,
             final JSourceCode jsc) {
         // -- reset method (handle collections only)
         if (member.isMultivalued()) {
@@ -297,7 +297,7 @@
 
     /**
      * Creates the newInstance() method of the corresponsing XMLFieldHandler.
-     * 
+     *
      * @param member
      *            The member element.
      * @param xsType
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorJClass.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorJClass.java	(revision 6531)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorJClass.java	(working copy)
@@ -42,8 +42,7 @@
  *
  * $Id$
  */
-
-package org.exolab.castor.builder.util;
+package org.exolab.castor.builder.descriptors;
 
 import org.exolab.castor.builder.BuilderConfiguration;
 import org.exolab.castor.builder.SGTypes;
@@ -57,7 +56,9 @@
 import org.exolab.javasource.JType;
 
 /**
- * A class which defines the necessary methods for generating ClassDescriptor source files.
+ * A class which defines the necessary methods for generating ClassDescriptor
+ * source files.
+ *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2006-03-10 15:42:54 -0700 (Fri, 10 Mar 2006) $
  */
@@ -63,38 +64,39 @@
  */
 public class DescriptorJClass extends JClass {
 
-    //-- org.exolab.castor.mapping
-    private static final JClass _ClassDescriptorClass;
-    private static final JClass _FieldDescriptorClass;
+    /** Class Descriptors extend this base class. */
+    private static final String XMLCLASS_DESCRIPTOR_IMPL = "org.exolab.castor.xml.util.XMLClassDescriptorImpl";
+    /** FIXME:  Document this field. */
+    private static final String MAPPING_ACCESS_MODE      = "org.exolab.castor.mapping.AccessMode";
 
-    //-- org.exolab.castor.xml
-    private static final JClass _XMLFieldDescriptorClass;
-    private static final JType  _TypeValidatorClass;
+    /** Class descriptors implement this interface from org.exolab.castor.mapping. */
+    private static final JClass CLASS_DESCRIPTOR_CLASS;
+    /** Field descriptors implement this interface from org.exolab.castor.mapping. */
+    private static final JClass FIELD_DESCRIPTOR_CLASS;
+
+    /** Field descriptors implement this interface from org.exolab.castor.xml. */
+    private static final JClass XML_FIELD_DESCRIPTOR_CLASS;
+    /** Type validators implement this interface from org.exolab.castor.xml. */
+    private static final JType  TYPE_VALIDATOR_CLASS;
 
     static {
-        _ClassDescriptorClass    = new JClass("org.exolab.castor.mapping.ClassDescriptor");
-        _FieldDescriptorClass    = new JClass("org.exolab.castor.mapping.FieldDescriptor");
-        _XMLFieldDescriptorClass = new JClass("org.exolab.castor.xml.XMLFieldDescriptor");
-        _TypeValidatorClass      = new JClass("org.exolab.castor.xml.TypeValidator");
+        CLASS_DESCRIPTOR_CLASS     = new JClass("org.exolab.castor.mapping.ClassDescriptor");
+        FIELD_DESCRIPTOR_CLASS     = new JClass("org.exolab.castor.mapping.FieldDescriptor");
+        XML_FIELD_DESCRIPTOR_CLASS = new JClass("org.exolab.castor.xml.XMLFieldDescriptor");
+        TYPE_VALIDATOR_CLASS       = new JClass("org.exolab.castor.xml.TypeValidator");
     }
 
-    //-- methods defined by org.exolab.castor.xml.util.XMLClassDescriptorImpl
-    private JMethod _getElementDefinition    = null;
-
-    //-- methods defined by org.exolab.castor.xml.XMLClassDescriptor
-    private JMethod _getNameSpacePrefix      = null;
-    private JMethod _getNameSpaceURI         = null;
-    private JMethod _getXMLName              = null;
-
-    //-- methods defined by org.exolab.castor.mapping.ClassDescriptor
-    private JMethod _getAccessMode = null;
-    private JMethod _getIdentity   = null;
-    private JMethod _getExtends    = null;
-    private JMethod _getJavaClass  = null;
-
+    /** The type being described by the Descriptor class we'll generate. */
     private final JClass               _type;
+    /** Source Builder configuration. */
     private final BuilderConfiguration _config;
 
+    /**
+     * Constructs a DescriptorJClass.
+     * @param config Builder Configuration
+     * @param className name of this descriptor class
+     * @param type the type that is described by this descriptor
+     */
     public DescriptorJClass(final BuilderConfiguration config, final String className,
                             final JClass type) {
         super(className);
@@ -103,38 +105,6 @@
         init();
     } //-- DescriptorJClass
 
-    public JMethod getElementDefinitionMethod() {
-        return _getElementDefinition;
-    } //-- getElementDefinitionMethod
-
-    public JMethod getNameSpacePrefixMethod() {
-        return _getNameSpacePrefix;
-    } //-- getNamespaceURIMethod
-
-    public JMethod getNameSpacePrefixURI() {
-        return _getNameSpaceURI;
-    } //-- getNamespacePrefixMethod
-
-    public JMethod getXMLNameMethod() {
-        return _getXMLName;
-    } //-- getIdentityMethod
-
-    public JMethod getAccessModeMethod() {
-        return _getAccessMode;
-    } //-- getAccessModeMethod
-
-    public JMethod getExtendsMethod() {
-        return _getExtends;
-    } //-- getExtendsMethod
-
-    public JMethod getIdentityMethod() {
-        return _getIdentity;
-    } //-- getIdentityMethod
-
-    public JMethod getJavaClassMethod() {
-        return _getJavaClass;
-    } // getJavaClassMethod
-
     //-------------------/
     //- Private Methods -/
     //-------------------/
@@ -140,7 +110,7 @@
     //-------------------/
 
     /**
-     * Initializes this DescriptorJClass with the required methods
+     * Initializes this DescriptorJClass with the required methods.
      */
     private void init() {
         // Make sure that the Descriptor is extended XMLClassDescriptor even when
@@ -154,7 +124,7 @@
 
         if (_type.getSuperClassQualifiedName() == null
             || _type.getSuperClassQualifiedName().equals(superClass)) {
-            setSuperClass("org.exolab.castor.xml.util.XMLClassDescriptorImpl");
+            setSuperClass(XMLCLASS_DESCRIPTOR_IMPL);
         } else {
             extended = true;
             setSuperClass(_type.getSuperClassQualifiedName() + "Descriptor");
@@ -161,12 +131,12 @@
         }
         superClass = null;
 
-//      addImport("org.exolab.castor.xml.NodeType");
-//      addImport("org.exolab.castor.xml.XMLFieldHandler");
-//      addImport("org.exolab.castor.xml.handlers.*");
-//      addImport("org.exolab.castor.xml.util.XMLFieldDescriptorImpl");
-//      addImport("org.exolab.castor.xml.validators.*");
-//      addImport("org.exolab.castor.xml.FieldValidator");
+        if (_type.getPackageName() != null && _type.getPackageName().length() > 0) {
+            addImport(_type.getName());
+            if (extended) {
+                addImport(_type.getSuperClassQualifiedName() + "Descriptor");
+            }
+        }
 
         addField(new JField(JType.BOOLEAN, "elementDefinition"));
 
@@ -175,7 +145,7 @@
         addField(new JField(SGTypes.String, "xmlName"));
         //-- if there is a super class, the identity field must remain
         //-- the same than the one in the super class
-        addField(new JField(_XMLFieldDescriptorClass, "identity"));
+        addField(new JField(XML_FIELD_DESCRIPTOR_CLASS, "identity"));
 
         //-- create default constructor
         addDefaultConstructor(extended);
@@ -222,7 +192,7 @@
     }
 
     /**
-     * Adds the methods we override from
+     * Adds the methods we override from.
      * {@link org.exolab.castor.xml.util.XMLClassDescriptorImpl}
      */
     private void addXMLClassDescriptorImplOverrides() {
@@ -227,16 +197,16 @@
      */
     private void addXMLClassDescriptorImplOverrides() {
         //-- create isElementDefinition method
-        _getElementDefinition = new JMethod("isElementDefinition", JType.BOOLEAN,
-                                            "true if XML schema definition of this Class is that of a global\n"
-                                            + "element or element with anonymous type definition.");
-        JSourceCode jsc = _getElementDefinition.getSourceCode();
+        JMethod getElementDefinition = new JMethod("isElementDefinition", JType.BOOLEAN,
+                               "true if XML schema definition of this Class is that of a global\n"
+                               + "element or element with anonymous type definition.");
+        JSourceCode jsc = getElementDefinition.getSourceCode();
         jsc.add("return elementDefinition;");
-        addMethod(_getElementDefinition);
+        addMethod(getElementDefinition);
     }
 
     /**
-     * Adds the methods we override from
+     * Adds the methods we override from.
      * {@link org.exolab.castor.xml.XMLClassDescriptor}
      */
     private void addXMLClassDescriptorOverrides() {
@@ -253,7 +223,6 @@
         jsc = method.getSourceCode();
         jsc.add("return nsPrefix;");
         addMethod(method);
-        _getNameSpacePrefix = method;
 
         //-- create getNameSpaceURI method
         method = new JMethod("getNameSpaceURI", SGTypes.String,
@@ -266,11 +235,11 @@
         jsc = method.getSourceCode();
         jsc.add("return nsURI;");
         addMethod(method);
-        _getNameSpaceURI = method;
 
         //-- create getValidator method
-        method = new JMethod("getValidator", _TypeValidatorClass,
-                             "a specific validator for the class described by this ClassDescriptor.");
+        method = new JMethod("getValidator", TYPE_VALIDATOR_CLASS,
+                             "a specific validator for the class described"
+                             + " by this ClassDescriptor.");
 
         if (_config.useJava50()) {
             method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
@@ -291,11 +260,10 @@
         jsc = method.getSourceCode();
         jsc.add("return xmlName;");
         addMethod(method);
-        _getXMLName = method;
     }
 
     /**
-     * Adds the methods we override from
+     * Adds the methods we override from.
      * {@link org.exolab.castor.mapping.ClassDescriptor}
      * @param extended true if we extend another class and thus need to call super()
      */
@@ -303,27 +271,27 @@
         JSourceCode jsc;
 
         //-- create getAccessMode method
-        JClass amClass = new JClass("org.exolab.castor.mapping.AccessMode");
-        _getAccessMode = new JMethod("getAccessMode", amClass,
+        JClass amClass = new JClass(MAPPING_ACCESS_MODE);
+        JMethod getAccessMode = new JMethod("getAccessMode", amClass,
                                      "the access mode specified for this class.");
 
         if (_config.useJava50()) {
-            _getAccessMode.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
+            getAccessMode.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
         }
 
-        jsc = _getAccessMode.getSourceCode();
+        jsc = getAccessMode.getSourceCode();
         jsc.add("return null;");
-        addMethod(_getAccessMode);
+        addMethod(getAccessMode);
 
         //-- create getExtends method
-        _getExtends = new JMethod("getExtends", _ClassDescriptorClass,
+        JMethod getExtends = new JMethod("getExtends", CLASS_DESCRIPTOR_CLASS,
                                   "the class descriptor of the class extended by this class.");
 
         if (_config.useJava50()) {
-            _getExtends.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
+            getExtends.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
         }
 
-        jsc = _getExtends.getSourceCode();
+        jsc = getExtends.getSourceCode();
         if (extended) {
             jsc.add("return super.getExtends();");
         } else {
@@ -331,17 +299,17 @@
         }
 
         //--don't add the type to the import list
-        addMethod(_getExtends, false);
+        addMethod(getExtends, false);
 
         //-- create getIdentity method
-        _getIdentity = new JMethod("getIdentity", _FieldDescriptorClass,
+        JMethod getIdentity = new JMethod("getIdentity", FIELD_DESCRIPTOR_CLASS,
                                    "the identity field, null if this class has no identity.");
 
         if (_config.useJava50()) {
-            _getIdentity.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
+            getIdentity.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
         }
 
-        jsc = _getIdentity.getSourceCode();
+        jsc = getIdentity.getSourceCode();
         if (extended) {
             jsc.add("if (identity == null) {");
             jsc.indent();
@@ -352,17 +320,17 @@
         jsc.add("return identity;");
 
         //--don't add the type to the import list
-        addMethod(_getIdentity, false);
+        addMethod(getIdentity, false);
 
         //-- create getJavaClass method
-        _getJavaClass = new JMethod("getJavaClass", SGTypes.Class,
+        JMethod getJavaClass = new JMethod("getJavaClass", SGTypes.Class,
                                     "the Java class represented by this descriptor.");
 
         if (_config.useJava50()) {
-            _getJavaClass.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
+            getJavaClass.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
         }
 
-        jsc = _getJavaClass.getSourceCode();
+        jsc = getJavaClass.getSourceCode();
         jsc.add("return ");
         jsc.append(classType(_type));
         jsc.append(";");
@@ -368,11 +336,11 @@
         jsc.append(";");
 
         //--don't add the type to the import list
-        addMethod(_getJavaClass, false);
+        addMethod(getJavaClass, false);
     }
 
     /**
-     * Returns the Class type (as a String) for the given XSType
+     * Returns the Class type (as a String) for the given XSType.
      *
      * @param jType
      *            the JType we are to return the class name of

Property changes on: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorJClass.java
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords
   + Id Revision

Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java	(working copy)
@@ -48,8 +48,11 @@
  * $Id$
  */
 
-package org.exolab.castor.builder;
+package org.exolab.castor.builder.descriptors;
 
+import org.exolab.castor.builder.BuilderConfiguration;
+import org.exolab.castor.builder.SGTypes;
+import org.exolab.castor.builder.XMLFieldHandlerFactory;
 import org.exolab.castor.builder.info.ClassInfo;
 import org.exolab.castor.builder.info.CollectionInfo;
 import org.exolab.castor.builder.info.FieldInfo;
@@ -54,10 +57,9 @@
 import org.exolab.castor.builder.info.CollectionInfo;
 import org.exolab.castor.builder.info.FieldInfo;
 import org.exolab.castor.builder.info.XMLInfo;
-import org.exolab.castor.builder.types.XSClass;
 import org.exolab.castor.builder.types.XSList;
 import org.exolab.castor.builder.types.XSType;
-import org.exolab.castor.builder.util.DescriptorJClass;
+import org.exolab.castor.xml.XMLConstants;
 import org.exolab.javasource.JClass;
 import org.exolab.javasource.JConstructor;
 import org.exolab.javasource.JField;
@@ -62,6 +64,7 @@
 import org.exolab.javasource.JConstructor;
 import org.exolab.javasource.JField;
 import org.exolab.javasource.JModifiers;
+import org.exolab.javasource.JNaming;
 import org.exolab.javasource.JSourceCode;
 import org.exolab.javasource.JType;
 
@@ -66,7 +69,7 @@
 import org.exolab.javasource.JType;
 
 /**
- * A factory for creating the source code of descriptor classes
+ * A factory for creating the source code of descriptor classes.
  *
  * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
  * @version $Revision$ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $
@@ -73,27 +76,20 @@
  */
 public class DescriptorSourceFactory {
 
-    /**
-     * GeneralizedFieldHandler
-     */
+    /** GeneralizedFieldHandler. */
     private static final JClass GENERALIZED_FIELD_HANDLER_CLASS =
         new JClass("org.exolab.castor.mapping.GeneralizedFieldHandler");
-
-    private static final String DESCRIPTOR_NAME      = "Descriptor";
+    /** Name of the field validator instance variable in generated code. */
     private static final String FIELD_VALIDATOR_NAME = "fieldValidator";
 
-    /**
-     * The BuilderConfiguration instance
-     */
-    private BuilderConfiguration _config = null;
+    /** The BuilderConfiguration instance. */
+    private final BuilderConfiguration _config;
 
-    /**
-     * Factory for creating XMLFieldHandler instances embedded in descriptors
-     */
+    /** Factory for creating XMLFieldHandler instances embedded in descriptors. */
     private XMLFieldHandlerFactory _xmlFieldHandlerFactory;
 
     /**
-     * Creates a new DescriptorSourceFactory with the given configuration
+     * Creates a new DescriptorSourceFactory with the given configuration.
      *
      * @param config the BuilderConfiguration instance
      */
@@ -108,7 +104,7 @@
 
     /**
      * Creates the Source code of a MarshalInfo for a given XML Schema element
-     * declaration
+     * declaration.
      *
      * @param classInfo
      *            the XML Schema element declaration
@@ -115,15 +111,15 @@
      * @return the JClass representing the MarshalInfo source code
      */
     public JClass createSource(final ClassInfo classInfo) {
-        JSourceCode jsc            = null;
         JClass jClass              = classInfo.getJClass();
-        String className           = jClass.getName();
         String localClassName      = jClass.getLocalName();
-        DescriptorJClass classDesc = new DescriptorJClass(_config, className + DESCRIPTOR_NAME, jClass);
+
+        String descriptorClassName = getQualifiedDescriptorClassName(jClass.getName(false));
+        DescriptorJClass classDesc = new DescriptorJClass(_config, descriptorClassName, jClass);
 
         //-- get handle to default constuctor
         JConstructor cons = classDesc.getConstructor(0);
-        jsc = cons.getSourceCode();
+        JSourceCode jsc   = cons.getSourceCode();
 
         //-- Set namespace prefix
         String nsPrefix = classInfo.getNamespacePrefix();
@@ -256,6 +252,27 @@
     //-------------------/
 
     /**
+     * Returns the fully-qualified class name of the Descriptor to create. Given
+     * the fully-qualified class name of the class we are creating a Descriptor
+     * for, return the correct fully-qualified name for the Descriptor.
+     *
+     * @param name
+     *            fully-qualified class name of the class we are describing
+     * @return the fully-qualified class name of the Descriptor to create
+     */
+    private String getQualifiedDescriptorClassName(final String name) {
+        String descPackage   = JNaming.getPackageFromClassName(name);
+        String descClassName = JNaming.getLocalNameFromClassName(name);
+
+        if (descPackage != null && descPackage.length() > 0) {
+            descPackage = descPackage +  "." + XMLConstants.DESCRIPTOR_PACKAGE + ".";
+        } else {
+            descPackage = "";
+        }
+        return descPackage + descClassName + XMLConstants.DESCRIPTOR_SUFFIX;
+    }
+
+    /**
      * Create special code for handling a member that is a restriction.
      * This will only change the Validation Code
      * @param member the restricted member for which we generate the restriction handling.
@@ -412,7 +429,8 @@
             if (className.equals(localClassName)) {
                 jsc.add("desc.setClassDescriptor(this);");
             } else {
-                jsc.add("desc.setClassDescriptor(new " + className + DESCRIPTOR_NAME + "());");
+                String descriptorClassName = getQualifiedDescriptorClassName(className);
+                jsc.add("desc.setClassDescriptor(new " + descriptorClassName + "());");
             }
         }
 
@@ -425,6 +443,7 @@
             jsc.append("\");");
         }
 
+        // FIXME:  This next statement does nothing ... why is it here?
         if (any && member.getNamespaceURI() == null) {
             nsURI = null;
         }

Property changes on: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords
   + Id Revision

Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/util/DescriptorJClass.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/util/DescriptorJClass.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/util/DescriptorJClass.java	(working copy)
@@ -1,388 +0,0 @@
-/**
- * Redistribution and use of this software and associated documentation
- * ("Software"), with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * 1. Redistributions of source code must retain copyright
- *    statements and notices.  Redistributions must also contain a
- *    copy of this document.
- *
- * 2. Redistributions in binary form must reproduce the
- *    above copyright notice, this list of conditions and the
- *    following disclaimer in the documentation and/or other
- *    materials provided with the distribution.
- *
- * 3. The name "Exolab" must not be used to endorse or promote
- *    products derived from this Software without prior written
- *    permission of Intalio, Inc.  For written permission,
- *    please contact info@exolab.org.
- *
- * 4. Products derived from this Software may not be called "Exolab"
- *    nor may "Exolab" appear in their names without prior written
- *    permission of Intalio, Inc. Exolab is a registered
- *    trademark of Intalio, Inc.
- *
- * 5. Due credit should be given to the Exolab Project
- *    (http://www.exolab.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved.
- *
- * $Id$
- */
-
-package org.exolab.castor.builder.util;
-
-import org.exolab.castor.builder.BuilderConfiguration;
-import org.exolab.castor.builder.SGTypes;
-import org.exolab.javasource.JAnnotation;
-import org.exolab.javasource.JAnnotationType;
-import org.exolab.javasource.JClass;
-import org.exolab.javasource.JConstructor;
-import org.exolab.javasource.JField;
-import org.exolab.javasource.JMethod;
-import org.exolab.javasource.JSourceCode;
-import org.exolab.javasource.JType;
-
-/**
- * A class which defines the necessary methods for generating ClassDescriptor source files.
- * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
- * @version $Revision$ $Date: 2006-03-10 15:42:54 -0700 (Fri, 10 Mar 2006) $
- */
-public class DescriptorJClass extends JClass {
-
-    //-- org.exolab.castor.mapping
-    private static final JClass _ClassDescriptorClass;
-    private static final JClass _FieldDescriptorClass;
-
-    //-- org.exolab.castor.xml
-    private static final JClass _XMLFieldDescriptorClass;
-    private static final JType  _TypeValidatorClass;
-
-    static {
-        _ClassDescriptorClass    = new JClass("org.exolab.castor.mapping.ClassDescriptor");
-        _FieldDescriptorClass    = new JClass("org.exolab.castor.mapping.FieldDescriptor");
-        _XMLFieldDescriptorClass = new JClass("org.exolab.castor.xml.XMLFieldDescriptor");
-        _TypeValidatorClass      = new JClass("org.exolab.castor.xml.TypeValidator");
-    }
-
-    //-- methods defined by org.exolab.castor.xml.util.XMLClassDescriptorImpl
-    private JMethod _getElementDefinition    = null;
-
-    //-- methods defined by org.exolab.castor.xml.XMLClassDescriptor
-    private JMethod _getNameSpacePrefix      = null;
-    private JMethod _getNameSpaceURI         = null;
-    private JMethod _getXMLName              = null;
-
-    //-- methods defined by org.exolab.castor.mapping.ClassDescriptor
-    private JMethod _getAccessMode = null;
-    private JMethod _getIdentity   = null;
-    private JMethod _getExtends    = null;
-    private JMethod _getJavaClass  = null;
-
-    private final JClass               _type;
-    private final BuilderConfiguration _config;
-
-    public DescriptorJClass(final BuilderConfiguration config, final String className,
-                            final JClass type) {
-        super(className);
-        this._config = config;
-        this._type   = type;
-        init();
-    } //-- DescriptorJClass
-
-    public JMethod getElementDefinitionMethod() {
-        return _getElementDefinition;
-    } //-- getElementDefinitionMethod
-
-    public JMethod getNameSpacePrefixMethod() {
-        return _getNameSpacePrefix;
-    } //-- getNamespaceURIMethod
-
-    public JMethod getNameSpacePrefixURI() {
-        return _getNameSpaceURI;
-    } //-- getNamespacePrefixMethod
-
-    public JMethod getXMLNameMethod() {
-        return _getXMLName;
-    } //-- getIdentityMethod
-
-    public JMethod getAccessModeMethod() {
-        return _getAccessMode;
-    } //-- getAccessModeMethod
-
-    public JMethod getExtendsMethod() {
-        return _getExtends;
-    } //-- getExtendsMethod
-
-    public JMethod getIdentityMethod() {
-        return _getIdentity;
-    } //-- getIdentityMethod
-
-    public JMethod getJavaClassMethod() {
-        return _getJavaClass;
-    } // getJavaClassMethod
-
-    //-------------------/
-    //- Private Methods -/
-    //-------------------/
-
-    /**
-     * Initializes this DescriptorJClass with the required methods
-     */
-    private void init() {
-        // Make sure that the Descriptor is extended XMLClassDescriptor even when
-        // the user has specified a super class for all the generated classes
-        String superClass = null;
-        if (_config != null) {
-            superClass = _config.getProperty(BuilderConfiguration.Property.SUPER_CLASS, null);
-        }
-
-        boolean extended = false;
-
-        if (_type.getSuperClassQualifiedName() == null
-            || _type.getSuperClassQualifiedName().equals(superClass)) {
-            setSuperClass("org.exolab.castor.xml.util.XMLClassDescriptorImpl");
-        } else {
-            extended = true;
-            setSuperClass(_type.getSuperClassQualifiedName() + "Descriptor");
-        }
-        superClass = null;
-
-//      addImport("org.exolab.castor.xml.NodeType");
-//      addImport("org.exolab.castor.xml.XMLFieldHandler");
-//      addImport("org.exolab.castor.xml.handlers.*");
-//      addImport("org.exolab.castor.xml.util.XMLFieldDescriptorImpl");
-//      addImport("org.exolab.castor.xml.validators.*");
-//      addImport("org.exolab.castor.xml.FieldValidator");
-
-        addField(new JField(JType.BOOLEAN, "elementDefinition"));
-
-        addField(new JField(SGTypes.String, "nsPrefix"));
-        addField(new JField(SGTypes.String, "nsURI"));
-        addField(new JField(SGTypes.String, "xmlName"));
-        //-- if there is a super class, the identity field must remain
-        //-- the same than the one in the super class
-        addField(new JField(_XMLFieldDescriptorClass, "identity"));
-
-        //-- create default constructor
-        addDefaultConstructor(extended);
-
-        //jsc.add("Class[] emptyClassArgs = new Class[0];");
-        //jsc.add("Class[] classArgs = new Class[1];");
-
-        //---------------------------------------------/
-        //- Methods Defined by XMLClassDescriptorImpl -/
-        //---------------------------------------------/
-
-        addXMLClassDescriptorImplOverrides();
-
-        //-----------------------------------------/
-        //- Methods Defined by XMLClassDescriptor -/
-        //-----------------------------------------/
-
-        addXMLClassDescriptorOverrides();
-
-        //--------------------------------------/
-        //- Methods defined by ClassDescriptor -/
-        //--------------------------------------/
-
-        addClassDescriptorOverrides(extended);
-    } //-- createSource
-
-    /**
-     * Adds our default constructor.
-     * @param extended true if we extend another class and thus need to call super()
-     */
-    private void addDefaultConstructor(final boolean extended) {
-        addConstructor(createConstructor());
-        JConstructor cons = getConstructor(0);
-        JSourceCode jsc = cons.getSourceCode();
-        jsc.add("super();");
-
-        if (extended) {
-            //-- add base class (for validation)
-            jsc.add("setExtendsWithoutFlatten(");
-            jsc.append("new ");
-            jsc.append(getSuperClassQualifiedName());
-            jsc.append("());");
-        }
-    }
-
-    /**
-     * Adds the methods we override from
-     * {@link org.exolab.castor.xml.util.XMLClassDescriptorImpl}
-     */
-    private void addXMLClassDescriptorImplOverrides() {
-        //-- create isElementDefinition method
-        _getElementDefinition = new JMethod("isElementDefinition", JType.BOOLEAN,
-                                            "true if XML schema definition of this Class is that of a global\n"
-                                            + "element or element with anonymous type definition.");
-        JSourceCode jsc = _getElementDefinition.getSourceCode();
-        jsc.add("return elementDefinition;");
-        addMethod(_getElementDefinition);
-    }
-
-    /**
-     * Adds the methods we override from
-     * {@link org.exolab.castor.xml.XMLClassDescriptor}
-     */
-    private void addXMLClassDescriptorOverrides() {
-        JMethod method;
-        JSourceCode jsc;
-        //-- create getNameSpacePrefix method
-        method = new JMethod("getNameSpacePrefix", SGTypes.String,
-                             "the namespace prefix to use when marshalling as XML.");
-
-        if (_config.useJava50()) {
-            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = method.getSourceCode();
-        jsc.add("return nsPrefix;");
-        addMethod(method);
-        _getNameSpacePrefix = method;
-
-        //-- create getNameSpaceURI method
-        method = new JMethod("getNameSpaceURI", SGTypes.String,
-                             "the namespace URI used when marshalling and unmarshalling as XML.");
-
-        if (_config.useJava50()) {
-            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = method.getSourceCode();
-        jsc.add("return nsURI;");
-        addMethod(method);
-        _getNameSpaceURI = method;
-
-        //-- create getValidator method
-        method = new JMethod("getValidator", _TypeValidatorClass,
-                             "a specific validator for the class described by this ClassDescriptor.");
-
-        if (_config.useJava50()) {
-            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = method.getSourceCode();
-        jsc.add("return this;");
-        addMethod(method);
-
-        //-- create getXMLName method
-        method = new JMethod("getXMLName", SGTypes.String,
-                             "the XML Name for the Class being described.");
-
-        if (_config.useJava50()) {
-            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = method.getSourceCode();
-        jsc.add("return xmlName;");
-        addMethod(method);
-        _getXMLName = method;
-    }
-
-    /**
-     * Adds the methods we override from
-     * {@link org.exolab.castor.mapping.ClassDescriptor}
-     * @param extended true if we extend another class and thus need to call super()
-     */
-    private void addClassDescriptorOverrides(final boolean extended) {
-        JSourceCode jsc;
-
-        //-- create getAccessMode method
-        JClass amClass = new JClass("org.exolab.castor.mapping.AccessMode");
-        _getAccessMode = new JMethod("getAccessMode", amClass,
-                                     "the access mode specified for this class.");
-
-        if (_config.useJava50()) {
-            _getAccessMode.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = _getAccessMode.getSourceCode();
-        jsc.add("return null;");
-        addMethod(_getAccessMode);
-
-        //-- create getExtends method
-        _getExtends = new JMethod("getExtends", _ClassDescriptorClass,
-                                  "the class descriptor of the class extended by this class.");
-
-        if (_config.useJava50()) {
-            _getExtends.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = _getExtends.getSourceCode();
-        if (extended) {
-            jsc.add("return super.getExtends();");
-        } else {
-            jsc.add("return null;");
-        }
-
-        //--don't add the type to the import list
-        addMethod(_getExtends, false);
-
-        //-- create getIdentity method
-        _getIdentity = new JMethod("getIdentity", _FieldDescriptorClass,
-                                   "the identity field, null if this class has no identity.");
-
-        if (_config.useJava50()) {
-            _getIdentity.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = _getIdentity.getSourceCode();
-        if (extended) {
-            jsc.add("if (identity == null) {");
-            jsc.indent();
-            jsc.add("return super.getIdentity();");
-            jsc.unindent();
-            jsc.add("}");
-        }
-        jsc.add("return identity;");
-
-        //--don't add the type to the import list
-        addMethod(_getIdentity, false);
-
-        //-- create getJavaClass method
-        _getJavaClass = new JMethod("getJavaClass", SGTypes.Class,
-                                    "the Java class represented by this descriptor.");
-
-        if (_config.useJava50()) {
-            _getJavaClass.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
-        }
-
-        jsc = _getJavaClass.getSourceCode();
-        jsc.add("return ");
-        jsc.append(classType(_type));
-        jsc.append(";");
-
-        //--don't add the type to the import list
-        addMethod(_getJavaClass, false);
-    }
-
-    /**
-     * Returns the Class type (as a String) for the given XSType
-     *
-     * @param jType
-     *            the JType we are to return the class name of
-     * @return the Class name (as a String) for the given XSType
-     */
-    private static String classType(final JType jType) {
-        if (jType.isPrimitive()) {
-            return jType.getWrapperName() + ".TYPE";
-        }
-        return jType.toString() + ".class";
-    } //-- classType
-
-} //-- DescriptorJClass
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/XMLConstants.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/XMLConstants.java	(revision 0)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/XMLConstants.java	(revision 0)
@@ -0,0 +1,10 @@
+package org.exolab.castor.xml;
+
+public interface XMLConstants {
+    /** Descriptors are placed into this special package relative to the generated source. */
+    String DESCRIPTOR_PACKAGE = "descriptors";
+
+    /** This suffix is added to a class name to make its descriptor. */
+    String DESCRIPTOR_SUFFIX = "Descriptor";
+
+}
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java	(working copy)
@@ -47,8 +47,6 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml.util;
 
 import java.io.IOException;
@@ -77,10 +75,11 @@
 import org.exolab.castor.xml.ResolverException;
 import org.exolab.castor.xml.XMLClassDescriptor;
 import org.exolab.castor.xml.XMLClassDescriptorResolver;
+import org.exolab.castor.xml.XMLConstants;
 import org.exolab.castor.xml.XMLMappingLoader;
 
 /**
- * The default implementation of the ClassDescriptorResolver interface
+ * The default implementation of the ClassDescriptorResolver interface.
  *
  * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
  * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
@@ -87,12 +86,10 @@
  */
 public class XMLClassDescriptorResolverImpl
     implements XMLClassDescriptorResolver {
- 
-    private static final String DESCRIPTOR_SUFFIX  = "Descriptor";
-    
+
     /**
      * internal cache for class loading (this is used to avoid trying to load
-     * missing classes again and again)
+     * missing classes again and again).
      */
     private ClassCache _classCache       = null;
 
@@ -103,30 +100,30 @@
     private DescriptorCache _descriptorCache  = null;
 
     /**
-     * The introspector to use, if necessary, to 
-     * create dynamic ClassDescriptors
+     * The introspector to use, if necessary, to
+     * create dynamic ClassDescriptors.
      */
     private Introspector _introspector = null;
-    
+
     /**
-     * The classloader to use
+     * The classloader to use.
      */
     private ClassLoader _loader  = null;
-    
+
     /**
      * MappingLoader instance for finding user-defined
-     * mappings from a mapping-file
+     * mappings from a mapping-file.
      */
     private XMLMappingLoader _mappingLoader = null;
-    
-    /** 
-     * A flag to indicate the use of introspection
+
+    /**
+     * A flag to indicate the use of introspection.
      */
     private boolean _useIntrospection = true;
-        
-    
+
+
     /**
-     * Creates a new ClassDescriptorResolverImpl
+     * Creates a new ClassDescriptorResolverImpl.
      */
     public XMLClassDescriptorResolverImpl() {
         _classCache = new ClassCache();
@@ -150,7 +147,7 @@
 
         return _introspector;
     } //-- getIntrospector
-    
+
     /**
      * {@inheritDoc}
      *
@@ -159,8 +156,8 @@
     public MappingLoader getMappingLoader() {
         return _mappingLoader;
     } //-- getXMLMappingLoader
-    
- 
+
+
     /**
      * {@inheritDoc}
      *
@@ -198,7 +195,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.exolab.castor.xml.ClassDescriptorResolver#resolve(java.lang.Class)
      */
     public ClassDescriptor resolve(Class type) throws ResolverException {
@@ -207,7 +204,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.exolab.castor.xml.XMLClassDescriptorResolver#resolve(java.lang.String)
      */
     public XMLClassDescriptor resolve(String className) throws ResolverException {
@@ -213,10 +210,10 @@
     public XMLClassDescriptor resolve(String className) throws ResolverException {
         return resolve(className, null);
     } // -- resolve(String)
-    
+
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.exolab.castor.xml.XMLClassDescriptorResolver#resolve(java.lang.String,
      *      java.lang.ClassLoader)
      */
@@ -248,7 +245,7 @@
         _descriptorCache.addMissingDescriptor(className);
         return null;
     } //-- resolve(String, ClassLoader)
-    
+
     /**
      * {@inheritDoc}
      *
@@ -301,8 +298,8 @@
         // get all descriptors with the correct xml name
         return new XCDEnumerator(_descriptorCache.getDescriptors(xmlName));
     } //-- resolveAllByXMLName
-    
-    
+
+
     /**
      * {@inheritDoc}
      *
@@ -311,7 +308,7 @@
     public void setClassLoader(ClassLoader loader) {
         this._loader = loader;
     } //-- setClassLoader
-    
+
     /**
      * Enables or disables introspection. Introspection is
      * enabled by default.
@@ -322,11 +319,11 @@
     public void setIntrospection(boolean enable) {
         _useIntrospection = enable;
     } //-- setIntrospection
-    
+
     /**
      * Sets whether or not to look for and load package specific
      * mapping files (".castor.xml" files).
-     * 
+     *
      * @param loadPackageMappings a boolean that enables or
      * disables the loading of package specific mapping files
      */
@@ -333,7 +330,7 @@
     public void setLoadPackageMappings(boolean loadPackageMappings) {
         _descriptorCache.setLoadPackageMappings(loadPackageMappings);
     } //-- setLoadPackageMappings
-    
+
     /**
      * {@inheritDoc}
      *
@@ -350,7 +347,7 @@
             }
         }
     } //-- setMappingLoader
-    
+
     /**
      * Creates an XMLClassDescriptor for the given type by using introspection.<br>
      * This method will rely on the <code>Introspector</code> set with
@@ -360,7 +357,7 @@
      * <br>
      * <b>NOTE</b>: If this XMLClassDescriptorResolver is NOT configured to use
      * introspection this method will NOT create an descriptor.<br>
-     * 
+     *
      * @param type
      *            The type to create an descriptor for.
      * @return The created XMLClassDescriptor or <code>null</code> if not
@@ -397,7 +394,7 @@
      * <li> If the loader of this XMLClassDescriptor is not <code>null</code>,
      * it is used.
      * <li> The context class loader of the current thread is used. </lu>
-     * 
+     *
      * @param loader The "preferred" <code>ClassLoader</code>.
      * @return The loader to be used.
      */
@@ -420,7 +417,7 @@
      * name <code>className</code> + "Descriptor", and contain a valid
      * XMLClassDescriptor.<br>
      * If a descriptor is found it is added to the internal descriptor cache.
-     * 
+     *
      * @param className
      *            The name of the class to load the descriptor for (This is NOT
      *            the class name of the descriptor!)
@@ -432,7 +429,7 @@
      *         <code>XMLClassDescriptor</code>.
      */
     private XMLClassDescriptor loadDescriptorClass(String className, ClassLoader loader) {
-        String descriptorClassName = className + DESCRIPTOR_SUFFIX;
+        String descriptorClassName = className + XMLConstants.DESCRIPTOR_SUFFIX;
         Class descriptorClass = _classCache.loadClass(descriptorClassName, this.getClassLoader(loader));
         if (descriptorClass == null) {
             return null;
@@ -450,7 +447,7 @@
         return null;
     }
 
-    /** 
+    /**
      * Compares the two strings for equality. A Null and empty
      * strings are considered equal.
      *
@@ -467,10 +464,10 @@
 
         return ns1.equals(ns2);
     } //-- namespaceEquals
-    
+
     /**
      * Gets the XMLClassDescriptor for the class with the given name.<br>
-     * 
+     *
      * The descriptor is searched in the following resources are search: <lu>
      * <li>The internal descriptor cache of this XMLClassDescriptorResolver
      * <li>The MappingLoader of this XMLClassDescriptorResolver
@@ -481,7 +478,7 @@
      * <br>
      * If any of these resources yield an XMLClassDescriptor it is added to the
      * internal cache and returned as result.
-     * 
+     *
      * @param className
      *            The class to get the descriptor for.
      * @param loader
@@ -521,6 +518,15 @@
 
         // try loading the descriptor from .class file
         descriptor = this.loadDescriptorClass(className, loader);
+        if (descriptor == null) {
+            // If we didn't find the descriptor, look in a lower package
+            int offset = className.lastIndexOf(".");
+            if (offset > 0 && !className.endsWith(".")) {
+                String newClassName = className.substring(0, offset+1)
+                        + XMLConstants.DESCRIPTOR_PACKAGE + className.substring(offset);
+                descriptor = this.loadDescriptorClass(newClassName, loader);
+            }
+        }
         if (descriptor != null) {
             return descriptor;
         }
@@ -530,7 +536,7 @@
 
     /**
      * Gets the package name of the given class name.
-     * 
+     *
      * @param className
      *            The class name to retrieve the package name from.
      * @return The package name or the empty String if <code>className</code>
@@ -547,7 +553,7 @@
         }
         return "";
     }
-    
+
 
     /**
      * Internal cache for Class objects.<br>
@@ -554,7 +560,7 @@
      * <br>
      * The cache keeps a list of classes that could not be loaded to prevent
      * loading those classes again.
-     * 
+     *
      * @author <a href="mailto:stevendolg AT gxm DOT at">Steven Dolg</a>
      */
     private class ClassCache {
@@ -571,7 +577,7 @@
          * If the requested class could not be loaded its name is stored in the
          * list of missing classes. Further requests to load such classes will
          * prevent asking the class loader again.
-         * 
+         *
          * @param className
          *            The name of the class to be loaded. This must be a fully
          *            qualified name (i.e. including the package).
@@ -614,10 +620,10 @@
      * mapping files and CDR lists that have been loaded. Just like the
      * ClassCache it also has a list of missing descriptors to avoid trying to
      * load those descriptors again.
-     * 
+     *
      * The cached descriptors are available via the name of the classes they
      * describe or via their XML name from a mapping file.
-     * 
+     *
      * @author <a href="mailto:stevendolg AT gxm DOT at">Steven Dolg</a>
      */
     private class DescriptorCache {
@@ -650,7 +656,7 @@
         private List                _loadedCDRLists;
         /**
          * Flag indicating whether package mappings should be loaded or not.
-         * 
+         *
          * @see XMLClassDescriptorResolverImpl#setLoadPackageMappings(boolean)
          */
         private boolean             _loadPackageMappings    = true;
@@ -673,15 +679,15 @@
         /**
          * Adds a descriptor to this caches maps.<br>
          * The descriptor is mapped both with the class name and its XML name.
-         * 
+         *
          * The descriptor will not be mapped with its XML name is
          * <code>null</code>, the empty string (""), or has the value of the
          * constant INTERNAL_CONTAINER_NAME.
-         * 
+         *
          * If there already is a descriptor for the given <code>className</code>
          * and/or the descriptor's XML name the previously cached descriptor is
          * replaced.
-         * 
+         *
          * @param className
          *            The class name to be used for mapping the given
          *            descriptor.
@@ -687,7 +693,7 @@
          *            descriptor.
          * @param descriptor
          *            The descriptor to be mapped.
-         * 
+         *
          * @see #INTERNAL_CONTAINER_NAME
          */
         private void addDescriptor(String className, XMLClassDescriptor descriptor) {
@@ -713,9 +719,9 @@
         /**
          * Adds the given descriptor to this DescriptorCache.<br>
          * The descriptor will be mapped to its class name and its XML name.
-         * 
+         *
          * @see #addDescriptor(String, XMLClassDescriptor) for details.
-         * 
+         *
          * @param descriptor
          *            The XMLClassDescriptor to be added.
          */
@@ -726,10 +732,10 @@
         /**
          * Adds the given class name to the list of classes a descriptor is
          * unavailable for.
-         * 
+         *
          * @param className
          *            The class name to be added.
-         * 
+         *
          * @see #isMissingDescriptor(String)
          */
         public void addMissingDescriptor(String className) {
@@ -738,7 +744,7 @@
 
         /**
          * Gets the descriptor that is mapped to the given class name.
-         * 
+         *
          * @param className
          *            The class name to get a descriptor for.
          * @return The descriptor mapped to the given name or <code>null</code>
@@ -753,7 +759,7 @@
          * <br>
          * This method will return all previously cached descriptors with the
          * given XML name regardless of their namespace.
-         * 
+         *
          * @param xmlName
          *            The XML name of the descriptors to get.
          * @return A list of descriptors with the given XML name or an empty
@@ -780,7 +786,7 @@
          * NOTE: If an descriptor with the XML name in question is added to this
          * cache, the iterator will fail due to an
          * <code>ConcurrentModificationException</code>
-         * 
+         *
          * @param xmlName
          *            The XML name of the descriptors to get.
          * @return An iterator over descriptors with the given XML name. If no
@@ -788,7 +794,7 @@
          *         the iterator will never return an object (.hasNext() will
          *         immediately return <code>false</code>). This method will
          *         never return <code>null</code>!
-         * 
+         *
          * @see ConcurrentModificationException
          * @see List#iterator()
          */
@@ -805,7 +811,7 @@
          * XMLClassDescriptorResolverImpl found to have no descriptor. The cache
          * itself has no means of determining that this is the case and thus
          * will never add/remove class names to/from it.
-         * 
+         *
          * @param className
          *            The class name to be checked.
          * @return <code>true</code> If the given class name was stated to
@@ -812,7 +818,7 @@
          *         have no descriptor by a previous call to
          *         <code>addMissingDescriptor</code> with exactly the same
          *         class name. <code>false</code> otherwise.
-         * 
+         *
          * @see #addMissingDescriptor(String)
          */
         public boolean isMissingDescriptor(String className) {
@@ -825,17 +831,17 @@
          * <br>
          * If the CDR file is available and could be loaded properly the
          * descriptors listed in it are added to this cache.
-         * 
+         *
          * If a descriptor is listed in the CDR file for the given package but
          * could not be loaded (e.g. because the reference class file is not
          * available) the descriptor is ignored but no exception is thrown.
-         * 
+         *
          * If a CDR file is not available for the given package this method will
          * not load any descriptors and not throw any exceptions.
-         * 
+         *
          * Further calls to this method with the same package name will not be
          * processed.
-         * 
+         *
          * @param packageName
          *            The package to load the CDR file for.
          * @param loader
@@ -891,7 +897,7 @@
          * <br>
          * Further calls to this method with the same package name will not be
          * processed.
-         * 
+         *
          * @param packageName
          *            The name of the package to load the mapping file for.
          * @param loader
@@ -924,7 +930,7 @@
 
         /**
          * Enables or disabled the loading of package mapping files.
-         * 
+         *
          * @param loadPackageMappings
          *            <code>true</code> if package mapping files should be
          *            loaded. <code>false</code> if not.
@@ -938,7 +944,7 @@
          * the given URL.<br>
          * The provided URL must exist and be suitable for loading properties
          * from.
-         * 
+         *
          * @param url
          *            The URL to load the properties from. This must not be
          *            null!
@@ -945,7 +951,7 @@
          * @return The loaded properties.
          * @throws IOException
          *             If loading the properties from the given ULR failed.
-         * 
+         *
          * @see Properties
          * @see Properties#load(InputStream)
          */
@@ -964,7 +970,7 @@
          * <code>packageName</code> and returns the resulting file path.<br>
          * If <code>packageName</code> is <code>null</code> or a zero-length
          * String, this method will return <code>fileName</code>.<br>
-         * 
+         *
          * @param fileName
          *            The file name to be qualified.
          * @param packageName
@@ -986,7 +992,7 @@
         /**
          * Loads a package mapping file for the given package name using the
          * provided ClassLoader.<br>
-         * 
+         *
          * @param packageName
          *            The name of the package to load the mapping file for.
          * @param loader
@@ -1030,7 +1036,7 @@
 
         /**
          * {@inheritDoc}
-         * 
+         *
          * @see org.exolab.castor.xml.ClassDescriptorEnumeration#getNext()
          */
         public XMLClassDescriptor getNext() {
@@ -1039,7 +1045,7 @@
 
         /**
          * {@inheritDoc}
-         * 
+         *
          * @see org.exolab.castor.xml.ClassDescriptorEnumeration#hasNext()
          */
         public boolean hasNext() {
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JCompUnit.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JCompUnit.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JCompUnit.java	(working copy)
@@ -68,7 +68,8 @@
  * learning curve.
  *
  * @author <a href="mailto:shea AT gtsdesign DOT com">Gary Shea</a>
- * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
+ * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar
+ *          2005) $
  */
 public final class JCompUnit {
 
@@ -81,7 +82,7 @@
     /**
      * JavaDoc comment for this compilation unit.
      */
-    private JComment _header = null;
+    private JComment            _header        = null;
 
     /**
      * The package for this JCompUnit.
@@ -86,7 +87,7 @@
     /**
      * The package for this JCompUnit.
      */
-    private String _packageName = null;
+    private String              _packageName   = null;
 
     /**
      * The file to which this JCompUnit will be written.
@@ -91,7 +92,7 @@
     /**
      * The file to which this JCompUnit will be written.
      */
-    private String _fileName = null;
+    private String              _fileName      = null;
 
     /**
      * The set of top-level classes that live in this compilation unit.
@@ -96,7 +97,7 @@
     /**
      * The set of top-level classes that live in this compilation unit.
      */
-    private Vector _classes = null;
+    private Vector              _classes       = null;
 
     /**
      * The set of top-level interfaces that live in this compilation unit.
@@ -101,7 +102,7 @@
     /**
      * The set of top-level interfaces that live in this compilation unit.
      */
-    private Vector _interfaces = null;
+    private Vector              _interfaces    = null;
 
     /**
      * Creates a new JCompUnit.
@@ -106,17 +107,17 @@
     /**
      * Creates a new JCompUnit.
      *
-     * @param packageName the name of the package for this JCompUnit. If
-     *            packageName is null or empty, no 'package' line will be
-     *            generated.
-     * @param fileName the name of the file to which this JCompUnit will be
-     *            written
+     * @param packageName
+     *            the name of the package for this JCompUnit. If packageName is
+     *            null or empty, no 'package' line will be generated.
+     * @param fileName
+     *            the name of the file to which this JCompUnit will be written
      */
     public JCompUnit(final String packageName, final String fileName) {
         this._packageName = packageName;
-        this._fileName    = fileName;
+        this._fileName = fileName;
         init();
-    } //-- JCompUnit
+    } // -- JCompUnit
 
     /**
      * Creates a new JCompUnit with the given JClass (which must have been
@@ -123,7 +124,8 @@
      * created with either a full class name or package/local name) as the
      * public class. Package and file name are taken from jClass.
      *
-     * @param jClass the public class for this JCompUnit
+     * @param jClass
+     *            the public class for this JCompUnit
      */
     public JCompUnit(final JClass jClass) {
         this._packageName = jClass.getPackageName();
@@ -129,21 +131,21 @@
         this._packageName = jClass.getPackageName();
 
         // The outer name is the package plus the simple name of the
-        // outermost enclosing class.  The file name is just the
+        // outermost enclosing class. The file name is just the
         // simple name of the outermost enclosing class, so the
         // package name part must be stripped off.
 
-//      Commented out until inner-class support has been added.
-//      kvisco - 20021211
-//
-//      String outer = jClass.getOuterName();
-//      int lastDot = outer.lastIndexOf(".");
-//      String filePrefix;
-//      if (lastDot != -1) {
-//          filePrefix = outer.substring (lastDot + 1);
-//      } else {
-//          filePrefix = outer;
-//      }
+        // Commented out until inner-class support has been added.
+        // kvisco - 20021211
+        //
+        // String outer = jClass.getOuterName();
+        // int lastDot = outer.lastIndexOf(".");
+        // String filePrefix;
+        // if (lastDot != -1) {
+        // filePrefix = outer.substring (lastDot + 1);
+        // } else {
+        // filePrefix = outer;
+        // }
 
         String filePrefix = jClass.getLocalName();
 
@@ -151,7 +153,7 @@
         init();
         _classes.add(jClass);
 
-    } //-- JCompUnit
+    } // -- JCompUnit
 
     /**
      * Creates a new JCompUnit with the given JInterface as public interface.
@@ -157,14 +159,15 @@
      * Creates a new JCompUnit with the given JInterface as public interface.
      * Package and file name are taken from jInterface.
      *
-     * @param jInterface the public interface for this JCompUnit.
+     * @param jInterface
+     *            the public interface for this JCompUnit.
      */
     public JCompUnit(final JInterface jInterface) {
         this._packageName = jInterface.getPackageName();
-        this._fileName    = jInterface.getLocalName() + ".java";
+        this._fileName = jInterface.getLocalName() + ".java";
         init();
         _interfaces.add(jInterface);
-    } //-- JCompUnit
+    } // -- JCompUnit
 
     /**
      * Common initialization code.
@@ -170,8 +173,8 @@
      * Common initialization code.
      */
     private void init() {
-        _classes          = new Vector();
-        _interfaces       = new Vector();
+        _classes = new Vector();
+        _interfaces = new Vector();
     }
 
     /**
@@ -178,7 +181,8 @@
      * Adds the given JStructure (either a JInterface or a JClass) to this
      * JCompUnit.
      *
-     * @param jStructure the JStructure to add
+     * @param jStructure
+     *            the JStructure to add
      */
     public void addStructure(final JStructure jStructure) {
         if (jStructure instanceof JInterface) {
@@ -187,11 +191,11 @@
             addClass((JClass) jStructure);
         } else {
             String err = "Unknown JStructure subclass '"
-                + jStructure.getClass().getName() + "'.";
+                    + jStructure.getClass().getName() + "'.";
             throw new IllegalArgumentException(err);
         }
 
-    } //-- addStructure
+    } // -- addStructure
 
     /**
      * Adds a JClass to be printed in this file.
@@ -196,11 +200,12 @@
     /**
      * Adds a JClass to be printed in this file.
      *
-     * @param jClass the JClass to be printed in this file
+     * @param jClass
+     *            the JClass to be printed in this file
      */
     public void addClass(final JClass jClass) {
         _classes.add(jClass);
-    } //-- addClass
+    } // -- addClass
 
     /**
      * Adds a JInterface to be printed in this file.
@@ -205,11 +210,12 @@
     /**
      * Adds a JInterface to be printed in this file.
      *
-     * @param jInterface the JInterface to be printed in this file
+     * @param jInterface
+     *            the JInterface to be printed in this file
      */
     public void addInterface(final JInterface jInterface) {
         _interfaces.add(jInterface);
-    } //-- addInterface
+    } // -- addInterface
 
     /**
      * Returns a array of String containing all imported classes/packages, also
@@ -247,13 +253,14 @@
      * given a call to {@link #print(String, String)}, or if destDir is null, a
      * call to {@link #print()}.
      *
-     * @param destDir the destination directory. This may be null.
+     * @param destDir
+     *            the destination directory. This may be null.
      * @return the name of the file that this JCompUnit would be printed to
      */
     public String getFilename(final String destDir) {
-        String filename = new String (_fileName);
+        String filename = new String(_fileName);
 
-        //-- Convert Java package to path string
+        // -- Convert Java package to path string
         String javaPackagePath = "";
         if ((_packageName != null) && (_packageName.length() > 0)) {
             javaPackagePath = _packageName.replace('.', File.separatorChar);
@@ -259,7 +266,7 @@
             javaPackagePath = _packageName.replace('.', File.separatorChar);
         }
 
-        //-- Create fully qualified path (including 'destDir') to file
+        // -- Create fully qualified path (including 'destDir') to file
         File pathFile;
         if (destDir == null) {
             pathFile = new File(javaPackagePath);
@@ -270,7 +277,7 @@
             pathFile.mkdirs();
         }
 
-        //-- Prefix filename with path
+        // -- Prefix filename with path
         if (pathFile.toString().length() > 0) {
             filename = pathFile.toString() + File.separator + filename;
         }
@@ -276,7 +283,7 @@
         }
 
         return filename;
-    } //-- getFilename
+    } // -- getFilename
 
     /**
      * Returns the name of the package that this JCompUnit is a member of.
@@ -286,18 +293,7 @@
      */
     public String getPackageName() {
         return this._packageName;
-    } //-- getPackageName
-
-    /**
-     * Returns the package name of the provided class name.
-     * @param className name from which to extract the package
-     * @return the package name of the provided class name.
-     */
-    protected static String getPackageFromClassName(final String className) {
-        int idx = className.lastIndexOf('.');
-        if (idx > 0) { return className.substring(0, idx); }
-        return null;
-    } //-- getPackageFromClassName
+    } // -- getPackageName
 
     /**
      * Prints the source code for this JClass in the current directory with the
@@ -307,7 +303,7 @@
      */
     public void print() {
         print(null, null);
-    } //-- print
+    } // -- print
 
     /**
      * Prints the source code for this JClass with the default line seperator of
@@ -313,7 +309,8 @@
      * Prints the source code for this JClass with the default line seperator of
      * the the runtime platform.
      *
-     * @param destDir the destination directory to use as the root directory for
+     * @param destDir
+     *            the destination directory to use as the root directory for
      *            source generation
      * @see #print(String, String)
      */
@@ -319,7 +316,7 @@
      */
     public void print(final String destDir) {
         print(destDir, null);
-    } //-- print
+    } // -- print
 
     /**
      * Prints the source code for this JCompUnit using the provided root
@@ -325,14 +322,16 @@
      * Prints the source code for this JCompUnit using the provided root
      * directory and line separator.
      *
-     * @param destDir the destination directory to use as the root directory for
+     * @param destDir
+     *            the destination directory to use as the root directory for
      *            source generation
-     * @param lineSeparator the line separator to use at the end of each line.
-     *            If null, then the default line separator for the runtime
-     *            platform will be used.
+     * @param lineSeparator
+     *            the line separator to use at the end of each line. If null,
+     *            then the default line separator for the runtime platform will
+     *            be used.
      */
     public void print(final String destDir, final String lineSeparator) {
-        //-- open output file
+        // -- open output file
         String filename = getFilename(destDir);
 
         File file = new File(filename);
@@ -340,7 +339,8 @@
         try {
             jsw = new JSourceWriter(new FileWriter(file));
         } catch (java.io.IOException ioe) {
-            System.out.println("unable to create compilation unit file: " + filename);
+            System.out.println("unable to create compilation unit file: "
+                    + filename);
             return;
         }
 
@@ -352,7 +352,7 @@
         print(jsw);
         jsw.flush();
         jsw.close();
-    } //-- print
+    } // -- print
 
     /**
      * Prints the source code for this JClass to the provided JSourceWriter.
@@ -357,7 +357,8 @@
     /**
      * Prints the source code for this JClass to the provided JSourceWriter.
      *
-     * @param jsw the JSourceWriter to print to
+     * @param jsw
+     *            the JSourceWriter to print to
      */
     public void print(final JSourceWriter jsw) {
         // Traverse the nested class and interface heirarchy and
@@ -363,10 +364,10 @@
         // Traverse the nested class and interface heirarchy and
         // update the names to match the compilation unit.
 
-        resolveNames ();
+        resolveNames();
         StringBuffer buffer = new StringBuffer();
 
-        //-- write file header
+        // -- write file header
         if (_header != null) {
             _header.print(jsw);
         } else {
@@ -377,7 +378,7 @@
         jsw.writeln();
         jsw.flush();
 
-        //-- print package name
+        // -- print package name
         if ((_packageName != null) && (_packageName.length() > 0)) {
             buffer.setLength(0);
             buffer.append("package ");
@@ -387,7 +388,7 @@
             jsw.writeln();
         }
 
-        //-- print imports
+        // -- print imports
         jsw.writeln("  //---------------------------------------------/");
         jsw.writeln(" //- Imported classes, interfaces and packages -/");
         jsw.writeln("//---------------------------------------------/");
@@ -396,8 +397,9 @@
         String compUnitPackage = getPackageName();
         for (Iterator iter = allImports.iterator(); iter.hasNext(); ) {
             String importName = (String) iter.next();
-            String importsPackage = JStructure.getPackageFromClassName(importName);
-            if ((importsPackage != null) && !importsPackage.equals(compUnitPackage)) {
+            String importsPackage = JNaming.getPackageFromClassName(importName);
+            if ((importsPackage != null)
+                    && !importsPackage.equals(compUnitPackage)) {
                 jsw.write("import ");
                 jsw.write(importName);
                 jsw.writeln(';');
@@ -414,7 +416,7 @@
         printStructures(jsw, false);
 
         jsw.flush();
-    } //-- print
+    } // -- print
 
     /**
      * Print the source code for the contained JClass objects.
@@ -419,18 +421,21 @@
     /**
      * Print the source code for the contained JClass objects.
      *
-     * @param jsw the JSourceWriter to print to.
-     * @param printPublic if true, print only public classes; if false, print
-     *            only non-public classes.
+     * @param jsw
+     *            the JSourceWriter to print to.
+     * @param printPublic
+     *            if true, print only public classes; if false, print only
+     *            non-public classes.
      */
-    public void printStructures(final JSourceWriter jsw, final boolean printPublic) {
+    public void printStructures(final JSourceWriter jsw,
+            final boolean printPublic) {
 
-        //-- print class information
-        //-- we need to add some JavaDoc API adding comments
+        // -- print class information
+        // -- we need to add some JavaDoc API adding comments
 
         boolean isFirst = true;
 
-        //SortedSet interfaceList = interfaces.sortedOnFullName();
+        // SortedSet interfaceList = interfaces.sortedOnFullName();
         for (Enumeration e = _interfaces.elements(); e.hasMoreElements(); ) {
             JInterface jInterface = (JInterface) e.nextElement();
             if (jInterface.getModifiers().isPublic() == printPublic) {
@@ -443,7 +448,7 @@
             }
         }
 
-        //SortedSet classList = classes.sortedOnFullName();
+        // SortedSet classList = classes.sortedOnFullName();
         for (Enumeration e = _classes.elements(); e.hasMoreElements(); ) {
             JClass jClass = (JClass) e.nextElement();
             if (jClass.getModifiers().isPublic() == printPublic) {
@@ -455,7 +460,7 @@
                 jsw.writeln();
             }
         }
-    } //-- printElements(JSourceWriter, int)
+    } // -- printElements(JSourceWriter, int)
 
     /**
      * Sets the header comment for this JCompUnit.
@@ -460,7 +465,8 @@
     /**
      * Sets the header comment for this JCompUnit.
      *
-     * @param comment the comment to display at the top of the source file when
+     * @param comment
+     *            the comment to display at the top of the source file when
      *            printed
      */
     public void setHeader(final JComment comment) {
@@ -465,11 +471,11 @@
      */
     public void setHeader(final JComment comment) {
         this._header = comment;
-    } //-- setHeader
+    } // -- setHeader
 
-    //-------------------/
-    //- Private Methods -/
-    //-------------------/
+    // -------------------/
+    // - Private Methods -/
+    // -------------------/
 
     /**
      * Update the names of nested classes and interfaces.
@@ -474,60 +480,53 @@
     /**
      * Update the names of nested classes and interfaces.
      */
-    private void resolveNames()  {
-//      Commented out until support for inner-classes is added
-//      kvisco - 20021211
-//
-//      for (int i = 0; i < classes.size(); i++) {
-//          JClass jClass = (JClass) classes.get(i);
-//          jClass.resolveNames(packageName, null);
-//      }
-//      for (int i = 0; i < interfaces.size(); i++) {
-//          JInterface jInterface = (JInterface) interfaces.get(i);
-//          jInterface.resolveNames(packageName, null);
-//      }
-    } //-- resolveNames
+    private void resolveNames() {
+        // Commented out until support for inner-classes is added
+        // kvisco - 20021211
+        //
+        // for (int i = 0; i < classes.size(); i++) {
+        // JClass jClass = (JClass) classes.get(i);
+        // jClass.resolveNames(packageName, null);
+        // }
+        // for (int i = 0; i < interfaces.size(); i++) {
+        // JInterface jInterface = (JInterface) interfaces.get(i);
+        // jInterface.resolveNames(packageName, null);
+        // }
+    } // -- resolveNames
 
     /**
-     * Test drive method...to be removed or commented out
-    **
-    public static void main(String[] args) {
-        JCompUnit unit = new JCompUnit("com.acme", "Test.java");
-
-        JClass testClass = new JClass("Test");
-
-        testClass.addImport("java.util.Vector");
-        testClass.addMember(new JField(JType.Int, "x"));
-
-        JField field = null;
-        field = new JField(JType.Int, "_z");
-        field.getModifiers().setStatic(true);
-        testClass.addField(field);
-
-        testClass.getStaticInitializationCode().add("_z = 75;");
-
-        JClass jcString = new JClass("String");
-        field = new JField(jcString, "myString");
-        field.getModifiers().makePrivate();
-        testClass.addMember(field);
-
-        //-- create constructor
-        JConstructor cons = testClass.createConstructor();
-        testClass.addConstructor(cons);
-        cons.getSourceCode().add("this.x = 6;");
-
-        JMethod jMethod = new JMethod(JType.Int, "getX");
-        jMethod.setSourceCode("return this.x;");
-        testClass.addMethod(jMethod);
-
-        unit.addClass (testClass);
-
-        unit.print();
+     * Test drive method...to be removed or commented out * public static void
+     * main(String[] args) { JCompUnit unit = new JCompUnit("com.acme",
+     * "Test.java");
+     *
+     * JClass testClass = new JClass("Test");
+     *
+     * testClass.addImport("java.util.Vector"); testClass.addMember(new
+     * JField(JType.Int, "x"));
+     *
+     * JField field = null; field = new JField(JType.Int, "_z");
+     * field.getModifiers().setStatic(true); testClass.addField(field);
+     *
+     * testClass.getStaticInitializationCode().add("_z = 75;");
+     *
+     * JClass jcString = new JClass("String"); field = new JField(jcString,
+     * "myString"); field.getModifiers().makePrivate();
+     * testClass.addMember(field);
+     *
+     * //-- create constructor JConstructor cons =
+     * testClass.createConstructor(); testClass.addConstructor(cons);
+     * cons.getSourceCode().add("this.x = 6;");
+     *
+     * JMethod jMethod = new JMethod(JType.Int, "getX");
+     * jMethod.setSourceCode("return this.x;"); testClass.addMethod(jMethod);
+     *
+     * unit.addClass (testClass);
+     *
+     * unit.print();
+     *  } //-- main /*
+     */
 
-    } //-- main
-    /* */
-
-} //-- JCompUnit
+} // -- JCompUnit
 
 /**
  * Print the headers delineating the public and non-public elements of the
@@ -538,11 +537,10 @@
     /**
      * Public header.
      */
-    private static final String[] PUBLIC_HEADER = {
-        "  //-----------------------------/",
-        " //-  Public Class / Interface -/",
-        "//-----------------------------/",
-    };
+    private static final String[] PUBLIC_HEADER     = {
+            "  //-----------------------------/",
+            " //-  Public Class / Interface -/",
+            "//-----------------------------/",    };
 
     /**
      * Private header.
@@ -548,10 +546,9 @@
      * Private header.
      */
     private static final String[] NON_PUBLIC_HEADER = {
-        "  //-------------------------------------/",
-        " //-  Non-Public Classes / Interfaces  -/",
-        "//-------------------------------------/",
-    };
+            "  //-------------------------------------/",
+            " //-  Non-Public Classes / Interfaces  -/",
+            "//-------------------------------------/", };
 
     /**
      * Print the specified header to the given Writer.
@@ -556,11 +553,14 @@
     /**
      * Print the specified header to the given Writer.
      *
-     * @param jsw an open JSourceWriter
-     * @param printPublic if true print the public header, otherwise print the
+     * @param jsw
+     *            an open JSourceWriter
+     * @param printPublic
+     *            if true print the public header, otherwise print the
      *            non-public header.
      */
-    protected static void print (final JSourceWriter jsw, final boolean printPublic) {
+    protected static void print(final JSourceWriter jsw,
+            final boolean printPublic) {
         String[] header = printPublic ? PUBLIC_HEADER : NON_PUBLIC_HEADER;
         for (int j = 0; j < header.length; ++j) {
             jsw.writeln(header[j]);
@@ -575,4 +575,4 @@
         // Nothing to do here
     }
 
-} //-- Header
+} // -- Header
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JNaming.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JNaming.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JNaming.java	(working copy)
@@ -247,6 +247,14 @@
      * Field names used within Castor that prevent a user from using the same
      * name as an element without using a mapping file. Some fields that Castor
      * uses depend on the contents of the schema, so we only warn.
+     * <p>
+     * Reserved:
+     * <pre>
+     * _items -- might be fetched using getXXXXItems where XXX == class name
+     * _content
+     * _choiceValue
+     * _anyObject
+     * </pre>
      */
     private static final String[] CASTOR_RESERVED = {
         "Content",
@@ -411,4 +419,38 @@
         return true;
     } //-- isValidJavaIdentifier
 
+    /**
+     * Returns the package name from the given class name.
+     *
+     * @param className an arbitrary class name, optionally including a package
+     * @return the package name from the given class name.
+     */
+    public static String getPackageFromClassName(final String className) {
+        if (className == null) {
+            return null;
+        }
+        int idx = className.lastIndexOf('.');
+        if (idx > 0) {
+            return className.substring(0, idx);
+        }
+        return null;
+    } //-- getPackageFromClassName
+
+    /**
+     * Returns the local class name from the given fully qualified class name.
+     *
+     * @param className an arbitrary class name, optionally including a package
+     * @return the local name from the given class name.
+     */
+    public static String getLocalNameFromClassName(final String className) {
+        if (className == null) {
+            return null;
+        }
+        int idx = className.lastIndexOf('.');
+        if (idx > 0) {
+            return className.substring(idx + 1);
+        }
+        return className;
+    } //-- getLocalNameFromClassName
+
 } //-- JNaming
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JStructure.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JStructure.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JStructure.java	(working copy)
@@ -137,7 +137,7 @@
             }
             throw new IllegalArgumentException(err);
         }
-        this._packageName = getPackageFromClassName(name);
+        this._packageName = JNaming.getPackageFromClassName(name);
         _imports          = new Vector();
         _interfaces       = new Vector();
         _jdc              = new JDocComment();
@@ -170,7 +170,8 @@
     public abstract void addMember(JMember jMember);
 
     /**
-     * Adds the given import to this JStructure.
+     * Adds the given import to this JStructure.  Note:  You cannot import
+     * from the "default package," so imports with no package are ignored.
      *
      * @param className name of the class to import.
      */
@@ -178,7 +179,7 @@
         if (className == null || className.length() == 0) { return; }
 
         //-- getPackageName
-        String pkgName = getPackageFromClassName(className);
+        String pkgName = JNaming.getPackageFromClassName(className);
 
         if (pkgName != null) {
             if (pkgName.equals(this._packageName) || pkgName.equals("java.lang")) {
@@ -492,8 +493,7 @@
     public final String getName(final boolean stripPackage) {
         String name = super.getName();
         if (stripPackage) {
-            int period = name.lastIndexOf(".");
-            if (period > 0) { name = name.substring(period + 1); }
+            name = JNaming.getLocalNameFromClassName(name);
         }
         return name;
     } //-- getName
@@ -542,10 +542,7 @@
         }
 
         //-- ignore package information, for now
-        int period = name.lastIndexOf(".");
-        if (period > 0) {
-            name = name.substring(period + 1);
-        }
+        name = JNaming.getLocalNameFromClassName(name);
 
         return JNaming.isValidJavaIdentifier(name);
     } //-- isValidClassName
@@ -880,16 +877,4 @@
         jsw.writeln();
     } //-- printlnWithPrefix
 
-    /**
-     * Returns the package name from the given class name.
-     *
-     * @param className an arbitrary class name, optionally including a package
-     * @return the package name from the given class name.
-     */
-    protected static String getPackageFromClassName(final String className) {
-        int idx = className.lastIndexOf('.');
-        if (idx > 0) { return className.substring(0, idx); }
-        return null;
-    } //-- getPackageFromClassName
-
 } //-- JStructure
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JType.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JType.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JType.java	(working copy)
@@ -138,16 +138,7 @@
      */
     public final String getLocalName() {
         // -- use getName method in case it's been overloaded
-        String name = getName();
-
-        if (name == null) {
-            return null;
-        }
-        int idx = name.lastIndexOf('.');
-        if (idx >= 0) {
-            name = name.substring(idx + 1);
-        }
-        return name;
+        return JNaming.getLocalNameFromClassName(getName());
     }
 
     /**
@@ -199,14 +190,14 @@
     }
 
     /**
-     * Change the package this JType belongs to. This method is protected to
+     * Changes the package this JType belongs to. This method is protected to
      * allow subtypes, such as JClass to alter the package to which this JType
      * belongs.
+     * <p>
+     * <B>Note:</B> The package name cannot be changed on a primitive type.
      *
      * @param newPackage
-     *            the new package to which this JType belongs <BR>
-     *            <B>Note:</B> The package name cannot be changed on a
-     *            primitive type.
+     *            the new package to which this JType belongs
      */
     protected final void changePackage(final String newPackage) {
         if (this._name == null || this.isPrimitive()) {
@@ -213,15 +204,9 @@
             return;
         }
 
-        String localName = null;
-        int idx = _name.lastIndexOf('.');
-        if (idx >= 0) {
-            localName = this._name.substring(idx + 1);
-        } else {
-            localName = this._name;
-        }
+        String localName = JNaming.getLocalNameFromClassName(_name);
 
-        if ((newPackage == null) || (newPackage.length() == 0)) {
+        if (newPackage == null || newPackage.length() == 0) {
             this._name = localName;
         } else {
             this._name = newPackage + "." + localName;
Index: /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JTypeName.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JTypeName.java	(revision 6550)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JTypeName.java	(working copy)
@@ -156,14 +156,9 @@
             _localName = null;
             _package   = null;
         } else {
-            _qName = name;
-            _localName = name;
-
-            int idx = name.lastIndexOf('.');
-            if (idx > 0) {
-                _package = name.substring(0, idx);
-                _localName = name.substring(idx + 1);
-            }
+            _qName     = name;
+            _localName = JNaming.getLocalNameFromClassName(name);
+            _package   = JNaming.getPackageFromClassName(name);
         }
     } //-- init
 
