Package org.exolab.javasource

Examples of org.exolab.javasource.JMethod


     * @param jClass The enumeration class to create this method for.
     * @param className The name of the class.
     */
    private void createEnumerateMethod(final JClass jClass, final String className) {
        // TODO for the time being return Enumeration<Object> for Java 5.0; change
        JMethod mEnumerate = new JMethod("enumerate",
                SGTypes.createEnumeration(SGTypes.OBJECT, getConfig().useJava50(), true),
                "an Enumeration over all possible instances of " + className);
        mEnumerate.getModifiers().setStatic(true);
        jClass.addMethod(mEnumerate);
        JDocComment jdc = mEnumerate.getJDocComment();
        jdc.appendComment("Returns an enumeration of all possible instances of ");
        jdc.appendComment(className);
        mEnumerate.getSourceCode().add("return _memberTable.elements();");
    }
View Full Code Here


     * Creates 'valueOf(String)' method for this enumeration class.
     * @param jClass The enumeration class to create this method for.
     * @param className The name of the class.
     */
    private void createValueOfMethod(final JClass jClass, final String className) {
        JMethod mValueOf = new JMethod(
                "valueOf", jClass, "the " + className + " value of parameter 'string'");
        mValueOf.addParameter(new JParameter(SGTypes.STRING, "string"));
        mValueOf.getModifiers().setStatic(true);
        jClass.addMethod(mValueOf);

        JDocComment jdc = mValueOf.getJDocComment();
        jdc.appendComment("Returns a new " + className);
        jdc.appendComment(" based on the given String value.");

        JSourceCode jsc = mValueOf.getSourceCode();
        jsc.add("java.lang.Object obj = null;\n"
              + "if (string != null) {\n"
              + " obj = _memberTable.get(string{1});\n"
              + "}\n"
              + "if (obj == null) {\n"
View Full Code Here

        fValues.setInitString(values.toString());
        jClass.addField(fValues);

        //-- #valueOf method
        JMethod method = new JMethod("valueOf", jClass,
                                     "the String value of the provided " + baseType.getJType());
        method.addParameter(new JParameter(SGTypes.STRING, "string"));
        method.getModifiers().setStatic(true);
        jClass.addMethod(method);
        jdc = method.getJDocComment();
        jdc.appendComment("Returns the " + baseType.getJType());
        jdc.appendComment(" based on the given String value.");
        jsc = method.getSourceCode();

        jsc.add("for (int i = 0; i < values.length; i++) {");
        jsc.add("}");
        jsc.add("throw new IllegalArgumentException(\"");
        jsc.append("Invalid value for ");
View Full Code Here

    /**
     * {@inheritDoc}
     */
    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 elements of this collection");

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("java.util.Vector v = new java.util.Vector();"); // ODMG 3.0
        sourceCode.add("java.util.Iterator i = ");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".iterator();");
        sourceCode.add("");
View Full Code Here

     * @param useJava50
     *            true if source code is supposed to be generated for Java 5
     */
    private void createGetterMethod(final FieldInfo fieldInfo,
            final JClass jClass, final boolean useJava50, AnnotationBuilder[] annotationBuilders) {
        JMethod method    = null;
        JSourceCode jsc   = null;

        String mname = fieldInfo.getMethodSuffix();

        XSType xsType = new XMLInfoNature(fieldInfo).getSchemaType();
        JType jType  = xsType.getJType();

        //-- create get method
        method = new JMethod(fieldInfo.getReadMethodName(), jType,
                             "the value of field '" + mname + "'.");
//        if (useJava50) {
//            Java5HacksHelper.addOverrideAnnotations(method.getSignature());
//        }
       
        for (int i = 0; i < annotationBuilders.length; i++) {
            AnnotationBuilder annotationBuilder = annotationBuilders[i];
            annotationBuilder.addFieldGetterAnnotations(fieldInfo, method);
        }
       
        jClass.addMethod(method);
        createGetterComment(fieldInfo, method.getJDocComment());
        jsc = method.getSourceCode();
        jsc.add("return this.");
        jsc.append(fieldInfo.getName());
        jsc.append(";");

        if (xsType.getType() == XSType.BOOLEAN_TYPE) {

            // -- create is<Property>t method
            method = new JMethod(fieldInfo.getIsMethodName(), jType,
                    "the value of field '" + mname + "'.");
//            if (useJava50) {
//                Java5HacksHelper.addOverrideAnnotations(method.getSignature());
//            }
            jClass.addMethod(method);
            createGetterComment(fieldInfo, method.getJDocComment());
            jsc = method.getSourceCode();
            jsc.add("return this.");
            jsc.append(fieldInfo.getName());
            jsc.append(";");

        }
View Full Code Here

     * @param fieldInfo the fieldInfo to translate
     * @param jClass the JClass to add the methods to
     */
    private void createHasAndDeleteMethods(final FieldInfo fieldInfo,
            final JClass jClass) {
        JMethod method    = null;
        JSourceCode jsc   = null;

        String mname = fieldInfo.getMethodSuffix();

        XSType xsType = new XMLInfoNature(fieldInfo).getSchemaType();
        xsType.getJType();

        //-- create hasMethod
        method = new JMethod(fieldInfo.getHasMethodName(), JType.BOOLEAN,
                             "true if at least one " + mname + " has been added");
        jClass.addMethod(method);
        jsc = method.getSourceCode();
        jsc.add("return this._has");
        String fieldName = fieldInfo.getName();
        jsc.append(fieldName);
        jsc.append(";");

        //-- create delete method
        method = new JMethod(fieldInfo.getDeleteMethodName());
        jClass.addMethod(method);
        jsc = method.getSourceCode();
        jsc.add("this._has");
        jsc.append(fieldName);
        jsc.append("= false;");
        //-- bound properties
        if (fieldInfo.isBound()) {
View Full Code Here

     * @param jClass the JClass to add the methods to
     * @param useJava50 true if source code is supposed to be generated for Java 5
     */
     private void createSetterMethod(final FieldInfo fieldInfo,
             final JClass jClass, final boolean useJava50) {
        JMethod method    = null;
        JSourceCode jsc   = null;

        XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
       
        String mname  = fieldInfo.getMethodSuffix();
        XSType xsType = xmlNature.getSchemaType();
        JType jType   = xsType.getJType();

        //-- create set method
        /*
         * fieldInfo.getWriteMethodName() will either prefix the method
         * with 'add' (for multivalued fields) or 'set'!
         * @see FieldInfo#getWriteMethodeName()
         */
        method = new JMethod(fieldInfo.getWriteMethodName());
        jClass.addMethod(method);

        String paramName = fieldInfo.getName();

        //-- make parameter name pretty,
        //-- simply for aesthetic beauty
        if (paramName.indexOf('_') == 0) {
            String tempName = paramName.substring(1);
            if (_javaNaming.isValidJavaIdentifier(tempName)) {
                paramName = tempName;
            }
        }

        method.addParameter(new JParameter(jType, paramName));
//        if (useJava50) {
//            Java5HacksHelper.addOverrideAnnotations(method.getSignature()); // DAB Java 5.0 hack
//        }
        createSetterComment(fieldInfo, method.getJDocComment());
        jsc = method.getSourceCode();

        String fieldName = fieldInfo.getName();
        //-- bound properties
        if (fieldInfo.isBound()) {
            // save old value
View Full Code Here

                        +  documentation.getSource() + "\", \""
                        + documentationContent + "\");");
            }
        }

        JMethod aMethod = new JMethod("getXmlSchemaDocumentations",
                new JClass("java.util.Map"),
        " A collection of documentation elements.");
        JSourceCode sourceCode = aMethod.getSourceCode();
        sourceCode.add("return _xmlSchemaDocumentations;");
        jClass.addMethod(aMethod);

        JMethod anotherMethod = new JMethod("getXmlSchemaDocumentation",
                new JClass("java.lang.String"),
                    " A specific XML schema documentation element.");
        JParameter parameter = new JParameter(new JClass("java.lang.String"), "source");
        anotherMethod.addParameter(parameter);
        sourceCode = anotherMethod.getSourceCode();
        sourceCode.add("return (java.lang.String) _xmlSchemaDocumentations.get(source);");
        jClass.addMethod(anotherMethod);
    }
View Full Code Here

        jClass.addInterface("org.exolab.castor.jdo.TimeStampable");
       
        JField jdoTimestamp = new JField(JType.LONG, "_jdoTimeStamp");
        jClass.addField(jdoTimestamp);
       
        JMethod getTSMethod = new JMethod("jdoGetTimeStamp", JType.LONG,
                 "returns the current time stamp");
        JSourceCode getSourceCode = getTSMethod.getSourceCode();
        getSourceCode.addIndented("return _jdoTimeStamp;");
        jClass.addMethod(getTSMethod);

        JMethod setTSMethod = new JMethod("jdoSetTimeStamp");
        JParameter parameter = new JParameter(JType.LONG, "jdoTimeStamp");
        setTSMethod.addParameter(parameter);
        JSourceCode setSourceCode = setTSMethod.getSourceCode();
        setSourceCode.addIndented("this._jdoTimeStamp = jdoTimeStamp;");
        jClass.addMethod(setTSMethod);
     }
View Full Code Here

        //---------------------------------/
        //- notifyPropertyChangeListeners -/
        //---------------------------------/

        JMethod jMethod = new JMethod("notifyPropertyChangeListeners");
        jMethod.getModifiers().makeProtected();

        JDocComment jdc = jMethod.getJDocComment();
        JDocDescriptor jdDesc = null;
        String desc = null;

        desc = "Notifies all registered PropertyChangeListeners "
             + "when a bound property's value changes.";
        jdc.appendComment(desc);

        jMethod.addParameter(new JParameter(SGTypes.STRING, "fieldName"));
        jdDesc = jdc.getParamDescriptor("fieldName");
        jdDesc.setDescription("the name of the property that has changed.");

        jMethod.addParameter(new JParameter(SGTypes.OBJECT, "oldValue"));
        jdDesc = jdc.getParamDescriptor("oldValue");
        jdDesc.setDescription("the old value of the property.");

        jMethod.addParameter(new JParameter(SGTypes.OBJECT, "newValue"));
        jdDesc = jdc.getParamDescriptor("newValue");
        jdDesc.setDescription("the new value of the property.");

        parent.addMethod(jMethod);
        JSourceCode jsc = jMethod.getSourceCode();
        //--fix for bug 1026
        jsc.add("if (");
        jsc.append(vName);
        jsc.append(" == null) return;");

        jsc.add(vName);
        jsc.append(".firePropertyChange(fieldName,oldValue,newValue);");

        //-----------------------------/
        //- addPropertyChangeListener -/
        //-----------------------------/

        JType jType = new JClass("java.beans.PropertyChangeListener");
        jMethod = new JMethod("addPropertyChangeListener");

        desc = "Registers a PropertyChangeListener with this class.";
        jdc = jMethod.getJDocComment();
        jdc.appendComment(desc);

        jMethod.addParameter(new JParameter(jType, "pcl"));
        desc = "The PropertyChangeListener to register.";
        jdDesc = jdc.getParamDescriptor("pcl");
        jdDesc.setDescription(desc);

        parent.addMethod(jMethod);

        jsc = jMethod.getSourceCode();

        jsc.add("if (");
        jsc.append(vName);
        jsc.append(" == null) {");
        jsc.addIndented(vName + " = new java.beans.PropertyChangeSupport(this);");
        jsc.add("}");
        jsc.add(vName);
        jsc.append(".addPropertyChangeListener(pcl);");

        //--------------------------------/
        //- removePropertyChangeListener -/
        //--------------------------------/

        jMethod = new JMethod("removePropertyChangeListener", JType.BOOLEAN,
                              "always returns true if pcl != null");

        desc = "Removes the given PropertyChangeListener "
             + "from this classes list of ProperyChangeListeners.";
        jdc = jMethod.getJDocComment();
        jdc.appendComment(desc);

        jMethod.addParameter(new JParameter(jType, "pcl"));
        desc = "The PropertyChangeListener to remove.";
        jdDesc = jdc.getParamDescriptor("pcl");
        jdDesc.setDescription(desc);

        parent.addMethod(jMethod);

        jsc = jMethod.getSourceCode();
        jsc.add("if (");
        jsc.append(vName);
        jsc.append(" == null) return false;");

        jsc.add(vName);
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.