Package org.exolab.javasource

Examples of org.exolab.javasource.JClass


     *            for
     */
    private void generateExtraDocumentationMethods(final Annotated annotated,
            final JClass jClass) {
        JField documentationsField =
            new JField(new JClass("java.util.Map"), "_xmlSchemaDocumentations");
        documentationsField.setComment("The content of the <xsd:documentation> elements");
        documentationsField.setInitString("new java.util.HashMap()");
        jClass.addMember(documentationsField);

        Enumeration<Annotation> annotations = annotated.getAnnotations();
        while (annotations.hasMoreElements()) {
            Annotation annotation = annotations.nextElement();
            Enumeration<Documentation> documentations = annotation.getDocumentation();
            while (documentations.hasMoreElements()) {
                Documentation documentation = documentations.nextElement();
                JConstructor defaultConstructor = jClass.getConstructor(0);
                String documentationContent = normalize(documentation.getContent());
                documentationContent =
                    StringUtil.replaceAll(documentationContent, "\n", "\"\n+ \" ");
                defaultConstructor.getSourceCode().add("_xmlSchemaDocumentations.put(\""
                        +  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


            create = tns.equals(component.getTargetNamespace());
        }

        if (create) {
            ClassInfo tmpInfo = sgState.resolve(simpleType);
            JClass tmpClass = null;
            if (tmpInfo != null) {
                tmpClass = tmpInfo.getJClass();
            } else {
                tmpClass = createSourceCode(component.getBinding(), simpleType, sgState);
            }
View Full Code Here

    private void processComplexType(final XMLBindingComponent component, final SGStateInfo sgState,
                                    final FactoryState state) {
        XMLType   type      = component.getXMLType();
        ClassInfo classInfo = state.getClassInfo();
        JClass    jClass    = state.getJClass();
        boolean creatingForAnElement =
            (component.getAnnotated().getStructureType() == Structure.ELEMENT);

        ComplexType complexType = (ComplexType) type;
        if (complexType.isTopLevel() && creatingForAnElement) {
             //--move the view and keep the structure
             Annotated saved = component.getAnnotated();
             String previousPackage = component.getJavaPackage();
             XMLBindingComponent baseComponent = new XMLBindingComponent(
                     getConfig(), getGroupNaming());
             baseComponent.setBinding(component.getBinding());
             baseComponent.setView(complexType);
             //-- call createSourceCode to pre-process the complexType
             createSourceCode(baseComponent, sgState);
             String baseClassName = null;
             String basePackage = baseComponent.getJavaPackage();
             //--if the base class is not in the same package
             //--of the current class then we have to qualify the base
             //--class
             if (basePackage != null && !basePackage.equals(previousPackage)) {
                 baseClassName = baseComponent.getQualifiedName();
                 if (baseClassName.indexOf('.') == -1) {
                     //--be sure it is a valid className
                     baseClassName = getJavaNaming().toJavaClassName(baseClassName);
                 }
             } else {
                 baseClassName = baseComponent.getJavaClassName();
             }
             jClass.setSuperClass(baseClassName);
             basePackage = null;
             baseClassName = null;
             component.setView(saved);
             saved = null;
        } else if (complexType.isTopLevel() || creatingForAnElement) {
View Full Code Here

                (enumeration && getConfig().useJava5Enums()));

        state.setParent(sgState.getCurrentFactoryState());

        ClassInfo classInfo = state.getClassInfo();
        JClass    jClass    = state.getJClass();

        initialize(jClass);

        //-- XML information
        Schema  schema = simpleType.getSchema();
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

        //-- create helper marshal method
        //-- start helper marshal method, this method will
        //-- be built up as we process the given ElementDecl
        jMethod = new JMethod("marshal");
        JClass jc = null;
        if (_sax1) {
            jc = new JClass("org.xml.sax.DocumentHandler");
        } else {
            jc = new JClass("org.xml.sax.ContentHandler");
            jMethod.addException(SGTypes.IO_EXCEPTION,
                    "if an IOException occurs during marshaling");
        }
        jMethod.addException(SGTypes.MARSHAL_EXCEPTION,
                "if object is null or if any SAXException is thrown during marshaling");
View Full Code Here

        //-- create main unmarshal method

        //-- search for proper base class
        // TODO[WG]: java 5.0 allows different types for unmarshal method in extension hierarchy
        JClass returnType;
        if (!getConfig().useJava50()) {
            returnType = findBaseClass(parent, sgState);
        } else {
            returnType = parent;
        }

        JMethod jMethod = new JMethod(methodName, returnType,
                                      "the unmarshaled " + returnType);
        jMethod.getModifiers().setStatic(true);
        jMethod.addException(SGTypes.MARSHAL_EXCEPTION,
                "if object is null or if any SAXException is thrown during marshaling");
        jMethod.addException(SGTypes.VALIDATION_EXCEPTION,
                "if this object is an invalid instance according to the schema");
        jMethod.addParameter(new JParameter(SGTypes.READER, "reader"));
        parent.addMethod(jMethod);

        JSourceCode jsc = jMethod.getSourceCode();
        jsc.add("return (");
        jsc.append(returnType.getName());
        jsc.append(") org.exolab.castor.xml.Unmarshaller.unmarshal(");
        jsc.append(parent.getName());
        jsc.append(".class, reader);");
    } //-- createUnmarshalMethods
View Full Code Here

     * @param jClass class to find the base class of
     * @param sgState current state of source generation
     * @return the base class of the provided class.
     */
    private JClass findBaseClass(final JClass jClass, final SGStateInfo sgState) {
        JClass returnType = jClass;

        List<JClass> classes = new LinkedList<JClass>();
        classes.add(returnType);

        while (returnType.getSuperClassQualifiedName() != null) {
            String superClassName = returnType.getSuperClassQualifiedName();
            JClass superClass = sgState.getSourceCode(superClassName);
            if (superClass == null) {
                superClass = sgState.getImportedSourceCode(superClassName);
            }

            // A binding can cause us to have to look for the superclass class in
            // the package of the current class
            if (superClass == null && superClassName.indexOf('.') < 0) {
                String pkgName = returnType.getPackageName();
                if (pkgName != null && pkgName.length() > 0) {
                    superClassName = pkgName + "." + superClassName;
                    superClass = sgState.getSourceCode(superClassName);
                }
            }

            // If returnClass has no superclass then it is the base class
            if (superClass == null) {
                break;
            }

            // Prevent inheritance loops from causing infinite loops
            if (classes.contains(superClass)) {
                StringBuilder buffer = new StringBuilder(64);
                buffer.append("Loop found in class hierarchy: ");
                for (Iterator<JClass> i = classes.iterator(); i.hasNext(); ) {
                    JClass element = i.next();
                    // If JClass told us the source of the class (ComplexType, Element, ...
                    // then we could report that to and make name conflicts more obvious.
                    buffer.append(element.getName());
                    buffer.append(" -> ");
                }
                buffer.append(superClass.getName());
                sgState.getDialog().notify(buffer.toString());
                // FIXME We should probably throw an exception here
View Full Code Here

      * @param jclass The JClass which will implement the CastorTestable Interface.
      * @param state
      */
    private void createRandomizeFields(final JClass jclass, final FactoryState state) {
        JMethod jMethod = new JMethod("randomizeFields");
        jMethod.addException(new JClass("InstantiationException"),
                             "if we try to instantiate an abstract class or interface");
        jMethod.addException(new JClass("IllegalAccessException"),
                             "if we do not have access to the field, for example if it is private");
        jMethod.setComment("implementation of org.castor.xmlctf.CastorTestable");
        jclass.addMethod(jMethod);
        JSourceCode jsc = jMethod.getSourceCode();
        JField[] fields = jclass.getFields();
View Full Code Here

                        handleField(fieldInfo, state, component);

                        //-- remove getter since we don't need to override the original getter
                        String mname = fieldInfo.getReadMethodName();
                        JClass jClass = state.getJClass();
                        JMethod method = jClass.getMethod(mname, 0);
                        jClass.removeMethod(method);

                        //-- update setter method
                        mname = fieldInfo.getWriteMethodName();
                        method = jClass.getMethod(mname, 0);
                        JSourceCode jsc = method.getSourceCode();
                        jsc.add("super.");
                        jsc.append(mname);
                        jsc.append("(this.");
                        jsc.append(fieldInfo.getName());
View Full Code Here

TOP

Related Classes of org.exolab.javasource.JClass

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.