directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r713701 - /directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java
Date Thu, 13 Nov 2008 10:34:26 GMT
Author: kayyagari
Date: Thu Nov 13 02:34:25 2008
New Revision: 713701

URL: http://svn.apache.org/viewvc?rev=713701&view=rev
Log:
o added javadoc
o fixed syntax handling

Modified:
    directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java

Modified: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java?rev=713701&r1=713700&r2=713701&view=diff
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java
(original)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java
Thu Nov 13 02:34:25 2008
@@ -35,7 +35,6 @@
 
 import org.antlr.stringtemplate.StringTemplate;
 import org.antlr.stringtemplate.StringTemplateGroup;
-import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 import org.apache.directory.shared.ldap.schema.parser.AttributeTypeLiteral;
 import org.apache.directory.shared.ldap.schema.parser.ObjectClassLiteral;
 import org.apache.directory.shared.ldap.schema.parser.OpenLdapSchemaParser;
@@ -75,7 +74,7 @@
     /** generated source file writer*/
     private SourceFileWriter sourceWriter;
 
-    private String strPackage = "org.apache.directory.olm";
+    private String defaultPackage;
 
     /* keys used for distinguishing the must and may attributes*/
     private static final String MUST = "MUST";
@@ -105,25 +104,37 @@
     Map<String, String> objClassToClassNameMap = new TreeMap<String, String>();
 
     /** root folder for writing the generated source files*/
-    private File sourceRoot;
+    private File sourceOutputDir;
 
     /** static logger */
     private static final Logger LOG = LoggerFactory.getLogger( SourceGenerator.class );
 
 
-    public SourceGenerator( Properties syntaxes ) throws IOException
+    public SourceGenerator( Properties syntaxes, File outputDir ) throws IOException
     {
         this.syntaxes = syntaxes;
         parser = new OpenLdapSchemaParser();
 
-        sourceRoot = new File( "/opt/workspace/apacheds-olm/target/generated-source" );
+        this.sourceOutputDir = outputDir;
 
-        if ( !sourceRoot.exists() )
+        if ( !sourceOutputDir.exists() )
         {
-            sourceRoot.mkdirs();
+            sourceOutputDir.mkdirs();
         }
 
-        sourceWriter = new SourceFileWriter( sourceRoot );
+        sourceWriter = new SourceFileWriter( sourceOutputDir );
+    }
+
+
+    public String getDefaultPackage()
+    {
+        return defaultPackage;
+    }
+
+
+    public void setDefaultPackage( String defaultPackage )
+    {
+        this.defaultPackage = defaultPackage;
     }
 
 
@@ -139,15 +150,14 @@
     /**
      * @see #loadSchema(File)
      */
-    public void loadSchema( Set<String> schemaFilePaths ) throws Exception
+    public void loadSchema( Set<File> schemaFilePaths ) throws Exception
     {
-        for ( String schema : schemaFilePaths )
+        for ( File schema : schemaFilePaths )
         {
-            loadSchema( new File( schema ) );
+            loadSchema( schema );
         }
     }
 
-
     /**
      * 
      *  parses the schema and extracts all the attribute and ojectclass literals.
@@ -231,7 +241,7 @@
             sb.append( objClass ).append( " = " ).append( objClassToClassNameMap.get( objClass
) ).append( '\n' );
         }
 
-        File file = new File( sourceRoot, "classmapping.properties" );
+        File file = new File( sourceOutputDir, "classmapping.properties" );
         FileWriter fwriter = new FileWriter( file );
         fwriter.write( sb.toString() );
         fwriter.close();
@@ -278,7 +288,7 @@
 
         for ( String s : mustAttrs )
         {
-            mustAttrNameClassSet.add( new NameClassPair( s, attrNameToClassNameMap.get( s.toLowerCase()
),
+            mustAttrNameClassSet.add( new NameClassPair( s.replace( "-", "_" ), attrNameToClassNameMap.get(
s.toLowerCase() ),
                 attrNameToJavaTypeMap.get( s.toLowerCase() ) ) );
         }
 
@@ -286,7 +296,7 @@
         {
             //TODO remove this debug statement
             LOG.debug( s + ": " + attrNameToClassNameMap.get( s.toLowerCase() ) );
-            NameClassPair np = new NameClassPair( s, attrNameToClassNameMap.get( s.toLowerCase()
),
+            NameClassPair np = new NameClassPair( s.replace( "-", "_" ), attrNameToClassNameMap.get(
s.toLowerCase() ),
                 attrNameToJavaTypeMap.get( s.toLowerCase() ) );
 
             mayAttrNameClassSet.add( np );
@@ -309,17 +319,22 @@
             + OBJECTCLASS_FILE_SUFFIX;
 
         template.setAttribute( "className", modifiedName );
-        template.setAttribute( "package", strPackage );
+        template.setAttribute( "package", defaultPackage );
+        
+        if( objClass.getOid().equals( "1.3.6.1.4.1.1466.101.120.111" ) )
+        {
+            template.setAttribute( "extensible", true );
+        }
 
         //        if ( objClass.getClassType() != ObjectClassTypeEnum.STRUCTURAL )
         //        {
         //            template.setAttribute( "abstract", true );
         //        }
 
-        sourceWriter.writeFile( modifiedName, template.toString(), strPackage );
+        sourceWriter.writeFile( modifiedName, template.toString(), defaultPackage );
 
         // the key should be the unaltered attributeName
-        objClassToClassNameMap.put( name.toLowerCase(), strPackage + "." + modifiedName );
+        objClassToClassNameMap.put( name.toLowerCase(), defaultPackage + "." + modifiedName
);
 
         LOG.debug( "Completed source generation for ObjectClass '{}'", modifiedName );
     }
@@ -459,25 +474,26 @@
             StringTemplateGroup stgGroup = new StringTemplateGroup( "olm" );
             StringTemplate template = stgGroup.getInstanceOf( "AttributeClass" );
 
+            // handle syntax
+            String attrSyntax = null;
             if ( attrLiteral.getSyntax() == null )
             {
-                template.setAttribute( "syntax", getSuperSyntax( attrLiteral ) );
-
-                template.setAttribute( "argType", DEFAULT_SYNTAX_TYPE );
-                attrNameToJavaTypeMap.put( name.toLowerCase(), DEFAULT_SYNTAX_TYPE );
+                 attrSyntax = getSuperSyntax( attrLiteral );
             }
             else
             {
-                String javaType = syntaxes.getProperty( attrLiteral.getSyntax() );
-
-                template.setAttribute( "argType", javaType );
-                attrNameToJavaTypeMap.put( name.toLowerCase(), javaType );
-
-                attrNameToSyntaxOidMap.put( name.toLowerCase(), attrLiteral.getSyntax() );
-
-                template.setAttribute( "syntax", attrLiteral.getSyntax() );
+                attrSyntax = attrLiteral.getSyntax();
             }
+            
+            template.setAttribute( "syntax", attrSyntax );
+            attrNameToSyntaxOidMap.put( name.toLowerCase(), attrSyntax );
+
+            String javaType = syntaxes.getProperty( attrSyntax );
+            template.setAttribute( "argType", javaType );
+            attrNameToJavaTypeMap.put( name.toLowerCase(), javaType );
+            // end handle syntax           
 
+            
             template.setAttribute( "paramName", modifiedName );
 
             modifiedName = String.valueOf( modifiedName.charAt( 0 ) ).toUpperCase() + modifiedName.substring(
1 );
@@ -491,19 +507,13 @@
 
             template.setAttribute( "oid", attrLiteral.getOid() );
 
-            //            if ( attrLiteral.getSuperior() != null )
-            //            {
-            //                template.setAttribute( "extends", true );
-            //                template.setAttribute( "superClass", attrNameToClassNameMap.get(
attrLiteral.getSuperior().toLowerCase() ) );
-            //            }
-
             template.setAttribute( "attrName", modifiedName );
-            template.setAttribute( "package", strPackage );
+            template.setAttribute( "package", defaultPackage );
 
-            sourceWriter.writeFile( modifiedName, template.toString(), strPackage );
+            sourceWriter.writeFile( modifiedName, template.toString(), defaultPackage );
 
             // the key should be the unaltered attributeName
-            attrNameToClassNameMap.put( name.toLowerCase(), strPackage + "." + modifiedName
);
+            attrNameToClassNameMap.put( name.toLowerCase(), defaultPackage + "." + modifiedName
);
 
             LOG.debug( "Completed source generation for Attribute '{}'", name );
         }
@@ -544,7 +554,9 @@
         Properties syntaxes = new Properties();
         syntaxes.load( SourceGenerator.class.getClassLoader().getResourceAsStream( "syntax.properties"
) );
 
-        SourceGenerator sg = new SourceGenerator( syntaxes );
+        File sourceRoot = new File( "/opt/workspace/apacheds-olm/target/generated-source"
);
+        SourceGenerator sg = new SourceGenerator( syntaxes, sourceRoot );
+        sg.setDefaultPackage( "org.apache.directory.olm" );
 
         boolean runTestSchema = false;
         if ( runTestSchema )
@@ -561,7 +573,13 @@
             schemas.add( "/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/core.schema"
);
             schemas.add( "/opt/workspace/apacheds/apacheds/schema-extras/src/main/schema/cosine.schema"
);
 
-            sg.loadSchema( schemas );
+            Set<File> schemaFiles = new HashSet<File>();
+            for( String s : schemas )
+            {
+                schemaFiles.add( new File( s ) );
+            }
+            
+            sg.loadSchema( schemaFiles );
             sg.generateSource();
         }
     }



Mime
View raw message