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 6538)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/DescriptorSourceFactory.java	(working copy)
@@ -1,815 +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.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.JavaNaming;
-import org.exolab.javasource.JArrayType;
-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;
-
-    /**
-     * 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;
-    } //-- 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;");
-            createXMLFieldHandler(member, xsType, localClassName, jsc, true);
-            jsc.add("gfh.setFieldHandler(handler);");
-            jsc.add("handler = gfh;");
-            jsc.unindent();
-            jsc.add("}");
-        } else {
-            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
-
-    /**
-     * Creates the XMLFieldHandler for the given FieldInfo.
-     *
-     * @param member
-     *            the member for which to create an XMLFieldHandler
-     * @param xsType the XSType (XML Schema Type) of this field
-     * @param localClassName
-     *            unqualified (no package) name of this class
-     * @param jsc
-     *            the source code to which we'll add this XMLFieldHandler
-     * @param forGeneralizedHandler Whether to generate a generalized field handler
-     */
-    private void createXMLFieldHandler(final FieldInfo member, final XSType xsType,
-                                       final String localClassName, final JSourceCode jsc,
-                                       final boolean forGeneralizedHandler) {
-
-        boolean any          = false;
-        boolean isEnumerated = false;
-
-        //-- a hack, I know, I will change later (kv)
-        if (member.getName().equals("_anyObject")) {
-            any = true;
-        }
-
-        if (xsType.getType() == XSType.CLASS) {
-            isEnumerated = ((XSClass) xsType).isEnumerated();
-        }
-
-        jsc.add("handler = new org.exolab.castor.xml.XMLFieldHandler() {");
-        jsc.indent();
-
-        //-- getValue(Object) method
-        if (_config.useJava50()) {
-            jsc.add("@Override");
-        }
-        jsc.add("public java.lang.Object getValue( java.lang.Object object ) ");
-        jsc.indent();
-        jsc.add("throws IllegalStateException");
-        jsc.unindent();
-        jsc.add("{");
-        jsc.indent();
-        jsc.add(localClassName);
-        jsc.append(" target = (");
-        jsc.append(localClassName);
-        jsc.append(") object;");
-        //-- handle primitives
-        if ((!xsType.isEnumerated()) && xsType.getJType().isPrimitive() && (!member.isMultivalued())) {
-            jsc.add("if(!target." + member.getHasMethodName() + "())");
-            jsc.indent();
-            jsc.add("return null;");
-            jsc.unindent();
-        }
-        //-- Return field value
-        jsc.add("return ");
-        String value = "target." + member.getReadMethodName() + "()";
-        if (member.isMultivalued()) {
-            jsc.append(value); //--Be careful : different for attributes
-        } else {
-            jsc.append(xsType.createToJavaObjectCode(value));
-        }
-        jsc.append(";");
-        jsc.unindent();
-        jsc.add("}");
-        //--end of getValue(Object) method
-
-        boolean isAttribute = (member.getNodeType() == XMLInfo.ATTRIBUTE_TYPE);
-        boolean isContent   = (member.getNodeType() == XMLInfo.TEXT_TYPE);
-
-        //-- setValue(Object, Object) method
-        if (_config.useJava50()) {
-            jsc.add("@Override");
-        }
-        jsc.add("public void setValue( java.lang.Object object, java.lang.Object value) ");
-        jsc.indent();
-        jsc.add("throws IllegalStateException, IllegalArgumentException");
-        jsc.unindent();
-        jsc.add("{");
-        jsc.indent();
-        jsc.add("try {");
-        jsc.indent();
-        jsc.add(localClassName);
-        jsc.append(" target = (");
-        jsc.append(localClassName);
-        jsc.append(") object;");
-        //-- check for null primitives
-        if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
-            if ((!member.isRequired()) && (!xsType.isEnumerated()) && (!member.isMultivalued())) {
-                jsc.add("// if null, use delete method for optional primitives ");
-                jsc.add("if (value == null) {");
-                jsc.indent();
-                jsc.add("target.");
-                jsc.append(member.getDeleteMethodName());
-                jsc.append("();");
-                jsc.add("return;");
-                jsc.unindent();
-                jsc.add("}");
-            } else {
-                jsc.add("// ignore null values for non optional primitives");
-                jsc.add("if (value == null) return;");
-                jsc.add("");
-            }
-        } //if primitive
-
-        jsc.add("target.");
-        jsc.append(member.getWriteMethodName());
-        jsc.append("( ");
-        if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
-            jsc.append(xsType.createFromJavaObjectCode("value"));
-        } else if (any) {
-            jsc.append(" value ");
-        } else {
-            jsc.append("(");
-            jsc.append(xsType.getJType().toString());
-            //special handling for the type package
-            //when we are dealing with attributes
-            //This is a temporary solution since we need to handle
-            //the 'types' in specific handlers in the future
-            //i.e add specific FieldHandler in org.exolab.castor.xml.handlers
-            //dateTime is not concerned by the following since it is directly
-            //handle by DateFieldHandler
-            if ((isAttribute | isContent) && xsType.isDateTime()
-                    && xsType.getType() != XSType.DATETIME_TYPE) {
-                jsc.append(".parse");
-                jsc.append(JavaNaming.toJavaClassName(xsType.getName()));
-                jsc.append("((java.lang.String) value))");
-            } else {
-                jsc.append(") value");
-            }
-        }
-        jsc.append(");");
-
-        jsc.unindent();
-        jsc.add("}");
-        jsc.add("catch (java.lang.Exception ex) {");
-        jsc.indent();
-        jsc.add("throw new IllegalStateException(ex.toString());");
-        jsc.unindent();
-        jsc.add("}");
-        jsc.unindent();
-        jsc.add("}");
-        //--end of setValue(Object, Object) method
-
-        //-- reset method (handle collections only)
-        if (member.isMultivalued()) {
-            CollectionInfo cInfo = (CollectionInfo) member;
-            // FieldInfo content = cInfo.getContent();
-            jsc.add("public void resetValue(Object object) throws IllegalStateException, IllegalArgumentException {");
-            jsc.indent();
-            jsc.add("try {");
-            jsc.indent();
-            jsc.add(localClassName);
-            jsc.append(" target = (");
-            jsc.append(localClassName);
-            jsc.append(") object;");
-            String cName = JavaNaming.toJavaClassName(cInfo.getElementName());
-//            if (cInfo instanceof CollectionInfoJ2) {
-//                jsc.add("target.clear" + cName + "();");
-//            } else {
-                jsc.add("target.removeAll" + cName + "();");
-//            }
-            jsc.unindent();
-            jsc.add("} catch (java.lang.Exception ex) {");
-            jsc.indent();
-            jsc.add("throw new IllegalStateException(ex.toString());");
-            jsc.unindent();
-            jsc.add("}");
-            jsc.unindent();
-            jsc.add("}");
-        }
-        //-- end of reset method
-
-
-        createNewInstanceMethodForXMLFieldHandler(member, xsType, jsc, forGeneralizedHandler,
-                                                  any, isEnumerated);
-        jsc.unindent();
-        jsc.add("};");
-    } //--end of XMLFieldHandler
-
-    /**
-     * Creates the newInstance() method of the corresponsing XMLFieldHandler.
-     * @param member The member element.
-     * @param xsType The XSType instance
-     * @param jsc The source code to which to append the 'newInstance' method.
-     * @param forGeneralizedHandler Whether to generate a generalized field handler
-     * @param any Whether to create a newInstance() method for <xs:any>
-     * @param isEnumerated Whether to create a newInstance() method for an enumeration.
-     */
-    private void createNewInstanceMethodForXMLFieldHandler(
-            final FieldInfo member, final XSType xsType, final JSourceCode jsc,
-            final boolean forGeneralizedHandler, final boolean any,
-            final boolean isEnumerated) {
-        boolean isAbstract = false;
-
-        // Commented out according to CASTOR-1340
-//        if (member.getDeclaringClassInfo() != null) {
-//           isAbstract = member.getDeclaringClassInfo().isAbstract();
-//        }
-
-        // check whether class of member is declared as abstract
-        if (member.getSchemaType() != null && member.getSchemaType().getJType() instanceof JClass) {
-            JClass jClass = (JClass) member.getSchemaType().getJType();
-            isAbstract = jClass.getModifiers().isAbstract();
-        }
-
-        if (!isAbstract && xsType.getJType() instanceof JClass) {
-            JClass jClass = (JClass) xsType.getJType();
-            isAbstract = jClass.getModifiers().isAbstract();
-        }
-
-        if (!isAbstract && member.getSchemaType() instanceof XSList) {
-            XSList xsList = (XSList) member.getSchemaType();
-            if (xsList.getContentType().getJType() instanceof JClass) {
-                JClass componentType = (JClass) xsList.getContentType().getJType();
-                if (componentType.getModifiers().isAbstract()) {
-                    isAbstract = componentType.getModifiers().isAbstract();
-                }
-            }
-        }
-
-        if (_config.useJava50()) {
-            jsc.add("@Override");
-            jsc.add("@SuppressWarnings(\"unused\")");
-        }
-
-        jsc.add("public java.lang.Object newInstance( java.lang.Object parent ) {");
-        jsc.indent();
-        jsc.add("return ");
-
-        if (any || forGeneralizedHandler || isEnumerated
-                || xsType.isPrimitive()
-                || xsType.getJType() instanceof JArrayType
-                || (xsType.getType() == XSType.STRING_TYPE) || isAbstract) {
-            jsc.append("null;");
-        } else {
-            jsc.append(xsType.newInstanceCode());
-        }
-
-        jsc.unindent();
-        jsc.add("}");
-    }
-
-    /**
-     * 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 6538)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SingleClassGenerator.java	(working copy)
@@ -54,7 +54,8 @@
 import java.io.IOException;
 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.util.ConsoleDialog;
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 6538)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/SourceFactory.java	(working copy)
@@ -645,8 +645,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.";
@@ -713,7 +713,7 @@
             comp.setBinding(binding);
         }
         comp.setView(simpleType);
-        
+
         String packageName = comp.getJavaPackage();
         if ((packageName == null) || (packageName.length() == 0)) {
             packageName = sgState._packageName;
@@ -723,13 +723,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;
@@ -1500,8 +1500,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;
@@ -1522,7 +1522,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.
@@ -1530,11 +1530,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();
@@ -1542,7 +1542,7 @@
                         attr.setSimpleType(sType);
                         break;
                     }
-                } 
+                }
 
                 // ... if not, go another step higher in the class hierarchy
                 baseXMLType = baseXMLType.getBaseType();
@@ -1822,8 +1822,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()) {
@@ -1867,7 +1867,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,19 @@
+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";
+
+    /** Descriptors are placed into this special package relative to the generated source. */
+    String DESCRIPTORS_PACKAGE = "descriptors";
+
+    /** This suffix is added to a class name to make its descriptor. */
+    String DESCRIPTORS_SUFFIX = "Descriptor";
+
+}
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 6538)
+++ /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/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 6531)
+++ /home/ekuns/workspace/castor-1/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java	(working copy)
@@ -47,13 +47,18 @@
  *
  * $Id$
  */
-
-package org.exolab.castor.builder;
+package org.exolab.castor.builder.descriptors;
 
+import org.exolab.castor.builder.BuilderConfiguration;
+import org.exolab.castor.builder.ClassInfo;
+import org.exolab.castor.builder.CollectionInfo;
+import org.exolab.castor.builder.FieldInfo;
+import org.exolab.castor.builder.SGTypes;
+import org.exolab.castor.builder.SourceGeneratorConstants;
+import org.exolab.castor.builder.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.JavaNaming;
 import org.exolab.javasource.JArrayType;
 import org.exolab.javasource.JClass;
@@ -60,6 +65,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;
 
@@ -64,7 +70,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) $
@@ -71,22 +77,17 @@
  */
 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;
 
     /**
-     * Creates a new DescriptorSourceFactory with the given configuration
+     * Creates a new DescriptorSourceFactory with the given configuration.
      *
      * @param config the BuilderConfiguration instance
      */
@@ -100,7 +101,7 @@
 
     /**
      * Creates the Source code of a MarshalInfo for a given XML Schema element
-     * declaration
+     * declaration.
      *
      * @param classInfo
      *            the XML Schema element declaration
@@ -107,15 +108,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();
@@ -243,6 +244,27 @@
         return classDesc;
     } //-- createSource
 
+    /**
+     * 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 +  "." + SourceGeneratorConstants.DESCRIPTORS_PACKAGE + ".";
+        } else {
+            descPackage = "";
+        }
+        return descPackage + descClassName + SourceGeneratorConstants.DESCRIPTORS_SUFFIX;
+    }
+
     //-------------------/
     //- Private Methods -/
     //-------------------/
@@ -404,7 +426,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 + "());");
             }
         }
 
@@ -417,6 +440,7 @@
             jsc.append("\");");
         }
 
+        // FIXME:  This next statement does nothing ... why is it here?
         if (any && member.getNamespaceURI() == null) {
             nsURI = null;
         }
@@ -464,7 +488,6 @@
     private void createXMLFieldHandler(final FieldInfo member, final XSType xsType,
                                        final String localClassName, final JSourceCode jsc,
                                        final boolean forGeneralizedHandler) {
-
         boolean any          = false;
         boolean isEnumerated = false;
 
@@ -484,18 +507,12 @@
         if (_config.useJava50()) {
             jsc.add("@Override");
         }
-        jsc.add("public java.lang.Object getValue( java.lang.Object object ) ");
-        jsc.indent();
-        jsc.add("throws IllegalStateException");
-        jsc.unindent();
-        jsc.add("{");
+        jsc.add("public java.lang.Object getValue(java.lang.Object object) "
+                 + "throws IllegalStateException {");
         jsc.indent();
-        jsc.add(localClassName);
-        jsc.append(" target = (");
-        jsc.append(localClassName);
-        jsc.append(") object;");
+        jsc.add(localClassName + " target = (" + localClassName + ") object;");
         //-- handle primitives
-        if ((!xsType.isEnumerated()) && xsType.getJType().isPrimitive() && (!member.isMultivalued())) {
+        if (!xsType.isEnumerated() && xsType.getJType().isPrimitive() && !member.isMultivalued()) {
             jsc.add("if(!target." + member.getHasMethodName() + "())");
             jsc.indent();
             jsc.add("return null;");
@@ -521,18 +538,12 @@
         if (_config.useJava50()) {
             jsc.add("@Override");
         }
-        jsc.add("public void setValue( java.lang.Object object, java.lang.Object value) ");
-        jsc.indent();
-        jsc.add("throws IllegalStateException, IllegalArgumentException");
-        jsc.unindent();
-        jsc.add("{");
+        jsc.add("public void setValue(java.lang.Object object, java.lang.Object value) "
+                + "throws IllegalStateException, IllegalArgumentException {");
         jsc.indent();
         jsc.add("try {");
         jsc.indent();
-        jsc.add(localClassName);
-        jsc.append(" target = (");
-        jsc.append(localClassName);
-        jsc.append(") object;");
+        jsc.add(localClassName + " target = (" + localClassName + ") object;");
         //-- check for null primitives
         if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
             if ((!member.isRequired()) && (!xsType.isEnumerated()) && (!member.isMultivalued())) {
@@ -539,9 +550,7 @@
                 jsc.add("// if null, use delete method for optional primitives ");
                 jsc.add("if (value == null) {");
                 jsc.indent();
-                jsc.add("target.");
-                jsc.append(member.getDeleteMethodName());
-                jsc.append("();");
+                jsc.add("target." + member.getDeleteMethodName() + "();");
                 jsc.add("return;");
                 jsc.unindent();
                 jsc.add("}");
@@ -552,9 +561,7 @@
             }
         } //if primitive
 
-        jsc.add("target.");
-        jsc.append(member.getWriteMethodName());
-        jsc.append("( ");
+        jsc.add("target." + member.getWriteMethodName() + "( ");
         if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
             jsc.append(xsType.createFromJavaObjectCode("value"));
         } else if (any) {
@@ -562,13 +569,11 @@
         } else {
             jsc.append("(");
             jsc.append(xsType.getJType().toString());
-            //special handling for the type package
-            //when we are dealing with attributes
-            //This is a temporary solution since we need to handle
-            //the 'types' in specific handlers in the future
-            //i.e add specific FieldHandler in org.exolab.castor.xml.handlers
-            //dateTime is not concerned by the following since it is directly
-            //handle by DateFieldHandler
+            //special handling for the type package when we are dealing with attributes.
+            //This is a temporary solution since we need to handle the 'types' in specific
+            //handlers in the future.  i.e add specific FieldHandler in
+            //org.exolab.castor.xml.handlers. dateTime is not concerned by the following
+            //since it is directly handle by DateFieldHandler
             if ((isAttribute | isContent) && xsType.isDateTime()
                     && xsType.getType() != XSType.DATETIME_TYPE) {
                 jsc.append(".parse");
@@ -595,14 +600,12 @@
         if (member.isMultivalued()) {
             CollectionInfo cInfo = (CollectionInfo) member;
             // FieldInfo content = cInfo.getContent();
-            jsc.add("public void resetValue(Object object) throws IllegalStateException, IllegalArgumentException {");
+            jsc.add("public void resetValue(Object object) "
+                    + "throws IllegalStateException, IllegalArgumentException {");
             jsc.indent();
             jsc.add("try {");
             jsc.indent();
-            jsc.add(localClassName);
-            jsc.append(" target = (");
-            jsc.append(localClassName);
-            jsc.append(") object;");
+            jsc.add(localClassName + " target = (" + localClassName + ") object;");
             String cName = JavaNaming.toJavaClassName(cInfo.getElementName());
 //            if (cInfo instanceof CollectionInfoJ2) {
 //                jsc.add("target.clear" + cName + "();");
@@ -620,7 +623,6 @@
         }
         //-- end of reset method
 
-
         createNewInstanceMethodForXMLFieldHandler(member, xsType, jsc, forGeneralizedHandler,
                                                   any, isEnumerated);
         jsc.unindent();
@@ -633,7 +635,7 @@
      * @param xsType The XSType instance
      * @param jsc The source code to which to append the 'newInstance' method.
      * @param forGeneralizedHandler Whether to generate a generalized field handler
-     * @param any Whether to create a newInstance() method for <xs:any>
+     * @param any Whether to create a newInstance() method for &lt;xs:any>
      * @param isEnumerated Whether to create a newInstance() method for an enumeration.
      */
     private void createNewInstanceMethodForXMLFieldHandler(

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 6538)
+++ /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/javasource/JCompUnit.java
===================================================================
--- /home/ekuns/workspace/castor-1/src/main/java/org/exolab/javasource/JCompUnit.java	(revision 6538)
+++ /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 6538)
+++ /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 6538)
+++ /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 6538)
+++ /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 6538)
+++ /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
 
