Package org.exolab.castor.builder.info

Examples of org.exolab.castor.builder.info.ClassInfo


        //-- handle  content
        if (classInfo.allowContent()) {
            createDescriptor(classDesc, classInfo.getTextField(), localClassName, null, jsc);
        }

        ClassInfo   base = classInfo.getBaseClass();
        FieldInfo[] atts = classInfo.getAttributeFields();

        //--------------------------------/
        //- Create attribute descriptors -/
        //--------------------------------/

        jsc.add("//-- initialize attribute descriptors");
        jsc.add("");

        for (int i = 0; i < atts.length; i++) {
            FieldInfo member = atts[i];
            //-- skip transient members
            if (member.isTransient()) {
                continue;
            }

            if (base != null) {
                String baseNodeName = new XMLInfoNature(member).getNodeName();
                if (baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION)) {
                    createDescriptor(classDesc, member, localClassName, nsURI, jsc);
                } else {
                    if (base.getAttributeField(baseNodeName) != null) {
                        createRestrictedDescriptor(member, jsc);
                    } else {
                        createDescriptor(classDesc, member, localClassName,
                                nsURI, jsc);
                    }
                }
            } else {
                createDescriptor(classDesc, member, localClassName, nsURI, jsc);
            }
        }

        //------------------------------/
        //- Create element descriptors -/
        //------------------------------/
        FieldInfo[] elements = classInfo.getElementFields();

        jsc.add("//-- initialize element descriptors");
        jsc.add("");

        for (int i = 0; i < elements.length; i++) {
            FieldInfo member = elements[i];
            //-- skip transient members
            if (member.isTransient()) {
                continue;
            }

            if (base != null) {
                String baseNodeName = xmlNature.getNodeName();
                if (baseNodeName == null) {
                    createDescriptor(classDesc, member, localClassName, nsURI, jsc);
                } else if (baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION)) {
                    createDescriptor(classDesc, member, localClassName, nsURI, jsc);
                } else {
                    if (base.getElementField(baseNodeName) != null) {
                        createRestrictedDescriptor(member, jsc);
                    } else {
                        createDescriptor(classDesc, member, localClassName,
                                nsURI, jsc);
                    }
View Full Code Here


            _xmlInfoRegistry = sgState.getSourceGenerator()
                    .getXMLInfoRegistry();
            _xmlInfoRegistry.bind(_jClass, component, "class");
        }

        _classInfo = new ClassInfo(_jClass);

        _resolver = sgState;

        _packageName = packageName;
View Full Code Here

     *         loaded or found
     */
    boolean processIfNotAlreadyProcessed(final Enumeration<?> classKeys,
                                         final SGStateInfo state) throws IOException {
        while (classKeys.hasMoreElements()) {
            ClassInfo classInfo = state.resolve(classKeys.nextElement());
            JClass jClass = classInfo.getJClass();
            if (!state.processed(jClass)
                    && (inCurrentSchema(state, classInfo)
                            || _sourceGenerator.getGenerateImportedSchemas())) {
                process(jClass, state);
                if (state.getStatusCode() == SGStateInfo.STOP_STATUS) {
View Full Code Here

        }

        //--Make sure this class's name doesn't conflict with a java.lang.* class
        checkNameNotReserved(jClass.getName(), state);

        ClassInfo classInfo = state.resolve(jClass);

        //-- Have we already processed a class with this name?
        JClass conflict = state.getProcessed(jClass.getName());
        if (conflict != null && !state.getSuppressNonFatalWarnings()) {
            SGStateInfo stateAfterResolution =
                _conflictStrategy.dealWithClassNameConflict(state, classInfo, conflict);
            return stateAfterResolution.getStatusCode() != SGStateInfo.STOP_STATUS;
        }

        //-- Mark the current class as processed
        state.markAsProcessed(jClass);

        //-- Print the class
        if (checkAllowPrinting(jClass)) {
            //hack for the moment
            //to avoid the compiler complaining with java.util.Date
            jClass.removeImport("org.exolab.castor.types.Date");
            jClass.setHeader(_header);
            if (_lineSeparator == null) {
                _lineSeparator = System.getProperty("line.separator");
            }
            _jClassPrinter.printClass(jClass, _destDir, _lineSeparator, DEFAULT_HEADER);
        }

        //-- Process and print the class descriptors
        if (classInfo != null) {
            processClassDescriptor(jClass, state, classInfo);
            if (classInfo.hasNature(JDOClassInfoNature.class.getName())) {
                processJDOClassDescriptor(jClass, state, classInfo);
            }
        }

        return state.getStatusCode() != SGStateInfo.STOP_STATUS;
View Full Code Here

        //-- handle  content
        if (classInfo.allowContent()) {
            createFieldMapping(classMapping, classInfo.getTextField(), null);
        }

        ClassInfo base = classInfo.getBaseClass();
        if (base != null) {
            classMapping.setExtends(base.getJClass().getName());
        }

        FieldInfo[] atts = classInfo.getAttributeFields();

        //-----------------------------/
        //- Create attribute mappings -/
        //-----------------------------/

        for (int i = 0; i < atts.length; i++) {
            FieldInfo member = atts[i];
            //-- skip transient members
            if (member.isTransient()) {
                continue;
            }

            //-- skip inherited fields
            if (base != null && base.getAttributeField(xmlNature.getNodeName()) != null) {
                continue;
            }

            createFieldMapping(classMapping, member, nsURI);
        }

        //---------------------------/
        //- Create element mappings -/
        //---------------------------/

        FieldInfo[] elements = classInfo.getElementFields();
        for (int i = 0; i < elements.length; i++) {
            FieldInfo member = elements[i];
            //-- skip transient members
            if (member.isTransient()) {
                continue;
            }

            //-- skip inherited fields
            if (base != null && base.getElementField(xmlNature.getNodeName()) != null) {
                continue;
            }

            createFieldMapping(classMapping, member, nsURI);
        }
View Full Code Here

            }
        }

        assertEquals(1, cInfos.size());

        ClassInfo cInfo = (ClassInfo) cInfos.get(0);
        XMLInfoNature xmlNature = new XMLInfoNature(cInfo);

        assertEquals("father", xmlNature.getNodeName());

        JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);

        assertEquals("Father", cNature.getTableName());

        List primaryKeys = cNature.getPrimaryKeys();

        assertEquals(1, primaryKeys.size());
        assertEquals("ssnr", primaryKeys.get(0));

        ///////// FieldInfo
        /*
         *  There should be 3 FieldInfos:
         *  - ssnr
         *  - firstName
         *  - lastName
         */
        assertEquals(3, cInfo.getFieldCount());

        FieldInfo fInfo = cInfo.getElementField("ssnr");

        assertNotNull(fInfo);

        JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);

        assertEquals("ssnr", fNature.getColumnName());
        assertEquals("integer", fNature.getColumnType());

        fInfo = cInfo.getElementField("firstName");

        assertNotNull(fInfo);

        fNature = new JDOFieldInfoNature(fInfo);

        assertEquals("firstName", fNature.getColumnName());
        assertEquals("varchar", fNature.getColumnType());

        fInfo = cInfo.getElementField("lastName");

        assertNotNull(fInfo);

        fNature = new JDOFieldInfoNature(fInfo);

View Full Code Here

        }

        assertEquals(2, cInfos.size());
       
        for (int i = 0; i < cInfos.size(); ++i) {
            ClassInfo cInfo = (ClassInfo) cInfos.get(i);

            assertNotNull(cInfo);

            XMLInfoNature xmlNature = new XMLInfoNature(cInfo);
           
            if (xmlNature.getNodeName().equals("book")) {
                /*
                 * No JDO-specific information should be stored to this
                 * ClassInfo.
                 */
                assertFalse(cInfo.hasNature(JDOClassInfoNature.class.getName()));
//                JDOClassNature cNature = new JDOClassNature(cInfo);
//               
//                assertEquals(null, cNature.getTableName());
//               
//                List primaryKeys = cNature.getPrimaryKeys();
//               
//                assertNull(primaryKeys);
               
                assertEquals(0, cInfo.getFieldCount());
               
            } else if (xmlNature.getNodeName().equals("bookType")) {
                JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);
               
                assertEquals("book", cNature.getTableName());
               
                List primaryKeys = cNature.getPrimaryKeys();
               
                assertEquals(1, primaryKeys.size());
                assertEquals("isbn", (String) primaryKeys.get(0));
               
                ///////// FieldInfo
                /*
                 *  There should be 3 FieldInfos:
                 *  - coverType (attribute field)
                 *  - isbn
                 *  - title
                 */
                assertEquals(3, cInfo.getFieldCount());

                // FieldInfo for coverType
                FieldInfo fInfo = cInfo.getAttributeField("coverType");
               
                assertNotNull(fInfo);
               
                fInfo.addNature(JDOFieldInfoNature.class.getName());
                JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
               
                assertEquals("cover_type", fNature.getColumnName());
                assertEquals("varchar", fNature.getColumnType());
               
                // FieldInfo for isbn               
                fInfo = cInfo.getElementField("isbn");
               
                assertNotNull(fInfo);
               
                fNature = new JDOFieldInfoNature(fInfo);
               
                assertEquals("isbn", fNature.getColumnName());
                assertEquals("varchar", fNature.getColumnType());
               
                // FieldInfo for title
                fInfo = cInfo.getElementField("title");
               
                assertNotNull(fInfo);
               
                fNature = new JDOFieldInfoNature(fInfo);
               
View Full Code Here

                cInfos.add(sgState.resolve(elem));
            }
        }
       
        for (int i = 0; i < cInfos.size(); ++i) {
            ClassInfo cInfo = (ClassInfo) cInfos.get(i);
           
            assertFalse(cInfo.hasNature(JDOClassInfoNature.class.getName()));

//            /*
//             * No JDO-specific information should be stored to the
//             * ClassInfo.
//             */
 
View Full Code Here

        }
       
        assertEquals(2, cInfos.size());
       
        for (int i = 0; i < cInfos.size(); ++i) {
            ClassInfo cInfo = (ClassInfo) cInfos.get(i);
           
            assertNotNull(cInfo);
           
            JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);
            XMLInfoNature xmlNature = new XMLInfoNature(cInfo);
           
            assertNotNull(cNature);
           
            if (xmlNature.getNodeName().equals("person")) {
                String tableName = cNature.getTableName();
                assertEquals("person", tableName);
               
                List primaryKeys = cNature.getPrimaryKeys();
               
                assertEquals(1, primaryKeys.size());
                assertEquals("ssn", (String) primaryKeys.get(0));
               
                assertEquals(4, cInfo.getFieldCount());
               
                FieldInfo[] fInfos = cInfo.getElementFields();
               
                assertNotNull(fInfos);
               
                for (int j = 0; j < fInfos.length; ++j) {
                    FieldInfo fInfo = fInfos[j];
                    assertNotNull(fInfo);
                    JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
                    assertNotNull(fNature);
                   
                    String columnName = fNature.getColumnName();
                    String columnType = fNature.getColumnType();
                   
                    XMLInfoNature xmlFieldNature = new XMLInfoNature(fInfo);
                   
                    if (xmlFieldNature.getNodeName().equals("ssn")) {   
                        assertEquals("ssn", columnName);
                        assertEquals("bigint", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("firstName")) {
                        assertEquals("firstName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("lastName")) {
                        assertEquals("lastName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("birthdate")) {
                        assertEquals("birthdate", columnName);
                        assertEquals("date", columnType);
                    } else {
                        fail("Unexpected FieldInfo Element encountered!");
                    }
                }
            } else if (xmlNature.getNodeName().equals("insurant")) {
                String tableName = cNature.getTableName();
                assertEquals("insurant", tableName);
               
                List primaryKeys = cNature.getPrimaryKeys();
               
                assertEquals(2, primaryKeys.size());
                assertEquals("ssn", (String) primaryKeys.get(0));
                assertEquals("policyNumber", (String) primaryKeys.get(1));
               
                assertEquals(1, cInfo.getFieldCount());
               
                FieldInfo fInfo = cInfo.getElementField("policyNumber");
               
                assertNotNull(fInfo);
               
                JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
               
View Full Code Here

   
    /**
     * Constructor initializes the XMLNature.
     */
    public XMLNatureClassInfoTest() {
        _holder = new ClassInfo(new JClass("test"));
        _xml = new XMLInfoNature(_holder);
    }
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.info.ClassInfo

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.