Package org.exolab.javasource

Examples of org.exolab.javasource.JType


     * @param fieldInfo the fieldInfo to translate
     * @return the created methods
     */
    public JMethod[] createAccessMethods(final FieldInfo fieldInfo) {
            String mname = fieldInfo.getMethodSuffix();
            JType jType = new XMLInfoNature(fieldInfo).getSchemaType().getJType();

            JMethod[] methods = new JMethod[3];
            methods[0] = makeGetMethod(fieldInfo, mname, jType); // -- create get method
            methods[1] = makeSetMethod(fieldInfo, mname, jType); // -- create set method
            methods[2] = makeGetReferenceIdMethod(fieldInfo); // -- create getReferenceId
View Full Code Here


            final JSourceCode sourceCode) {
        CollectionInfo collectionInfo = (CollectionInfo) fieldInfo;
        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(" = new ");
        JType jType = collectionInfo.getXSList().getJType();
        sourceCode.append(((JCollectionType) jType).getInstanceName());
        sourceCode.append("();");
    } // -- generateConstructorCode
View Full Code Here

     * @param annotationBuilders the custom builders
     */
    private void createGetAsArrayMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50,
            AnnotationBuilder[] annotationBuilders) {
        JType baseType = fieldInfo.getContentType().getJType();
        JType arrayType = new JArrayType(baseType, useJava50);
        JMethod method = new JMethod(fieldInfo.getReadMethodName(), arrayType,
                                     "this collection as an Array");

        JSourceCode sourceCode = method.getSourceCode();

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Returns the contents of the collection in an Array.  ");

        if (!(baseType.isPrimitive())) {
            // For non-primitive types, we use the API method made for this purpose
            comment.appendComment("<p>");
            comment.appendComment("Note:  Just in case the collection contents are changing in ");
            comment.appendComment("another thread, we pass a 0-length Array of the correct type ");
            comment.appendComment("into the API call.  This way we <i>know</i> that the Array ");
            comment.appendComment("returned is of exactly the correct length.");

            String baseTypeName = baseType.toString();
            if (baseType.isArray()) {
                sourceCode.add(arrayType.toString() + " array = new ");
                sourceCode.append(baseTypeName.substring(0, baseTypeName.length() - 2) + "[0][];");
            } else {
                sourceCode.add(arrayType.toString() + " array = new ");
                sourceCode.append(baseTypeName + "[0];");
            }
            sourceCode.add("return (" + arrayType.toString() + ") ");
            sourceCode.append("this." + fieldInfo.getName() + ".toArray(array);");
        } else {
            // For primitive types, we have to do this the hard way
            sourceCode.add("int size = this.");
            sourceCode.append(fieldInfo.getName());
            sourceCode.append(".size();");

            sourceCode.add(arrayType.toString());
            sourceCode.append(" array = new ");
            // the first brackets must contain the size...
            int brackets = arrayType.toString().indexOf("[]");
            sourceCode.append(arrayType.toString().substring(0, brackets));
            sourceCode.append("[size]");
            sourceCode.append(";");
            sourceCode.add("java.util.Iterator iter = " + fieldInfo.getName() + ".iterator();");

            String value = "iter.next()";
            sourceCode.add("for (int index = 0; index < size; index++) {");
            sourceCode.indent();
            sourceCode.add("array[index] = ");
            if (fieldInfo.getContentType().getType() == XSType.CLASS) {
                sourceCode.append("(");
                sourceCode.append(arrayType.getName());
                sourceCode.append(") ");
                sourceCode.append(value);
            } else {
                sourceCode.append(fieldInfo.getContentType().createFromJavaObjectCode(value));
            }
View Full Code Here

     */
    private void createSetAsReferenceMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("set" + fieldInfo.getMethodSuffix()
                + fieldInfo.getReferenceSuffix());
        final JType collectionJType = new XMLInfoNature(fieldInfo).getSchemaType().getJType();
        JParameter parameter = new JParameter(
                collectionJType, fieldInfo.getParameterPrefix() + collectionJType.getLocalName());
        method.addParameter(parameter);

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Sets the value of '");
View Full Code Here

                    buffer.append(character);
                }
            }
            value = buffer.toString();
        } else if (enumeration) {
            JType jType = (classInfo != null) ? classInfo.getJClass() : xsType.getJType();
            if (getSourceGenerator().useJava5Enums()) {
                value = jType.getName() + ".fromValue(\"" + value + "\")";
            } else {
                value = jType.getName() + ".valueOf(\"" + value + "\")";   
            }
        } else if (xsType.getJType().isArray()) {
            JType componentType = ((JArrayType) xsType.getJType()).getComponentType();
            if (componentType.isPrimitive()) {
                JPrimitiveType primitive = (JPrimitiveType) componentType;
                value = "new " + primitive.getName() + "[] { "
                      + primitive.getWrapperName() + ".valueOf(\"" + value
                      + "\")." + primitive.getName() + "Value() }";
            } else {
                value = "new " + componentType.getName() + "[] { "
                      + componentType.getName() + ".valueOf(\"" + value + "\") }";
               
            }
        } else if (!(xsType.getJType().isPrimitive())) {
            if (xsType.isDateTime()) {
                // Castor marshals DATETIME_TYPE into java.util.Date(), so we need to convert it
View Full Code Here

     *
     * @return true if the has and delete methods are needed.
     */
    public final boolean requiresHasAndDeleteMethods() {
        XSType xsType = new XMLInfoNature(this).getSchemaType();
        JType jType  = xsType.getJType();
        return ((!xsType.isEnumerated()) && jType.isPrimitive());
    } //-- requiresHasAndDeleteMethods
View Full Code Here

       //-- set typeInfo
       String type = null;
       XSType schemaType;
      
       schemaType = xmlNature.getSchemaType();
       JType javaType = schemaType.getJType();
       type = javaType.toString();
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
           wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
           wrapperType = type;
View Full Code Here

       //-- set typeInfo
       String type = null;
       XSType schemaType;
      
       schemaType = xmlNature.getSchemaType();
       JType javaType = schemaType.getJType();
       type = javaType.toString();
      
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
        wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
View Full Code Here

       //-- set typeInfo
       String type = null;
       XSList schemaType;
      
       schemaType = (XSList) xmlNature.getSchemaType();
       JType javaType = schemaType.getContentType().getJType();
       type = javaType.toString();
      
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
        wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
View Full Code Here

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

TOP

Related Classes of org.exolab.javasource.JType

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.