Пример #1
0
    private void processSimpleType(SimpleType simpleType, SGStateInfo sInfo) {

        if (simpleType == null) return;

        String packageName = sInfo.packageName;

        //-- Right now the only time we actually
        //-- generate source for a simpletype is
        //-- when it's an enumeration
        //if (! (simpleType instanceof BuiltInType) ) {
        if (simpleType.hasFacet(Facet.ENUMERATION)) {

            ClassInfo classInfo = sInfo.resolve(simpleType);

            if (classInfo == null) {

                JClass jClass
                    = sourceFactory.createSourceCode(simpleType, sInfo);

                processJClass(jClass, sInfo);
            }
            else {
                JClass jClass = classInfo.getJClass();
                if (!sInfo.processed(jClass)) {
                    processJClass(jClass, sInfo);
                }
            }
        }
    } //-- processSimpleType
Пример #2
0
    /**
     * Creates Java Source code (Object model) for the given XML Schema
     * @param schema the XML schema to generate the Java sources for
     * @param packageName the package for the generated source files
    **/
    public void generateSource(Schema schema, String packageName) {
        SGStateInfo sInfo = new SGStateInfo();
        sInfo.packageName = packageName;
		if(sInfo.packageName==null)
			sInfo.packageName=SourceGenerator.getJavaPackage(schema.getTargetNamespace());

        sInfo.setPromptForOverwrite(warnOnOverwrite);
        sInfo.setVerbose(verbose);

        createClasses(schema, sInfo);
    } //-- generateSource
Пример #3
0
    /**
     * Processes the given JClass by creating the
     * corresponding MarshalInfo and print the Java classes
     * @param classInfo the classInfo to process
    **/
    private void processJClass(JClass jClass, SGStateInfo state) {


        boolean allowPrinting = true;

        if (state.promptForOverwrite()) {
            String filename = jClass.getFilename(destDir);
            File file = new File(filename);
            if (file.exists()) {
                String message = filename + " already exists. overwrite?";
                allowPrinting = dialog.confirm(message);
            }
        }
        //-- print class
        if (allowPrinting) {

            //hack for the moment
            //to avoid the compiler complaining with java.util.Date
            jClass.removeImport("org.exolab.castor.types.Date");
            jClass.setHeader(header);
            jClass.print(destDir,lineSeparator);
        }

        //------------------------------------/
        //- Create ClassDescriptor and print -/
        //------------------------------------/

        ClassInfo classInfo = state.resolve(jClass);

        if (_createDescriptors && (classInfo != null)) {

            JClass desc
                = DescriptorSourceFactory.createSource(classInfo);

            allowPrinting = true;
            if (state.promptForOverwrite()) {
                String filename = desc.getFilename(destDir);
                File file = new File(filename);
                if (file.exists()) {
                    String message = filename + " already exists. overwrite?";
                    allowPrinting = dialog.confirm(message);
                }
            }

            if (allowPrinting) {
                desc.setHeader(header);
                desc.print(destDir,lineSeparator);
            }
        }

        state.markAsProcessed(jClass);
    } //-- processJClass
Пример #4
0
    /**
     * Processes the given ComplexType and creates all necessary class
     * to support it
     * @param complexType the ComplexType to process
    **/
    private void processComplexType(ComplexType complexType, SGStateInfo sInfo) {

        if (complexType == null) return;

        ClassInfo classInfo = sInfo.resolve(complexType);

        if (classInfo == null) {

            //-- handle top-leve complextypes
            if (complexType.isTopLevel()) {

                JClass[] classes
                    = sourceFactory.createSourceCode(complexType, sInfo);

                for (int i = 0; i < classes.length; i++)
                    processJClass(classes[i], sInfo);
            }

            //-- process base complextype if necessary
            XMLType baseType= complexType.getBaseType();
            if (baseType != null &&
				baseType.getSchema() == complexType.getSchema()) {

				if (baseType.isComplexType())
                    processComplexType((ComplexType)baseType, sInfo);
            }

            //-- process AttributeDecl
            processAttributes(complexType, sInfo);

            //-- process ContentModel
            processContentModel(complexType, sInfo);

        }
        else {
            JClass jClass = classInfo.getJClass();
            if (!sInfo.processed(jClass)) {
                //-- process AttributeDecl
                processAttributes(complexType, sInfo);
                //-- process ContentModel
                processContentModel(complexType, sInfo);
                processJClass(jClass, sInfo);
            }
        }
    } //-- processComplexType
Пример #5
0
    private void createClasses(Group group, SGStateInfo sInfo) {

		if (sInfo.verbose()) {
		    System.out.print("Creating classes for group: ");
		    System.out.println(group.getName());
            if (group.getName() == null) {
                System.out.println("cannot create classes for unnamed nested groups");
                return;
            }
		}

		JClass[] classes = sourceFactory.createSourceCode(group, sInfo);
        processContentModel(group, sInfo);
        for (int i = 0; i < classes.length; i++)
            processJClass(classes[i], sInfo);

    } //-- createClasses
Пример #6
0
    private void createClasses(ElementDecl elementDecl, SGStateInfo sInfo) {

		//-- when mapping schema types, only interested in producing classes
		//-- for elements with anonymous complex types
		if (SourceGenerator.mappingSchemaType2Java())
			if (elementDecl.isReference() ||
				(elementDecl.getType()!=null &&
				 elementDecl.getType().getName()!=null))
				return;

		if (sInfo.verbose()) {
		    System.out.print("Creating classes for element: ");
		    System.out.println(elementDecl.getName());
		}
        //-- create classes for sub-elements if necessary
        XMLType xmlType = elementDecl.getType();

        //-- No type definition
        if (xmlType == null) {
            System.out.print("Type not found for element: ");
            System.out.println(elementDecl.getName());
            return;
        }
        //-- ComplexType
        else if (xmlType.isComplexType()) {

			JClass[] classes = sourceFactory.createSourceCode(elementDecl,
                                                        sInfo);

            processComplexType((ComplexType)xmlType, sInfo);

            for (int i = 0; i < classes.length; i++)
                 processJClass(classes[i], sInfo);

        }
        //-- SimpleType
        else {
            processSimpleType((SimpleType)xmlType, sInfo);
        }

    }  //-- createClasses