Examples of JSourceCode


Examples of org.exolab.javasource.JSourceCode

        String descriptorClassName = getQualifiedDescriptorClassName(jClass.getName());
        DescriptorJClass classDesc = new DescriptorJClass(_config, descriptorClassName, jClass);

        //-- get handle to default constuctor
        JConstructor cons = classDesc.getConstructor(0);
        JSourceCode jsc   = cons.getSourceCode();
        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);

        //-- Set namespace prefix
        String nsPrefix = xmlNature.getNamespacePrefix();
        if ((nsPrefix != null) && (nsPrefix.length() > 0)) {
            jsc.add("_nsPrefix = \"");
            jsc.append(nsPrefix);
            jsc.append("\";");
        }

        //-- Set namespace URI
        String nsURI = xmlNature.getNamespaceURI();
        if ((nsURI != null) && (nsURI.length() > 0)) {
            jsc.add("_nsURI = \"");
            jsc.append(nsURI);
            jsc.append("\";");
        }

        //-- set XML Name
        String xmlName = xmlNature.getNodeName();
        if (xmlName != null) {
            jsc.add("_xmlName = \"");
            jsc.append(xmlName);
            jsc.append("\";");
        }

        //-- set Element Definition flag
        boolean elementDefinition = xmlNature.isElementDefinition();
        jsc.add("_elementDefinition = ");
        jsc.append(new Boolean(elementDefinition).toString());
        jsc.append(";");
       
        //-- set grouping compositor
        if (xmlNature.isChoice()) {
            jsc.add("");
            jsc.add("//-- set grouping compositor");
            jsc.add("setCompositorAsChoice();");
        } else if (xmlNature.isSequence()) {
            jsc.add("");
            jsc.add("//-- set grouping compositor");
            jsc.add("setCompositorAsSequence();");
        }
       
        // handle substitution groups
        List<String> substitutionGroups = xmlNature.getSubstitutionGroups();
        if (!substitutionGroups.isEmpty()) {
            jsc.add("java.util.List substitutionGroups = new java.util.ArrayList();");
            Iterator<String> substitutionGroupIter = substitutionGroups.iterator();
            while (substitutionGroupIter.hasNext()) {
                String substitutionGroup = substitutionGroupIter.next();
                jsc.add("substitutionGroups.add(\"");
                jsc.append(substitutionGroup);
                jsc.append("\");");
            }
            jsc.add("setSubstitutes(substitutionGroups);");
        }
               
        //-- 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 = new XMLInfoNature(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()) {
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

     * @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("());");
        }
    }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

    private void addXMLClassDescriptorImplOverrides() {
        //-- create isElementDefinition method
        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);
    }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

     * 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 marshaling as XML.");

        if (_config.useJava50()) {
            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
        }

        jsc = method.getSourceCode();
        jsc.add("return _nsPrefix;");
        addMethod(method);

        //-- create getNameSpaceURI method
        method = new JMethod("getNameSpaceURI", SGTypes.STRING,
                             "the namespace URI used when marshaling and unmarshaling as XML.");

        if (_config.useJava50()) {
            method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
        }

        jsc = method.getSourceCode();
        jsc.add("return _nsURI;");
        addMethod(method);

        //-- create getValidator method
        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")));
        }

        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);
    }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

     * 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(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")));
        }

        jsc = getAccessMode.getSourceCode();
        jsc.add("return null;");
        addMethod(getAccessMode);

        //-- create getIdentity method
        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")));
        }

        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
        JMethod 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);
    }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("enumerate" + fieldInfo.getMethodSuffix(),
                SGTypes.createEnumeration(fieldInfo.getContentType().getJType(), useJava50, true),
                "an Enumeration over all possible elements of this collection");

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("return java.util.Collections.enumeration(this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(");");

        jClass.addMethod(method);
    }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

                            "if the index given is outside the bounds of the collection");
        final JParameter parameter = new JParameter(fieldInfo.getContentType().getJType(),
                fieldInfo.getContentName());
        method.addParameter(parameter);

        JSourceCode sourceCode = method.getSourceCode();
        this.addMaxSizeCheck(fieldInfo, method.getName(), sourceCode);

        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".add(");
        sourceCode.append(fieldInfo.getContentType().createToJavaObjectCode(parameter.getName()));
        sourceCode.append(");");

        if (fieldInfo.isBound()) {
            this.createBoundPropertyCode(fieldInfo, sourceCode);
        }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

         */
        private JMethod makeGetMethod(final FieldInfo fieldInfo,
                final String mname, final JType jType) {
            JMethod method = new JMethod("get" + mname, jType,
                    "the value of field '" + mname + "'.");
            JSourceCode jsc = method.getSourceCode();
            jsc.add("return this.");
            jsc.append(fieldInfo.getName());
            jsc.append(";");
            return method;
        }
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

         */
        private JMethod makeSetMethod(final FieldInfo fieldInfo,
                final String mname, final JType jType) {
            JMethod method = new JMethod("set" + mname);
            method.addParameter(new JParameter(jType, fieldInfo.getName()));
            JSourceCode jsc = method.getSourceCode();
            jsc.add("this.");
            jsc.append(fieldInfo.getName());
            jsc.append(" = ");
            jsc.append(fieldInfo.getName());
            jsc.append(";");

            //-- add resolver registration
            //jsc.add("if (idResolver != null) ");
            //jsc.indent();
            //jsc.add("idResolver.addResolvable(");
View Full Code Here

Examples of org.exolab.javasource.JSourceCode

         * @return the getReferenceId method.
         */
        private JMethod makeGetReferenceIdMethod(final FieldInfo fieldInfo) {
            JMethod method = new JMethod("getReferenceId", SGTypes.STRING,
                    "the reference ID");
            JSourceCode jsc = method.getSourceCode();
            jsc.add("return this.");
            jsc.append(fieldInfo.getName());
            jsc.append(";");
            return method;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.