db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r430577 - /db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
Date Thu, 10 Aug 2006 22:51:21 GMT
Author: arminw
Date: Thu Aug 10 15:51:20 2006
New Revision: 430577

URL: http://svn.apache.org/viewvc?rev=430577&view=rev
Log:
apply patch by Tom Antony

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java?rev=430577&r1=430576&r2=430577&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
Thu Aug 10 15:51:20 2006
@@ -39,11 +39,18 @@
  * Utility to process OJB's repository.xml file and generate Java bean source code and
  * SQL schema in Torque XML format.
  *
+ * Persistent inner classes
+ * ------------------------
+ *
+ * The utility supports persistent inner classes. In case the outer class is not defined
in the OR mapping
+ * metadata an artificial outer class is generated to hold the inner class(es).
+ *
  * Auto generated indirection tables
  * ---------------------------------
  *
  * If there are no explicit mappings for an indirection table, the utility generates the
SQL
- * schema for it including referential constraints.
+ * schema for it including referential constraints. The utility also takes care of one sided
+ * m:n mappings where the indirection table is specified by only one party.
  *
  * An indirection table associates two tables. So it will contain two referential constraints,
  * one for each of the associated table. The primary key will be a combination of the foreign
@@ -112,10 +119,10 @@
     /**
      * Creates a new instance of the repository xml processor.
      *
-     * @param    repositoryXml the path of the repository.xml to be processed.
-     * @param    dbOutputDirectory the output directory into which java beans and Torque
xml are
+     * @param repositoryXml the path of the repository.xml to be processed.
+     * @param dbOutputDirectory the output directory into which java beans and Torque xml
are
      * generated, specify null for current directory.
-     * @param    beanOutputDirectory the name of the Torque xml file, specify null for the
default
+     * @param beanOutputDirectory the name of the Torque xml file, specify null for the default
      * which is is 'ojb-torque.xml'.
      */
     public RepositoryXmlProcessor(String repositoryXml, String dbOutputDirectory, String
beanOutputDirectory) throws Exception
@@ -134,18 +141,18 @@
     }
 
     /*
-	 *	Convinience method.
-	 */
+      *	Convinience method.
+      */
     private Table getTableInfo(Element clsDescElem)
     {
         return getTableInfo(clsDescElem, true);
     }
 
-	/*
-	 *	Get the table description associated with a <class-descriptor> element.
-	 *  If recurse is true, explore <reference-descriptor> elements, else return after
-	 *	filling in the columns.
-	 */
+    /*
+      *	Get the table description associated with a <class-descriptor> element.
+      *  If recurse is true, explore <reference-descriptor> elements, else return after
+      *	filling in the columns.
+      */
     private Table getTableInfo(Element clsDescElem, boolean recurse)
     {
         Table table = new Table();
@@ -248,8 +255,8 @@
     }
 
     /*
-     *	Returns set of all table names.
-     */
+      *	Returns set of all table names.
+      */
     private Set allTables(Document doc)
     {
         Set tableNames = new HashSet();
@@ -264,33 +271,33 @@
     }
 
     /*
-     *	Returns set of names of tables mapped to multiple classes. This includes tables used
as indirection tables
-     *  betwen two entities in addition to having explicit mappings.
-     */
+      *	Returns set of names of tables mapped to multiple classes. This includes tables used
as indirection tables
+      *  betwen two entities in addition to having explicit mappings.
+      */
     private Set duplicateTables(Document doc)
     {
         Set workingSet = new HashSet();
         Set duplicateSet = new HashSet();
 
-		NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
+        NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
 
-		/* First collect all indirection tables into the working set. */
-		for(int i = 0; i < clsDescList.getLength(); i++)
-		{
-			Element clsDescElem = (Element) clsDescList.item(i);
+        /* First collect all indirection tables into the working set. */
+        for(int i = 0; i < clsDescList.getLength(); i++)
+        {
+            Element clsDescElem = (Element) clsDescList.item(i);
 
             NodeList colDescList = clsDescElem.getElementsByTagName("collection-descriptor");
 
-			for(int j = 0; j < colDescList.getLength(); j++)
-			{
-				Element colDescElem = (Element) colDescList.item(j);
+            for(int j = 0; j < colDescList.getLength(); j++)
+            {
+                Element colDescElem = (Element) colDescList.item(j);
                 String indirectionTableName = colDescElem.getAttribute("indirection-table");
                 if(StringUtils.isNotBlank(indirectionTableName))
                 {
-                	workingSet.add(indirectionTableName);
-				}
-			}
-		}
+                    workingSet.add(indirectionTableName);
+                }
+            }
+        }
 
         for(int i = 0; i < clsDescList.getLength(); i++)
         {
@@ -305,8 +312,8 @@
     }
 
     /*
-     *	Merge the src table into the target.
-     */
+      *	Merge the src table into the target.
+      */
     private void mergeTables(Table target, Table src)
     {
         // merge columns
@@ -340,7 +347,9 @@
         }
     }
 
-    /** Generate the Torque format SQL schema definitions. */
+    /**
+     * Generate the Torque format SQL schema definitions.
+     */
     public void generateSQL() throws Exception
     {
         Set allTables = allTables(doc);
@@ -362,10 +371,10 @@
             {
                 try
                 {
-                   /*
-                    *	If table has multiple class mappings, keep the table structure in the
deferred
-                    *	list and keep merging later definitions we encounter.
-                    */
+                    /*
+                          *	If table has multiple class mappings, keep the table structure
in the deferred
+                          *	list and keep merging later definitions we encounter.
+                          */
                     if(duplicateTables.contains(tableName))
                     {
                         Table existingTable = (Table) deferredTables.get(tableName);
@@ -392,67 +401,131 @@
                         {
                             Table indirectionTable = (Table) indirectionTables.get(indirectionTableName);
 
+                            /*
+                                    * Who ever who sees the 'indirection-table' first handles
filling up
+                                    * all details. This also takes care of a corner case
where only one party
+                                    * defines the 'indirection-table' i.e one-sided m:n mapping.
+                                    */
                             if(indirectionTable == null)
                             {
                                 indirectionTable = new Table();
                                 indirectionTable.name = indirectionTableName;
 
                                 indirectionTables.put(indirectionTableName, indirectionTable);
-                            }
 
-                            // Generate one foreign key constraint for the current table.
-                            ForeignKey foreignKey = new ForeignKey();
+                                // Generate one foreign key constraint for the current table.
+                                ForeignKey foreignKey = new ForeignKey();
 
-                            indirectionTable.foreignKeys.add(foreignKey);
+                                indirectionTable.foreignKeys.add(foreignKey);
 
-                            foreignKey.foreignTable = currentTable.name;
+                                foreignKey.foreignTable = currentTable.name;
 
-                            NodeList fkSelfList = colDescElem.getElementsByTagName("fk-pointing-to-this-class");
-                            for(int k = 0; k < fkSelfList.getLength(); k++)
-                            {
-                                Element fkSelfElem = (Element) fkSelfList.item(k);
-                                String columnName = fkSelfElem.getAttribute("column");
+                                NodeList fkSelfList = colDescElem.getElementsByTagName("fk-pointing-to-this-class");
+                                for(int k = 0; k < fkSelfList.getLength(); k++)
+                                {
+                                    Element fkSelfElem = (Element) fkSelfList.item(k);
+                                    String columnName = fkSelfElem.getAttribute("column");
 
-                                Column column = new Column();
-                                indirectionTable.columns.add(column);
+                                    Column column = new Column();
+                                    indirectionTable.columns.add(column);
 
-                                column.name = columnName;
-                                foreignKey.localColumns.add(columnName);
+                                    column.name = columnName;
+                                    foreignKey.localColumns.add(columnName);
 
-                               /*
-                                *	Foreign keys pointing to current table in the <collection-descriptor>
-                                *	element should match primary keys of current table in the
same sequence.
-                                *	Match attributes for indirection columns with corresponding
primary key columns.
-                                */
-                                String foreignColumnName = null;
-                                String foreignColumnType = null;
-                                String foreignColumnLength = null;
+                                    /*
+                                              *	Foreign keys pointing to current table in
the <collection-descriptor>
+                                              *	element should match primary keys of current
table in the same sequence.
+                                              *	Match attributes for indirection columns
with corresponding primary key columns.
+                                              */
+                                    String foreignColumnName = null;
+                                    String foreignColumnType = null;
+                                    String foreignColumnLength = null;
 
-                                int primaryKeyCounter = 0;
-                                for(int q = 0; q < currentTable.columns.size(); q++)
-                                {
-                                    Column currentTableColumn = (Column) currentTable.columns.get(q);
-                                    if(currentTableColumn.isPrimaryKey)
+                                    int primaryKeyCounter = 0;
+                                    for(int q = 0; q < currentTable.columns.size(); q++)
                                     {
-                                        if(primaryKeyCounter == k)
+                                        Column currentTableColumn = (Column) currentTable.columns.get(q);
+                                        if(currentTableColumn.isPrimaryKey)
                                         {
-                                            foreignColumnName = currentTableColumn.name;
-                                            foreignColumnType = currentTableColumn.jdbcType;
-                                            foreignColumnLength = currentTableColumn.length;
-                                            break;
+                                            if(primaryKeyCounter == k)
+                                            {
+                                                foreignColumnName = currentTableColumn.name;
+                                                foreignColumnType = currentTableColumn.jdbcType;
+                                                foreignColumnLength = currentTableColumn.length;
+                                                break;
+                                            }
+                                            else
+                                                primaryKeyCounter++;
                                         }
-                                        else
-                                            primaryKeyCounter++;
                                     }
+
+                                    column.jdbcType = foreignColumnType;
+                                    column.length = foreignColumnLength;
+                                    foreignKey.foreignColumns.add(foreignColumnName);
+
+                                    // All indirection columns become part of primary key
for indirection table.
+                                    column.isPrimaryKey = true;
+                                    column.isNullable = false;
                                 }
 
-                                column.jdbcType = foreignColumnType;
-                                column.length = foreignColumnLength;
-                                foreignKey.foreignColumns.add(foreignColumnName);
-
-                                // All indirection columns become part of primary key for
indirection table.
-                                column.isPrimaryKey = true;
-                                column.isNullable = false;
+                                // Generate one foreign key constraint for the other table.
+                                ForeignKey otherForeignKey = new ForeignKey();
+                                indirectionTable.foreignKeys.add(otherForeignKey);
+
+                                NodeList fkOtherList = colDescElem.getElementsByTagName("fk-pointing-to-element-class");
+                                for(int k = 0; k < fkOtherList.getLength(); k++)
+                                {
+                                    Element fkOtherElem = (Element) fkOtherList.item(k);
+                                    String columnName = fkOtherElem.getAttribute("column");
+
+                                    Column column = new Column();
+                                    indirectionTable.columns.add(column);
+
+                                    column.name = columnName;
+                                    otherForeignKey.localColumns.add(columnName);
+
+                                    /*
+                                              *	Foreign keys pointing to other table in the
<collection-descriptor>
+                                              *	element should match primary keys of other
table in the same sequence.
+                                              *	Match attributes for indirection columns
with corresponding primary key columns.
+                                              */
+                                    String foreignColumnName = null;
+                                    String foreignColumnType = null;
+                                    String foreignColumnLength = null;
+
+                                    String otherClass = colDescElem.getAttribute("element-class-ref");
+
+                                    Element otherClassElem = findClass(doc, otherClass);
+                                    Table otherTable = getTableInfo(otherClassElem);
+
+                                    otherForeignKey.foreignTable = otherTable.name;
+
+                                    int primaryKeyCounter = 0;
+                                    for(int q = 0; q < otherTable.columns.size(); q++)
+                                    {
+                                        Column otherTableColumn = (Column) otherTable.columns.get(q);
+                                        if(otherTableColumn.isPrimaryKey)
+                                        {
+                                            if(primaryKeyCounter == k)
+                                            {
+                                                foreignColumnName = otherTableColumn.name;
+                                                foreignColumnType = otherTableColumn.jdbcType;
+                                                foreignColumnLength = otherTableColumn.length;
+                                                break;
+                                            }
+                                            else
+                                                primaryKeyCounter++;
+                                        }
+                                    }
+
+                                    column.jdbcType = foreignColumnType;
+                                    column.length = foreignColumnLength;
+                                    otherForeignKey.foreignColumns.add(foreignColumnName);
+
+                                    // All indirection columns become part of primary key
for indirection table.
+                                    column.isPrimaryKey = true;
+                                    column.isNullable = false;
+                                }
                             }
                         }
                     }
@@ -465,24 +538,23 @@
         }
 
         /*
-         * Deferred tables also includes tables which are also used as indirection tables
in addition to
-         * having explicit mapping. So merge them with the corresponding indirection table
if any.
-         */
+           * Deferred tables also includes tables which are also used as indirection tables
in addition to
+           * having explicit mapping. So merge them with the corresponding indirection table
if any.
+           */
         Set defKeySet = deferredTables.keySet();
-		Iterator defKeysItr = defKeySet.iterator();
-		while(defKeysItr.hasNext())
-		{
-			String tableName = (String) defKeysItr.next();
-
-			Table defferedTable = (Table) deferredTables.get(tableName);
-			Table indirectionTable = (Table) indirectionTables.get(tableName);
-
-			if(indirectionTable != null)
-			{
-				mergeTables(defferedTable, indirectionTable);
-			}
+        Iterator defKeysItr = defKeySet.iterator();
+        while(defKeysItr.hasNext())
+        {
+            String tableName = (String) defKeysItr.next();
+
+            Table defferedTable = (Table) deferredTables.get(tableName);
+            Table indirectionTable = (Table) indirectionTables.get(tableName);
 
-		}
+            if(indirectionTable != null)
+            {
+                mergeTables(defferedTable, indirectionTable);
+            }
+        }
 
         /* Generate deferred tables at the end. */
 
@@ -497,21 +569,20 @@
             fwr.write(tableStr);
         }
 
-	   /*
-	    *	Generate tables for indirection tables at the end. Table structure for an
-	    *	indirection table gets filled up after processing both of the association tables.
-	    */
-
+        /*
+           * Generate tables for indirection tables at the end. Table structure for an
+           * indirection table gets filled up after processing both of the association tables.
+           */
         Set indKeySet = indirectionTables.keySet();
         Iterator indKeysItr = indKeySet.iterator();
         while(indKeysItr.hasNext())
         {
             String tableName = (String) indKeysItr.next();
 
-           /*
-			*	Sometimes there can be explicit mappings for indirection tables. In such cases
-			*	skip the auto generation of indirection table.
-			*/
+            /*
+                *	Sometimes there can be explicit mappings for indirection tables. In such
cases
+                *	skip the auto generation of indirection table.
+                */
             if(allTables.contains(tableName))
                 continue;
 
@@ -525,234 +596,233 @@
         fwr.close();
     }
 
-	/**
-	 *	Return bean descriptor for a class descriptor element.
-	 *	This method always returns an empty list for inner classes.
-	 */
-	private BeanDescriptor getBeanDescriptor(Element clsDescElem)
-	{
-		String clsName = clsDescElem.getAttribute("class");
-
-		String packageName = null;
-		String className;
-
-		/* Handle inner class names */
-		if(clsName.indexOf("$") != -1)
-		{
-			int index = clsName.indexOf("$");
-			className = clsName.substring(index + 1);
-		}
-		else
-		{
-			int indexDot = clsName.lastIndexOf(".");
-			if(indexDot == -1)
-				className = clsName;
-			else
-			{
-				packageName = clsName.substring(0, indexDot);
-				className = clsName.substring(indexDot + 1);
-			}
-		}
-
-		String baseClass = null;
-		ArrayList attributes = new ArrayList();
-		ArrayList types = new ArrayList();
-
-		NodeList refDescList = clsDescElem.getElementsByTagName("reference-descriptor");
-		for(int j = 0; j < refDescList.getLength(); j++)
-		{
-			Element refDescElem = (Element) refDescList.item(j);
-
-			String fieldName = refDescElem.getAttribute("name");
-			String classRef = refDescElem.getAttribute("class-ref");
-			classRef = classRef.replace('$', '.');	// handle inner classes
-
-			// handle super references
-			if(fieldName.equals("super"))
-			{
-				baseClass = classRef;
-			}
-			else
-			{
-				attributes.add(fieldName);
-				types.add(classRef);
-			}
-		}
-
-		NodeList fldDescList = clsDescElem.getElementsByTagName("field-descriptor");
-		for(int j = 0; j < fldDescList.getLength(); j++)
-		{
-			Element fldDescElem = (Element) fldDescList.item(j);
-
-			String fieldName = fldDescElem.getAttribute("name");
-			String jdbcType = fldDescElem.getAttribute("jdbc-type");
-			String primaryKey = fldDescElem.getAttribute("primarykey");
-			boolean isPrimaryKey = primaryKey != null && primaryKey.equals("true");
-			String type = (String) typeMap.get(jdbcType);
-
-				/*
-				 *	If baseClass is set using the 'super' reference then primary key
-				 *	fields are being repeated only for join purpose.
-				 */
-			if(baseClass == null || !isPrimaryKey)
-			{
-				attributes.add(fieldName);
-				types.add(type);
-			}
-		}
-
-		NodeList colDescList = clsDescElem.getElementsByTagName("collection-descriptor");
-		for(int j = 0; j < colDescList.getLength(); j++)
-		{
-			Element colDescElem = (Element) colDescList.item(j);
-
-			String fieldName = colDescElem.getAttribute("name");
-			String type = "java.util.List";
-
-			attributes.add(fieldName);
-			types.add(type);
-		}
+    /**
+     * Return bean descriptor for a class descriptor element.
+     * This method always returns an empty list for inner classes.
+     */
+    private BeanDescriptor getBeanDescriptor(Element clsDescElem)
+    {
+        String clsName = clsDescElem.getAttribute("class");
+
+        String packageName = null;
+        String className;
+
+        /* Handle inner class names */
+        if(clsName.indexOf("$") != -1)
+        {
+            int index = clsName.indexOf("$");
+            className = clsName.substring(index + 1);
+        }
+        else
+        {
+            int indexDot = clsName.lastIndexOf(".");
+            if(indexDot == -1)
+                className = clsName;
+            else
+            {
+                packageName = clsName.substring(0, indexDot);
+                className = clsName.substring(indexDot + 1);
+            }
+        }
+
+        String baseClass = null;
+        ArrayList attributes = new ArrayList();
+        ArrayList types = new ArrayList();
+
+        NodeList refDescList = clsDescElem.getElementsByTagName("reference-descriptor");
+        for(int j = 0; j < refDescList.getLength(); j++)
+        {
+            Element refDescElem = (Element) refDescList.item(j);
+
+            String fieldName = refDescElem.getAttribute("name");
+            String classRef = refDescElem.getAttribute("class-ref");
+            classRef = classRef.replace('$', '.');    // handle inner classes
+
+            // handle super references
+            if(fieldName.equals("super"))
+            {
+                baseClass = classRef;
+            }
+            else
+            {
+                attributes.add(fieldName);
+                types.add(classRef);
+            }
+        }
+
+        NodeList fldDescList = clsDescElem.getElementsByTagName("field-descriptor");
+        for(int j = 0; j < fldDescList.getLength(); j++)
+        {
+            Element fldDescElem = (Element) fldDescList.item(j);
+
+            String fieldName = fldDescElem.getAttribute("name");
+            String jdbcType = fldDescElem.getAttribute("jdbc-type");
+            String primaryKey = fldDescElem.getAttribute("primarykey");
+            boolean isPrimaryKey = primaryKey != null && primaryKey.equals("true");
+            String type = (String) typeMap.get(jdbcType);
+
+            /*
+                *	If baseClass is set using the 'super' reference then primary key
+                *	fields are being repeated only for join purpose.
+                */
+            if(baseClass == null || !isPrimaryKey)
+            {
+                attributes.add(fieldName);
+                types.add(type);
+            }
+        }
+
+        NodeList colDescList = clsDescElem.getElementsByTagName("collection-descriptor");
+        for(int j = 0; j < colDescList.getLength(); j++)
+        {
+            Element colDescElem = (Element) colDescList.item(j);
+
+            String fieldName = colDescElem.getAttribute("name");
+            String type = "java.util.List";
+
+            attributes.add(fieldName);
+            types.add(type);
+        }
 
-		ArrayList innerClasses = new ArrayList();
+        ArrayList innerClasses = new ArrayList();
 
         return new BeanDescriptor(packageName, className, baseClass, null,
-        attributes, types, innerClasses);
-	}
+                attributes, types, innerClasses);
+    }
 
     /**
-     *	Generate the source for Java beans mapped to tables.
+     * Generate the source for Java beans mapped to tables.
      *
-     *	For inner classes, if the parent is not a persistent class defined in the mapping
metadata, then a holder parent
-     *	class will be generated to hold the inner classes.
+     * For inner classes, if the parent is not a persistent class defined in the mapping
metadata, then a holder parent
+     * class will be generated to hold the inner classes.
      */
     public void generateJavaCode() throws Exception
     {
-		/*
-		 First form a mapping of inner classes to their outer classes, with outer class as the
key
-		 and a list of inner class names as the value.
-		 */
-		HashMap innerOuterClassMap = new HashMap();
-
-		NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
-
-		for(int i = 0; i < clsDescList.getLength(); i++)
-		{
-			Element clsDescElem = (Element) clsDescList.item(i);
+        /*
+           First form a mapping of inner classes to their outer classes, with outer class
as the key
+           and a list of inner class names as the value.
+           */
+        HashMap innerOuterClassMap = new HashMap();
+
+        NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
+
+        for(int i = 0; i < clsDescList.getLength(); i++)
+        {
+            Element clsDescElem = (Element) clsDescList.item(i);
 
             String clsName = clsDescElem.getAttribute("class");
 
-			if(clsName.indexOf("$") != -1)
-			{
-				int index = clsName.indexOf("$");
-				String outerClass = clsName.substring(0,index);
-				String innerClass = clsName.substring(index + 1);
-				if(innerOuterClassMap.get(outerClass) == null)
-				{
-					ArrayList list = new ArrayList();
-					list.add(innerClass);
-					innerOuterClassMap.put(outerClass, list);
-				}
-				else
-				{
-					ArrayList list = (ArrayList) innerOuterClassMap.get(outerClass);
-					list.add(innerClass);
-				}
-			}
-		}
+            if(clsName.indexOf("$") != -1)
+            {
+                int index = clsName.indexOf("$");
+                String outerClass = clsName.substring(0, index);
+                String innerClass = clsName.substring(index + 1);
+                if(innerOuterClassMap.get(outerClass) == null)
+                {
+                    ArrayList list = new ArrayList();
+                    list.add(innerClass);
+                    innerOuterClassMap.put(outerClass, list);
+                }
+                else
+                {
+                    ArrayList list = (ArrayList) innerOuterClassMap.get(outerClass);
+                    list.add(innerClass);
+                }
+            }
+        }
 
-		/* A map holding descriptions for inner classes. */
-		HashMap innerDescriptionsMap = new HashMap();
+        /* A map holding descriptions for inner classes. */
+        HashMap innerDescriptionsMap = new HashMap();
 
-		/* Also collect the inner class descriptions upfront before generating outer class definitions.
 */
+        /* Also collect the inner class descriptions upfront before generating outer class
definitions.	 */
         for(int i = 0; i < clsDescList.getLength(); i++)
         {
             Element clsDescElem = (Element) clsDescList.item(i);
 
-			String clsName = clsDescElem.getAttribute("class");
+            String clsName = clsDescElem.getAttribute("class");
 
-			if(clsName.indexOf("$") != -1)
-			{
-				int index = clsName.indexOf("$");
-				String innerClass = clsName.substring(index + 1);
+            if(clsName.indexOf("$") != -1)
+            {
+                int index = clsName.indexOf("$");
+                String innerClass = clsName.substring(index + 1);
 
-				BeanDescriptor descriptor = getBeanDescriptor(clsDescElem);
+                BeanDescriptor descriptor = getBeanDescriptor(clsDescElem);
 
-				innerDescriptionsMap.put(innerClass, descriptor);
-			}
+                innerDescriptionsMap.put(innerClass, descriptor);
+            }
         }
 
-		/* Now generate class definitions for persistent outer classes defined in metadata */
+        /* Now generate class definitions for persistent outer classes defined in metadata
*/
         for(int i = 0; i < clsDescList.getLength(); i++)
-		{
-			Element clsDescElem = (Element) clsDescList.item(i);
-
-			String clsName = clsDescElem.getAttribute("class");
+        {
+            Element clsDescElem = (Element) clsDescList.item(i);
 
-			if(clsName.indexOf("$") == -1)
-			{
-				BeanDescriptor descriptor = getBeanDescriptor(clsDescElem);
+            String clsName = clsDescElem.getAttribute("class");
 
-				/* Set innerClasses list (if present) for the outer class. */
+            if(clsName.indexOf("$") == -1)
+            {
+                BeanDescriptor descriptor = getBeanDescriptor(clsDescElem);
 
-				ArrayList innerDescriptors = descriptor.innerClasses();
+                /* Set innerClasses list (if present) for the outer class. */
 
-				ArrayList innerClassList  = (ArrayList) innerOuterClassMap.get(clsName);
+                ArrayList innerDescriptors = descriptor.innerClasses();
 
-				if(innerClassList != null)
-				{
-					for(int j = 0; j < innerClassList.size(); j++)
-					{
-						String innerClass = (String) innerClassList.get(j);
+                ArrayList innerClassList = (ArrayList) innerOuterClassMap.get(clsName);
 
-						BeanDescriptor innerDescriptor = (BeanDescriptor) innerDescriptionsMap.get(innerClass);
+                if(innerClassList != null)
+                {
+                    for(int j = 0; j < innerClassList.size(); j++)
+                    {
+                        String innerClass = (String) innerClassList.get(j);
 
-						innerDescriptors.add(innerDescriptor);
-					}
-				}
+                        BeanDescriptor innerDescriptor = (BeanDescriptor) innerDescriptionsMap.get(innerClass);
+                        innerDescriptors.add(innerDescriptor);
+                    }
+                }
 
-				BeanGenerator generator = new BeanGenerator(beanOutputDirectory);
-				generator.generate(descriptor);
+                BeanGenerator generator = new BeanGenerator(beanOutputDirectory);
+                generator.generate(descriptor);
 
-				/* Remove persistent outer classes from mappings for the next stage. */
-				innerOuterClassMap.remove(clsName);
-			}
+                /* Remove persistent outer classes from mappings for the next stage. */
+                innerOuterClassMap.remove(clsName);
+            }
         }
 
         /*  Generate holder outer classes for inner classes without persistent outer classes
defined */
         Iterator itr = innerOuterClassMap.keySet().iterator();
         while(itr.hasNext())
         {
-			String outerClass = (String) itr.next();
+            String outerClass = (String) itr.next();
 
-			ArrayList innerDescriptors = new ArrayList();
+            ArrayList innerDescriptors = new ArrayList();
 
-			ArrayList innerClassList = (ArrayList) innerOuterClassMap.get(outerClass);
-			for(int i = 0; i < innerClassList.size(); i++)
-			{
-				String innerClass = (String) innerClassList.get(i);
-				BeanDescriptor innerDescriptor = (BeanDescriptor) innerDescriptionsMap.get(innerClass);
-				innerDescriptors.add(innerDescriptor);
-			}
-
-			String packageName = null;
-			String className;
-			int indexDot = outerClass.lastIndexOf(".");
-			if(indexDot == -1)
-				className = outerClass;
-			else
-			{
-				packageName = outerClass.substring(0, indexDot);
-				className = outerClass.substring(indexDot + 1);
-			}
-
-			/* Generate an artificial outer class for holding the inner classes */
-			BeanDescriptor descriptor = new BeanDescriptor(packageName, className, null, null,
-											new ArrayList(), new ArrayList(), innerDescriptors);
+            ArrayList innerClassList = (ArrayList) innerOuterClassMap.get(outerClass);
+            for(int i = 0; i < innerClassList.size(); i++)
+            {
+                String innerClass = (String) innerClassList.get(i);
+                BeanDescriptor innerDescriptor = (BeanDescriptor) innerDescriptionsMap.get(innerClass);
+                innerDescriptors.add(innerDescriptor);
+            }
 
-			BeanGenerator generator = new BeanGenerator(beanOutputDirectory);
-			generator.generate(descriptor);
+            String packageName = null;
+            String className;
+            int indexDot = outerClass.lastIndexOf(".");
+            if(indexDot == -1)
+                className = outerClass;
+            else
+            {
+                packageName = outerClass.substring(0, indexDot);
+                className = outerClass.substring(indexDot + 1);
+            }
+
+            /* Generate an artificial outer class for holding the inner classes */
+            BeanDescriptor descriptor = new BeanDescriptor(packageName, className, null,
null,
+                    new ArrayList(), new ArrayList(), innerDescriptors);
+
+            BeanGenerator generator = new BeanGenerator(beanOutputDirectory);
+            generator.generate(descriptor);
 
-		}
+        }
     }
 
     Element findClass(Document doc, String name)
@@ -826,12 +896,14 @@
 
     public static void main(String [] args) throws Exception
     {
+		RepositoryXmlProcessor processor = new RepositoryXmlProcessor
+		("repository.xml", "target/test", "target/test");
+//		RepositoryXmlProcessor processor = new RepositoryXmlProcessor
+//		("repository.xml", "target/test", "target/test");
 //        RepositoryXmlProcessor processor = new RepositoryXmlProcessor
-//                ("repository.xml", "target/test", "target/test");
-        RepositoryXmlProcessor processor = new RepositoryXmlProcessor
-                ("E:/repository_test.xml", "target/test", "target/test");
+//                ("E:/repository_test.xml", "target/test/forward", "target/test/forward");
 
         processor.generateSQL();
         processor.generateJavaCode();
-    }
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message