Package org.exolab.javasource

Examples of org.exolab.javasource.JMethod


     * Adds the methods we override from.
     * {@link org.exolab.castor.xml.util.XMLClassDescriptorImpl}
     */
    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


    /**
     * 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

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

    /**
     * {@inheritDoc}
     */
    protected final void createEnumerateMethod(final CollectionInfo fieldInfo,
            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

    /**
     * {@inheritDoc}
     */
    protected final void createAddMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod(fieldInfo.getWriteMethodName());
        method.addException(SGTypes.INDEX_OUT_OF_BOUNDS_EXCEPTION,
                            "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()));
View Full Code Here

         * @param jType the type of this field
         * @return the getter method for this identity
         */
        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

         * @param jType the type of this field
         * @return the setter method for this identity
         */
        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(";");
View Full Code Here

         * Creates the getReferenceId method.
         * @param fieldInfo the fieldInfo to translate
         * @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

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    protected void createAddMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod(fieldInfo.getWriteMethodName());
        method.addException(SGTypes.INDEX_OUT_OF_BOUNDS_EXCEPTION,
                "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(".addElement(");
        sourceCode.append(fieldInfo.getContentType().createToJavaObjectCode(parameter.getName()));
View Full Code Here

     * @param jClass the jClass to add the method to.
     * @param useJava50 java version flag
     */
    protected void createEnumerateMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("enumerate" + fieldInfo.getMethodSuffix(),
                SGTypes.createEnumeration(fieldInfo.getContentType().getJType(), useJava50, true),
                "an Enumeration over all " + fieldInfo.getContentType().getJType() + " elements");

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("return this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".elements();");

        jClass.addMethod(method);
View Full Code Here

TOP

Related Classes of org.exolab.javasource.JMethod

Copyright © 2018 www.massapicom. 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.