You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2008/10/22 20:07:54 UTC
svn commit: r707152 [1/2] - in /directory/sandbox/kayyagari/apacheds-olm: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/ src/main/java/org/apache/directory/olm/
src/main/java/org/apache...
Author: kayyagari
Date: Wed Oct 22 11:07:53 2008
New Revision: 707152
URL: http://svn.apache.org/viewvc?rev=707152&view=rev
Log:
initial checkin of the work done for a possible OLM solution.
This provides a POJO based persistence ( based on reverse engineering the LDAP schema of a target server )
Added:
directory/sandbox/kayyagari/apacheds-olm/
directory/sandbox/kayyagari/apacheds-olm/pom.xml
directory/sandbox/kayyagari/apacheds-olm/src/
directory/sandbox/kayyagari/apacheds-olm/src/main/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Attribute.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Entry.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/NameClassPair.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceFileWriter.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/AttributeFieldInterceptor.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/CodeEnhancer.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/EntryFieldInterceptor.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldFilter.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldInterceptor.java
directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/LdapPersistenceUtil.java
directory/sandbox/kayyagari/apacheds-olm/src/main/resources/
directory/sandbox/kayyagari/apacheds-olm/src/main/resources/AttributeClass.st
directory/sandbox/kayyagari/apacheds-olm/src/main/resources/ObjectClass.st
directory/sandbox/kayyagari/apacheds-olm/src/main/resources/syntax.properties
directory/sandbox/kayyagari/apacheds-olm/src/main/resources/test.schema
directory/sandbox/kayyagari/apacheds-olm/src/test/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/org/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/org/apache/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/org/apache/directory/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/org/apache/directory/olm/
directory/sandbox/kayyagari/apacheds-olm/src/test/java/org/apache/directory/olm/PojoPersistenceTest.java
directory/sandbox/kayyagari/apacheds-olm/src/test/resources/
directory/sandbox/kayyagari/apacheds-olm/src/test/resources/log4j.properties
Added: directory/sandbox/kayyagari/apacheds-olm/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/pom.xml?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/pom.xml (added)
+++ directory/sandbox/kayyagari/apacheds-olm/pom.xml Wed Oct 22 11:07:53 2008
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-parent</artifactId>
+ <version>1.5.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>apacheds-olm</artifactId>
+ <name>apacheds-olm</name>
+ <version>0.0.1-SNAPSHOT</version>
+ <description>Object LDAP Mapping</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-ldap</artifactId>
+ <version>0.9.13-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>antlr</groupId>
+ <artifactId>antlrall</artifactId>
+ <version>2.7.4</version>
+ </dependency>
+ <dependency>
+ <groupId>antlr</groupId>
+ <artifactId>stringtemplate</artifactId>
+ <version>2.3b6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-server-unit</artifactId>
+ <version>1.5.5-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <optimize>true</optimize>
+ <showDeprecations>true</showDeprecations>
+ <encoding>ISO-8859-1</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Attribute.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Attribute.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Attribute.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Attribute.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm;
+
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ *
+ * TODO Attribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface Attribute //extends java.io.Serializable
+{
+ /**
+ *
+ * Gives the name of the attribute
+ *
+ * @return the name of the attribute
+ */
+ String getAttrName();
+
+ /**
+ *
+ * gets the value of the attribute.
+ *
+ * @return value of the attribute
+ */
+ Object getAttrValue();
+
+
+ /**
+ *
+ * gets the syntax of the attribute.
+ *
+ * @return the syntax of the attribute, null if no syntax defined
+ */
+ String getSyntax();
+
+ /**
+ *
+ * gets all the values if the Attribute is multivalued.
+ *
+ * @return iterator values of the attribute
+ */
+ public Iterator getAttrValues();
+
+ boolean isObsolete();
+
+ boolean isSingleValue();
+
+ boolean isCollective();
+
+ boolean isNoUserModification();
+
+ String getOid();
+
+ Class getJavaType();
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Entry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Entry.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Entry.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/Entry.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm;
+
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+
+/**
+ *
+ * TODO Entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface Entry
+{
+
+ String getName();
+
+ String getOid();
+
+ Set<Attribute> getAttributes();
+
+ Attribute[] getAllAttributes();
+
+ ObjectClassTypeEnum getType();
+
+ String getDN();
+
+ void setDN( String dn );
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/NameClassPair.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/NameClassPair.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/NameClassPair.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/NameClassPair.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm;
+
+/**
+ *
+ * TODO NameClassPair.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NameClassPair implements Comparable
+{
+ private String name;
+ private String className;
+ private String javaType;
+
+ public NameClassPair( String name, String className, String javaType )
+ {
+ if( name == null || className == null || javaType == null )
+ {
+ throw new IllegalArgumentException( "Null value cannot be accepted" );
+ }
+
+ this.name = name;
+ this.className = className;
+ this.javaType = javaType;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+
+ public String getJavaType()
+ {
+ return javaType;
+ }
+
+ public String getClassSimpleName()
+ {
+ return className.substring( className.lastIndexOf( '.' ) + 1 );
+ }
+
+
+ public int compareTo( Object o )
+ {
+ NameClassPair that = ( NameClassPair ) o;
+
+ return getName().compareTo( that.getName() );
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ return getName().equals( ( ( NameClassPair ) obj ).getName() );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return name + "=" + className;
+ }
+
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceFileWriter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceFileWriter.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceFileWriter.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceFileWriter.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm;
+
+import java.io.File;
+import java.io.FileWriter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * TODO SourceFileWriter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SourceFileWriter
+{
+ private static File TARGET_ROOT;
+ private static final String COMMENT = "// generated by Apache Directory Object LDAP Mapping tool\n\n";
+
+ /** static logger */
+ private static final Logger LOG = LoggerFactory.getLogger( SourceFileWriter.class );
+
+ public SourceFileWriter( File targetRoot )
+ {
+ TARGET_ROOT = targetRoot;
+ }
+
+
+ public void writeFile( final String className, final String javaSource, final String strPackage ) throws Exception
+ {
+ File packgePath = null;
+
+ if( strPackage != null )
+ {
+ String pkDirPath = strPackage.replaceAll( "\\.", File.separator );
+ packgePath = new File( TARGET_ROOT, pkDirPath );
+
+ if( ! packgePath.exists() )
+ {
+ LOG.warn( "Creating package {} at {} ", strPackage, TARGET_ROOT );
+ packgePath.mkdirs();
+ }
+ }
+
+ packgePath = ( packgePath == null ? TARGET_ROOT : packgePath );
+
+ FileWriter fileWriter = new FileWriter( new File( packgePath, className + ".java" ) );
+
+ fileWriter.write( COMMENT );
+ fileWriter.write( javaSource );
+
+ fileWriter.close();
+ }
+}
Added: 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=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/SourceGenerator.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm;
+
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
+
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ *
+ * Generates source from the given schema(s)
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SourceGenerator
+{
+ private OpenLdapSchemaParser parser;
+ private Properties syntaxes;
+
+ private List<AttributeTypeLiteral> attrLiterals = new ArrayList<AttributeTypeLiteral>();
+ private List<ObjectClassLiteral> objClassLiterals = new ArrayList<ObjectClassLiteral>();
+
+ private static final String DEFAULT_SYNTAX_TYPE = "java.lang.String";
+
+ private SourceFileWriter sourceWriter;
+
+ private String strPackage = "org.apache.directory.olm";
+
+ private static final String MUST = "MUST";
+ private static final String MAY = "MAY";
+ private static final String OBJECTCLASS_FILE_SUFFIX = "Entry";
+
+ Map<String, String> attrNameToClassNameMap = new TreeMap<String, String>();
+ Map<String, String> attrNameToJavaTypeMap = new HashMap<String, String>();
+ Map<String, String> attrNameToSyntaxOidMap = new HashMap<String, String>();
+ Map<String, String> objClassToClassNameMap = new TreeMap<String, String>();
+
+ private File sourceRoot;
+
+ /** static logger */
+ private static final Logger LOG = LoggerFactory.getLogger( SourceGenerator.class );
+
+
+ public SourceGenerator( Properties syntaxes ) throws IOException
+ {
+ this.syntaxes = syntaxes;
+ parser = new OpenLdapSchemaParser();
+
+ sourceRoot = new File( "/opt/workspace/apacheds-olm/target/generated-source" );
+
+ if( ! sourceRoot.exists() )
+ {
+ sourceRoot.mkdirs();
+ }
+
+ sourceWriter = new SourceFileWriter( sourceRoot );
+ }
+
+
+ public void loadSchema( String schemaFilePath ) throws Exception
+ {
+ loadSchema( new File( schemaFilePath ) );
+ }
+
+
+ public void loadSchema( Set<String> schemaFilePaths ) throws Exception
+ {
+ for ( String schema : schemaFilePaths )
+ {
+ loadSchema( new File( schema ) );
+ }
+ }
+
+
+ public void loadSchema( File schemaFile ) throws Exception
+ {
+ parser.parse( schemaFile );
+
+ attrLiterals.addAll( parser.getAttributeTypes() );
+ objClassLiterals.addAll( parser.getObjectClassTypes() );
+ }
+
+
+ public void generateSource() throws Exception
+ {
+ LOG.debug( "Generating source..." );
+
+ for ( AttributeTypeLiteral attrLiteral : attrLiterals )
+ {
+ if ( attrLiteral.getEquality() == null )
+ {
+ LOG.debug( "Equality is null for " + attrLiteral.getNames()[0] + " ordering is : "
+ + attrLiteral.getOrdering() );
+
+ LOG.debug( "and substr is : " + attrLiteral.getSubstr() + "\n\n" );
+ }
+
+ if ( attrLiteral.getOid().equals( "2.5.4.45" ) )
+ {
+ System.out.println( "breakpoint" );
+ }
+ generateAttributeSource( attrLiteral );
+ }
+
+ for ( ObjectClassLiteral objClass : objClassLiterals )
+ {
+ if ( objClass.getOid().equals( "2.16.840.1.113730.3.2.2" ) )
+ {
+ System.out.println( "breakpoint" );
+ }
+
+ generateObjectClassSource( objClass );
+ }
+
+ writeNameClassMap();
+ }
+
+
+ private void writeNameClassMap() throws Exception
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "# Attribute name to fully qualified class name mappings \n\n" );
+
+ for( String attrName : attrNameToClassNameMap.keySet() )
+ {
+ sb.append( attrName )
+ .append( " = " )
+ .append( attrNameToClassNameMap.get( attrName ) )
+ .append( '\n' );
+ }
+
+ sb.append( "\n\n" );
+ sb.append( "# ObjectClass name to fully qualified class name mappings \n\n" );
+
+ for( String objClass : objClassToClassNameMap.keySet() )
+ {
+ sb.append( objClass )
+ .append( " = " )
+ .append( objClassToClassNameMap.get( objClass ) )
+ .append( '\n' );
+ }
+
+ File file = new File( sourceRoot, "classmapping.properties" );
+ FileWriter fwriter = new FileWriter( file );
+ fwriter.write( sb.toString() );
+ fwriter.close();
+ }
+
+
+ private void generateObjectClassSource( ObjectClassLiteral objClass ) throws Exception
+ {
+ String name = objClass.getNames()[0];
+
+ String modifiedName = name.replaceAll( "-", "_" );
+
+ LOG.debug( "Generating source for ObjectClass '{}'", modifiedName );
+
+ Map<String, Set<String>> attributesMap = new HashMap<String, Set<String>>();
+ Set<String> objClassSuperiors = new HashSet<String>();
+ getAttributesFromObjClass( objClass, attributesMap, objClassSuperiors );
+
+ Set<String> mustAttrs = attributesMap.get( MUST );
+ Set<String> mayAttrs = attributesMap.get( MAY );
+
+ Set<NameClassPair> mustAttrNameClassSet = new HashSet<NameClassPair>();
+ Set<NameClassPair> mayAttrNameClassSet = new HashSet<NameClassPair>();
+
+ StringTemplateGroup stgGroup = new StringTemplateGroup( "olm" );
+ StringTemplate template = stgGroup.getInstanceOf( "ObjectClass" );
+
+ for ( String s : mustAttrs )
+ {
+ mustAttrNameClassSet.add( new NameClassPair( s, attrNameToClassNameMap.get( s.toLowerCase() ), attrNameToJavaTypeMap.get( s.toLowerCase() ) ) );
+ }
+
+ for ( String s : mayAttrs )
+ {
+ //TODO remove this debug statement
+ LOG.debug( s + ": " + attrNameToClassNameMap.get( s.toLowerCase() ) );
+ NameClassPair np = new NameClassPair( s, attrNameToClassNameMap.get( s.toLowerCase() ), attrNameToJavaTypeMap.get( s.toLowerCase() ) );
+
+ mayAttrNameClassSet.add( np );
+ }
+
+ List<NameClassPair> allAttrList = new ArrayList<NameClassPair>();
+ allAttrList.addAll( mustAttrNameClassSet );
+ allAttrList.addAll( mayAttrNameClassSet );
+
+ template.setAttribute( "superiorClassNames", objClassSuperiors );
+ template.setAttribute( "allAttrs", allAttrList );
+
+ template.setAttribute( "mustAttrs", mustAttrNameClassSet );
+
+ template.setAttribute( "oid", objClass.getOid() );
+ template.setAttribute( "objClassName", objClass.getNames()[0] );
+ template.setAttribute( "classType", objClass.getClassType() );
+
+ modifiedName = String.valueOf( modifiedName.charAt( 0 ) ).toUpperCase() + modifiedName.substring( 1 )
+ + OBJECTCLASS_FILE_SUFFIX;
+
+ template.setAttribute( "className", modifiedName );
+ template.setAttribute( "package", strPackage );
+
+ if ( objClass.getClassType() != ObjectClassTypeEnum.STRUCTURAL )
+ {
+ template.setAttribute( "abstract", true );
+ }
+
+ sourceWriter.writeFile( modifiedName, template.toString(), strPackage );
+
+ // the key should be the unaltered attributeName
+ objClassToClassNameMap.put( name.toLowerCase(), strPackage + "." + modifiedName );
+
+ LOG.debug( "Completed source generation for ObjectClass '{}'", modifiedName );
+ }
+
+
+ private void getAttributesFromObjClass( ObjectClassLiteral objClass, Map<String, Set<String>> map, Set<String> objClassSuperiors )
+ throws Exception
+ {
+ String[] superClasses = objClass.getSuperiors();
+ if ( superClasses != null )
+ {
+ for ( String s : superClasses )
+ {
+ if ( s.equalsIgnoreCase( "top" ) )
+ {
+ continue;
+ }
+ objClassSuperiors.add( s );
+ getAttributesFromObjClass( getObjClassByName( s ), map, objClassSuperiors );
+ }
+ }
+
+ String[] mustAttrs = objClass.getMust();
+ String[] mayAttrs = objClass.getMay();
+
+ if ( mustAttrs != null )
+ {
+ Set<String> mustSet = map.get( MUST );
+
+ if ( mustSet == null )
+ {
+ mustSet = new HashSet<String>();
+ map.put( MUST, mustSet );
+ }
+
+ mustSet.addAll( Arrays.asList( mustAttrs ) );
+ }
+
+ if ( mayAttrs != null )
+ {
+ Set<String> maySet = map.get( MAY );
+
+ if ( maySet == null )
+ {
+ maySet = new HashSet<String>();
+ map.put( MAY, maySet );
+ }
+
+ maySet.addAll( Arrays.asList( mayAttrs ) );
+ }
+
+ }
+
+
+ private ObjectClassLiteral getObjClassByName( String name ) throws Exception
+ {
+ for ( ObjectClassLiteral obj : objClassLiterals )
+ {
+ String[] names = obj.getNames();
+ for ( String s : names )
+ {
+ if ( s.equalsIgnoreCase( name ) )
+ {
+ return obj;
+ }
+ }
+ }
+
+ throw new Exception( "No objectClass with the name '" + name + "' found" );
+ }
+
+
+ private AttributeTypeLiteral getSupAttribute( String supAttrName )
+ {
+ LOG.debug( "getting the SUP with name " + supAttrName );
+
+ for ( AttributeTypeLiteral attrLiteral : attrLiterals )
+ {
+ String[] names = attrLiteral.getNames();
+ for ( String name : names )
+ {
+ if ( supAttrName.equals( name ) )
+ {
+ return attrLiteral;
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ private void generateAttributeSource( AttributeTypeLiteral attrLiteral ) throws Exception
+ {
+ if ( attrLiteral.getSuperior() != null )
+ {
+ generateAttributeSource( getSupAttribute( attrLiteral.getSuperior() ) );
+ }
+
+ for ( String name : attrLiteral.getNames() )
+ {
+ LOG.debug( "Generating source for Attribute '{}'", name );
+
+ String modifiedName = name.replaceAll( "-", "_" );
+
+ StringTemplateGroup stgGroup = new StringTemplateGroup( "olm" );
+ StringTemplate template = stgGroup.getInstanceOf( "AttributeClass" );
+
+ if ( attrLiteral.getSyntax() == null )
+ {
+ template.setAttribute( "syntax", getSuperSyntax( attrLiteral ) );
+
+ template.setAttribute( "argType", DEFAULT_SYNTAX_TYPE );
+ attrNameToJavaTypeMap.put( name.toLowerCase(), DEFAULT_SYNTAX_TYPE );
+ }
+ 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() );
+ }
+
+ template.setAttribute( "paramName", modifiedName );
+
+ modifiedName = String.valueOf( modifiedName.charAt( 0 ) ).toUpperCase() + modifiedName.substring( 1 );
+ template.setAttribute( "className", modifiedName );
+ template.setAttribute( "mArgName", modifiedName );
+
+ template.setAttribute( "obsolete", attrLiteral.isObsolete() );
+ template.setAttribute( "singleValue", attrLiteral.isSingleValue() );
+ template.setAttribute( "collective", attrLiteral.isCollective() );
+ template.setAttribute( "noUserModification", attrLiteral.isNoUserModification() );
+
+ 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 );
+
+ sourceWriter.writeFile( modifiedName, template.toString(), strPackage );
+
+ // the key should be the unaltered attributeName
+ attrNameToClassNameMap.put( name.toLowerCase(), strPackage + "." + modifiedName );
+
+ LOG.debug( "Completed source generation for Attribute '{}'", name );
+ }
+ }
+
+
+ /**
+ *
+ * gets the syntax of a attribute by walking up the AttributeType hierarchy.
+ *
+ * @param attrLiteral
+ * @return
+ */
+ private String getSuperSyntax( AttributeTypeLiteral attrLiteral )
+ {
+ String superior = attrLiteral.getSuperior();
+ String syntax = "";
+
+ if( superior != null )
+ {
+ AttributeTypeLiteral superiorAttr = getSupAttribute( superior );
+ if( superiorAttr.getSyntax() != null )
+ {
+ syntax = superiorAttr.getSyntax();
+ }
+ else if( superiorAttr.getSuperior() != null )
+ {
+ getSuperSyntax( superiorAttr );
+ }
+ }
+
+ return syntax;
+ }
+
+
+ public static void main( String[] args ) throws Exception
+ {
+ Properties syntaxes = new Properties();
+ syntaxes.load( SourceGenerator.class.getClassLoader().getResourceAsStream( "syntax.properties" ) );
+
+ SourceGenerator sg = new SourceGenerator( syntaxes );
+
+ boolean runTestSchema = false;
+ if( runTestSchema )
+ {
+ sg.loadSchema( "src/main/resources/test.schema" );
+
+ }
+ else
+ {
+ Set<String> schemas = new HashSet<String>();
+ schemas.add( "/opt/workspace/apacheds/apacheds/schema-extras/src/main/schema/inetorgperson.schema" );
+ schemas.add( "/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/system.schema" );
+ schemas.add( "/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/apache.schema" );
+ 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 );
+ sg.generateSource();
+ }
+ }
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/AttributeFieldInterceptor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/AttributeFieldInterceptor.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/AttributeFieldInterceptor.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/AttributeFieldInterceptor.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+
+import net.sf.cglib.transform.impl.InterceptFieldEnabled;
+
+import org.apache.directory.olm.Attribute;
+import org.apache.directory.olm.Entry;
+
+
+public class AttributeFieldInterceptor extends FieldInterceptor
+{
+// private Map<String, Object> dirtyFieldMap = new HashMap<String, Object>();
+
+ private Entry entry;
+
+ public AttributeFieldInterceptor( Entry entry )
+ {
+ if( entry == null )
+ {
+ throw new IllegalArgumentException( "Entry cannot be null" );
+ }
+
+ this.entry = entry;
+ }
+
+// public boolean isDirty()
+// {
+// return ( ! dirtyFieldMap.isEmpty() );
+// }
+
+
+ protected void interceptWrite( Object obj, String name, Object oldValue, Object newValue )
+ {
+// System.out.println( "intercept attribute obj:" + obj + ", name: " + name + ", oldValue: " + oldValue + ", newValue: "
+// + newValue );
+// if ( ( ! dirtyFieldMap.containsKey( name ) ) && oldValue != newValue )
+// {
+// dirtyFieldMap.put( name, newValue );
+// }
+
+ EntryFieldInterceptor interceptor = ( EntryFieldInterceptor ) ( ( InterceptFieldEnabled ) entry ).getInterceptFieldCallback();
+
+ // this name is important to identify the modified field
+ name = ( ( Attribute ) obj ).getAttrName();
+
+ interceptor.interceptWrite( entry, name, obj, newValue );
+ }
+
+
+ @Override
+ protected void interceptRead( Object obj, String name, Object oldValue )
+ {
+ System.out.println( "interceptRead name: " + name + ", oldValue: " + oldValue );
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/CodeEnhancer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/CodeEnhancer.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/CodeEnhancer.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/CodeEnhancer.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.lang.reflect.Field;
+
+import net.sf.cglib.core.ClassGenerator;
+import net.sf.cglib.core.DebuggingClassWriter;
+import net.sf.cglib.transform.ClassReaderGenerator;
+import net.sf.cglib.transform.ClassTransformer;
+import net.sf.cglib.transform.ClassTransformerFactory;
+import net.sf.cglib.transform.TransformingClassGenerator;
+import net.sf.cglib.transform.impl.InterceptFieldEnabled;
+import net.sf.cglib.transform.impl.InterceptFieldTransformer;
+
+import org.apache.directory.olm.InetOrgPersonEntry;
+import org.objectweb.asm.Attribute;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * TODO CodeEnhancer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CodeEnhancer
+{
+
+ private static Logger LOG = LoggerFactory.getLogger( CodeEnhancer.class );
+
+ ClassTransformerFactory transformFactory = new ClassTransformerFactory()
+ {
+
+ public ClassTransformer newInstance()
+ {
+ return new InterceptFieldTransformer( new FieldFilter() );
+ }
+
+ };
+
+
+ protected ClassGenerator getGenerator( ClassReader r )
+ {
+// return new TransformingClassGenerator( new ClassReaderGenerator( r, attributes(), getFlags() ),
+// transformFactory.newInstance() );
+ return new TransformingClassGenerator( new ClassReaderGenerator( r, attributes(), getFlags() ), new InterceptFieldTransformer( new FieldFilter() ) );
+ }
+
+
+ protected int getFlags()
+ {
+ return 0;
+ }
+
+
+ protected Attribute[] attributes()
+ {
+ return null;
+ }
+
+
+ private void enhance( File classFile ) throws Exception
+ {
+ java.io.InputStream is = new FileInputStream( classFile ); //classPath.getResourceAsStream( name.replace( '.', '/' ) + ".class" );
+
+ if ( is == null )
+ {
+ throw new FileNotFoundException( classFile.getAbsolutePath() );
+ }
+
+ ClassReader r = new ClassReader( is );
+ is.close();
+
+ String[] interfaces = r.getInterfaces();
+
+ if( ! canEnhance( interfaces ) )
+ {
+ LOG.warn( "Neither an Entry nor an Attribute skipping enhancing" );
+ return;
+ }
+
+ if( isEnhanced( interfaces ) )
+ {
+ LOG.warn( "Skipping class {} as it was already enhanced.", classFile.getAbsolutePath() );
+ return;
+ }
+
+// if( isAttribute( interfaces ) )
+// {
+// LOG.warn( "TODO need to enance Attributes for dirty tracking of underlying collection of multi valued attributes." );
+// return;
+// }
+
+ ClassWriter w = new CustomDebuggingClassWriter( ClassWriter.COMPUTE_MAXS );
+ getGenerator( r ).generateClass( w );
+ byte[] b = w.toByteArray();
+
+ LOG.warn( "Writing enhanced class '{}' to file {}", classFile.getName(), classFile.getAbsolutePath() );
+
+ FileOutputStream fout = new FileOutputStream( classFile );
+ fout.write( b );
+ fout.close();
+ }
+
+
+ private boolean isEnhanced( String[] interfaces )
+ {
+ for( String s : interfaces )
+ {
+ s = s.replace( "/", "." );// class file doesn't contain a '.' in a FQCN
+ if( s.equals( "net.sf.cglib.transform.impl.InterceptFieldEnabled" ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ private boolean isAttribute( String[] interfaces )
+ {
+ for( String s : interfaces )
+ {
+ s = s.replace( "/", "." );// class file doesn't contain a '.' in a FQCN
+ if( s.equals( "org.apache.directory.olm.Attribute" ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean canEnhance( String[] interfaces )
+ {
+ boolean isAttribute = false;
+ boolean isEntry = false;
+
+ for( String s : interfaces )
+ {
+ s = s.replace( "/", "." );// class file doesn't contain a '.' in a FQCN
+ if( s.equals( "org.apache.directory.olm.Attribute" ) )
+ {
+ isAttribute = true;
+ }
+
+ if( s.equals( "org.apache.directory.olm.Entry" ) )
+ {
+ isEntry = true;
+ }
+ }
+
+ return ( isEntry || isAttribute );
+ }
+
+
+ public static void main( String[] args ) throws Exception
+ {
+ CodeEnhancer ce = new CodeEnhancer();
+
+ File rootDir = new File( "/opt/workspace/apacheds-olm/target/classes" );
+ ce.enhanceAll( rootDir.listFiles() );
+
+// String claz = InetOrgPersonEntry.class.getName().replace( ".", "/" ) + ".class";
+// claz = Cn.class.getName().replace( ".", "/" ) + ".class";
+// File classFile = new File( ce.getClass().getClassLoader().getSystemResource( claz ).getPath() );
+// ce.enhance( classFile );
+// ce.interceptPerson();
+ }
+
+
+ public void enhanceAll( File[] dirs ) throws Exception
+ {
+ for( File f : dirs )
+ {
+ if( f.isDirectory() )
+ {
+ enhanceAll( f.listFiles() );
+ }
+ else if( f.isFile() && f.getName().endsWith( ".class" ) )
+ {
+ enhance( f );
+ }
+ }
+ }
+
+
+ public void interceptPerson() throws Exception
+ {
+ InetOrgPersonEntry person = new InetOrgPersonEntry( "cn", "sn" );
+ ( ( InterceptFieldEnabled ) person ).setInterceptFieldCallback( new EntryFieldInterceptor() );
+ person.setCn( "cn" );
+ person.getCn().addValue( "xyz" );
+ person.setSn( "sn" );
+ person.setTelephoneNumber( "08855289560" );
+ person.setAudio( new byte[0] );
+
+ Field f = person.getClass().getDeclaredField( "dirty" );
+ f.setAccessible( true );
+ System.out.println( f.get( person ) );
+ f.set( person, true );
+ System.out.println( f.get( person ) );
+ }
+}
+
+class CustomDebuggingClassWriter extends DebuggingClassWriter
+{
+
+ public CustomDebuggingClassWriter( int flags )
+ {
+ super( flags );
+ }
+
+ @Override
+ public void visitEnd()
+ {
+ System.out.println( "visitEnd of custom writer" );
+ super.visitField( Opcodes.ACC_PRIVATE, "dirty", Type.getDescriptor( Boolean.class ), null, Boolean.FALSE ).visitEnd();
+ super.visitEnd();
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/EntryFieldInterceptor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/EntryFieldInterceptor.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/EntryFieldInterceptor.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/EntryFieldInterceptor.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.olm.Attribute;
+
+/**
+ *
+ * TODO EntryFieldInterceptor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryFieldInterceptor extends FieldInterceptor
+{
+ private Map<String, Attribute> dirtyAttrMap = new HashMap<String, Attribute>();
+
+ public boolean isDirty()
+ {
+ return ( ! dirtyAttrMap.isEmpty() );
+ }
+
+ protected void interceptWrite( Object obj, String name, Object oldValue, Object newValue )
+ {
+ System.out.println( "intercept obj:" + obj + ", name: " + name + ", oldValue: " + oldValue + ", newValue: "
+ + newValue );
+
+ if ( ( ! dirtyAttrMap.containsKey( name ) ) && oldValue != newValue )
+ {
+ dirtyAttrMap.put( name, ( Attribute ) oldValue );
+ }
+ }
+
+
+ public Map<String, Attribute> getDirtyAttrMap()
+ {
+ return dirtyAttrMap;
+ }
+
+
+ @Override
+ protected void interceptRead( Object obj, String name, Object oldValue )
+ {
+ System.out.println( "interceptRead name: " + name + ", oldValue: " + oldValue );
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldFilter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldFilter.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldFilter.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldFilter.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+
+import net.sf.cglib.transform.impl.InterceptFieldFilter;
+
+/**
+ *
+ * TODO FieldFilter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FieldFilter implements InterceptFieldFilter
+{
+
+ public boolean acceptRead( org.objectweb.asm.Type owner, String name )
+ {
+ return true;
+ }
+
+
+ public boolean acceptWrite( org.objectweb.asm.Type owner, String name )
+ {
+ return true;
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldInterceptor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldInterceptor.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldInterceptor.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/FieldInterceptor.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+
+import net.sf.cglib.transform.impl.InterceptFieldCallback;
+
+/**
+ *
+ * TODO FieldInterceptor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class FieldInterceptor implements InterceptFieldCallback
+{
+ protected abstract void interceptWrite( Object obj, String name, Object oldValue, Object newValue );
+ protected abstract void interceptRead( Object obj, String name, Object oldValue );
+
+ public boolean writeBoolean( Object obj, String name, boolean oldValue, boolean newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public byte writeByte( Object obj, String name, byte oldValue, byte newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public char writeChar( Object obj, String name, char oldValue, char newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public double writeDouble( Object obj, String name, double oldValue, double newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public float writeFloat( Object obj, String name, float oldValue, float newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public int writeInt( Object obj, String name, int oldValue, int newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public long writeLong( Object obj, String name, long oldValue, long newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public Object writeObject( Object obj, String name, Object oldValue, Object newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return newValue;
+ }
+
+
+ public short writeShort( Object obj, String name, short oldValue, short newValue )
+ {
+ interceptWrite( obj, name, oldValue, newValue );
+ return 0;
+ }
+
+
+ //------------------read methods-------------------
+
+ public boolean readBoolean( Object obj, String name, boolean oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public byte readByte( Object obj, String name, byte oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public char readChar( Object obj, String name, char oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public double readDouble( Object obj, String name, double oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public float readFloat( Object obj, String name, float oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public int readInt( Object obj, String name, int oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public long readLong( Object obj, String name, long oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public Object readObject( Object obj, String name, Object oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+
+ public short readShort( Object obj, String name, short oldValue )
+ {
+ interceptRead( obj, name, oldValue );
+ return oldValue;
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/LdapPersistenceUtil.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/LdapPersistenceUtil.java?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/LdapPersistenceUtil.java (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/olm/util/LdapPersistenceUtil.java Wed Oct 22 11:07:53 2008
@@ -0,0 +1,366 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.olm.util;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import net.sf.cglib.transform.impl.InterceptFieldEnabled;
+
+import org.apache.directory.olm.Attribute;
+import org.apache.directory.olm.Entry;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.entry.DefaultServerAttribute;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerModification;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.ObjectClassRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.server.schema.registries.SyntaxRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * TODO LdapPersistenceUtil.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapPersistenceUtil
+{
+ private CoreSession session;
+ private Registries registries;
+ private SyntaxRegistry syntaxRegistry;
+ private AttributeTypeRegistry attrRegistry;
+
+ private final static Properties NAME_CLASS_MAP = new Properties();
+
+ /** static logger */
+ private static final Logger LOG = LoggerFactory.getLogger( LdapPersistenceUtil.class );
+
+ static
+ {
+ try
+ {
+ InputStream in = LdapPersistenceUtil.class.getClassLoader().getResourceAsStream( "classmapping.properties" );
+ NAME_CLASS_MAP.load( in );
+ in.close();
+ }
+ catch( Exception e )
+ {
+ LOG.error( "could not load class mappings file classmapping.properties" );
+ }
+ }
+
+ public LdapPersistenceUtil(){}
+
+ public LdapPersistenceUtil( Registries registries, CoreSession session )
+ {
+ this.session = session;
+ this.registries = registries;
+ syntaxRegistry = registries.getSyntaxRegistry();
+ attrRegistry = registries.getAttributeTypeRegistry();
+ }
+
+
+ public void save( Entry entry ) throws Exception
+ {
+ ServerEntry serverEntry = new DefaultServerEntry( registries );
+
+ LdapDN dn = new LdapDN( entry.getDN() );
+ dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+
+ serverEntry.setDn( dn );
+ serverEntry.add( SchemaConstants.OBJECT_CLASS_AT, entry.getName() );
+
+ Set<Attribute> attributes = entry.getAttributes();
+ for( Attribute attr: attributes )
+ {
+ boolean isHr = syntaxRegistry.lookup( attr.getSyntax() ).isHumanReadable();
+ if( isHr )
+ {
+ if( attr.isSingleValue() )
+ {
+ serverEntry.add( attr.getAttrName(), String.valueOf( attr.getAttrValue() ) );
+ }
+ else
+ {
+ Iterator values = attr.getAttrValues();
+ if( values != null )
+ {
+ while( values.hasNext() )
+ {
+ Object v = values.next();
+ serverEntry.add( attr.getAttrName(), String.valueOf( v ) );
+ }
+ }
+ }
+ }
+ else
+ {
+ // assuming all non-HR values as byte[]
+ serverEntry.add( attr.getAttrName(), ( byte[] ) attr.getAttrValue() );
+ }
+ }
+
+ session.add( serverEntry );
+ }
+
+
+ public Entry fetch( String dn ) throws Exception
+ {
+ return fetch( new LdapDN( dn ) );
+ }
+
+ //FIXME need to support extensible objectclasses
+ public Entry fetch( LdapDN dn ) throws Exception
+ {
+ if( ! dn.isNormalized() )
+ {
+ dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ }
+
+ ClonedServerEntry clonedServerEntry = session.lookup( dn );
+
+ if( clonedServerEntry == null )
+ {
+ return null;
+ }
+
+ ServerEntry serverEntry = clonedServerEntry.getOriginalEntry();
+
+ EntryAttribute objectClassAttr = serverEntry.get( SchemaConstants.OBJECT_CLASS_AT );
+
+ Iterator<Value<?>> itr = objectClassAttr.iterator();
+
+ List<ObjectClass> ocList = new ArrayList<ObjectClass>();
+ List<String> ocNameList = new ArrayList<String>();
+
+ ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+
+ while( itr.hasNext() )
+ {
+ String objClassName = ( String ) itr.next().get();
+ ObjectClass oc = ocRegistry.lookup( objClassName );
+
+ if( oc.isStructural() )
+ {
+ ocList.add( oc );
+ ocNameList.add( objClassName.toLowerCase() );
+ }
+ }
+
+ for( ObjectClass oc : ocList )
+ {
+ if( oc.getSuperClasses() != null )
+ {
+ for( ObjectClass superOc : oc.getSuperClasses() )
+ {
+ if( superOc.isStructural() )
+ {
+ ocNameList.remove( superOc.getName().toLowerCase() );
+ }
+ }
+ }
+ }
+
+ System.out.println( "ocNameList: " + ocNameList );
+
+ Entry entry = ( Entry ) getClass( ocNameList.get( 0 ) ).newInstance();
+
+ entry.setDN( serverEntry.getDn().getUpName() );
+
+ Field[] fields = entry.getClass().getDeclaredFields();
+
+ Map<String,Field> nameToFieldMap = new HashMap<String,Field>();
+ for( Field f : fields )
+ {
+ f.setAccessible( true );
+ nameToFieldMap.put( f.getName().toLowerCase(), f );
+ }
+
+ Set<AttributeType> attrTypes = serverEntry.getAttributeTypes();
+ for( EntryAttribute attr : serverEntry )
+ {
+ Field f = nameToFieldMap.get( attr.getId() );
+
+ if( f == null )
+ {
+ continue;
+ }
+
+ Attribute olmAttr = ( Attribute ) f.get( entry );
+
+ if( olmAttr == null )
+ {
+ olmAttr = ( Attribute ) Class.forName( f.getType().getName() ).newInstance();
+ }
+
+ if( attr.isHR() )
+ {
+ if( ! registries.getAttributeTypeRegistry().lookup( attr.getId() ).isSingleValue() )
+ {
+ Iterator<Value<?>> values = attr.getAll();
+
+ Set set = new HashSet();
+ while( values.hasNext() )
+ {
+ set.add( values.next().get() );
+ }
+
+ // java.util.Set is the common container for all the multi valued attribute values
+ olmAttr.getClass().getDeclaredMethod( "setValues", Set.class ).invoke( olmAttr, set );
+ }
+ else
+ {
+ olmAttr.getClass().getDeclaredMethod( "setValue", olmAttr.getJavaType() ).invoke( olmAttr, attr.get().get() );
+ }
+ ( ( InterceptFieldEnabled ) olmAttr ).setInterceptFieldCallback( new AttributeFieldInterceptor( entry ) );
+ f.set( entry, olmAttr );
+ }
+ }
+
+ ( ( InterceptFieldEnabled ) entry ).setInterceptFieldCallback( new EntryFieldInterceptor() );
+ return entry;
+ }
+
+
+ public void update( Entry entry ) throws Exception
+ {
+ ServerEntry serverEntry = new DefaultServerEntry( registries );
+
+ LdapDN dn = new LdapDN( entry.getDN() );
+ dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+
+ serverEntry.setDn( dn );
+// serverEntry.add( SchemaConstants.OBJECT_CLASS_AT, entry.getName() );
+
+ EntryFieldInterceptor interceptor = ( EntryFieldInterceptor ) ( ( InterceptFieldEnabled ) entry ).getInterceptFieldCallback();
+
+ if( ! interceptor.isDirty() )
+ {
+ LOG.debug( "None of the Attributes of Entry changed no need to update" );
+ return;
+ }
+
+ List<Modification> modList = new ArrayList<Modification>();
+
+ Map<String, Attribute> dirtyMap = interceptor.getDirtyAttrMap();
+ Class entryClass = entry.getClass();
+
+ for( String fieldName : dirtyMap.keySet() )
+ {
+ Field f = entryClass.getDeclaredField( fieldName );
+ // TODO need to remove this if block, this is for finding errors related to fieldnames during development
+ if( f == null )
+ {
+ throw new Exception( "Attribute field not found with name " + fieldName );
+ }
+
+ f.setAccessible( true );
+
+ Attribute newAttr = ( Attribute ) f.get( entry );
+ Attribute oldAttr = dirtyMap.get( fieldName );
+
+ if( newAttr == null ) // remove
+ {
+ EntryAttribute tmpAttr = convertToEntryAttribute( oldAttr );
+ Modification mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, tmpAttr );
+ modList.add( mod );
+ }
+ else if( oldAttr != null && newAttr != null ) // replace
+ {
+ // TODO need to have an efficient way to calculate delta of differences
+ // for performing the update operation currently it send the whole attribute
+ EntryAttribute tmpAttr = convertToEntryAttribute( newAttr );
+ Modification mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, tmpAttr );
+ modList.add( mod );
+ }
+ else if( oldAttr == null ) // add
+ {
+ EntryAttribute tmpAttr = convertToEntryAttribute( newAttr );
+ Modification mod = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, tmpAttr );
+ modList.add( mod );
+ }
+ }
+
+ session.modify( dn, modList );
+ }
+
+
+
+ private EntryAttribute convertToEntryAttribute( Attribute attr ) throws Exception
+ {
+ if( attr == null )
+ {
+ return null;
+ }
+
+ EntryAttribute entryAttr = new DefaultServerAttribute( attrRegistry.lookup( attr.getAttrName() ) );
+
+ if( syntaxRegistry.lookup( attr.getSyntax() ).isHumanReadable() )
+ {
+ if( attr.isSingleValue() )
+ {
+ entryAttr.add( String.valueOf( attr.getAttrValue() ) );
+ }
+ else
+ {
+ Iterator itr = attr.getAttrValues();
+ while( itr.hasNext() )
+ {
+ entryAttr.add( String.valueOf( itr.next() ) );
+ }
+ }
+ }
+ else
+ {
+ entryAttr.add( ( byte[] ) attr.getAttrValue() );
+ }
+
+ return entryAttr;
+ }
+
+
+ private Class getClass( String propName ) throws Exception
+ {
+ String className = NAME_CLASS_MAP.getProperty( propName );
+ return Class.forName( className );
+ }
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/resources/AttributeClass.st
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/resources/AttributeClass.st?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/resources/AttributeClass.st (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/resources/AttributeClass.st Wed Oct 22 11:07:53 2008
@@ -0,0 +1,177 @@
+$!/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */!$
+package $package$;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class $className$ implements Attribute
+{
+
+ // if no syntax or matching rule is defined then the default argument type will be java.lang.String
+
+ private $argType$ $paramName$;
+
+ private Set<$argType$> _attrValues;
+
+ private boolean obsolete = $obsolete$;
+ private boolean singleValue = $singleValue$;
+ private boolean collective = $collective$;
+ private boolean noUserModification = $noUserModification$;
+
+ public static final String OID = "$oid$";
+
+ //TODO
+ // may be here needs a reference to the corresponding object class to apply the changes done to this
+ // attribute transparently. This reference should be injected at runtime through byte code manipulation
+
+ // TODO this constructor needs to be dynamically injected
+ public $className$() {}
+
+ public $className$( $argType$ $paramName$ )
+ {
+ $if(singleValue)$
+ $!set$mArgName$( $paramName$ );!$
+ setValue( $paramName$ );
+ $else$
+ this.$paramName$ = $paramName$;
+ addValue( this.$paramName$ );
+ $endif$
+ }
+
+
+ $if(singleValue)$
+ public void setValue( $argType$ $paramName$ )
+ {
+ if( $paramName$ == null )
+ {
+ throw new IllegalArgumentException( "Attribute value cannot be null" );
+ }
+
+ this.$paramName$ = $paramName$;
+ }
+
+
+ $!public $argType$ get$mArgName$()
+ {
+ return $paramName$;
+ }!$
+ $else$
+ public void setValues( Set<$argType$> _attrValues )
+ {
+ if( _attrValues == null )
+ {
+ throw new IllegalArgumentException( "Attribute values cannot be null" );
+ }
+
+ this._attrValues = _attrValues;
+ }
+
+ public void addValue( $argType$ $paramName$ )
+ {
+ if( $paramName$ == null )
+ {
+ throw new IllegalArgumentException( "Attribute value cannot be null" );
+ }
+
+ if( _attrValues == null )
+ {
+ _attrValues = new HashSet<$argType$>();
+ }
+
+ _attrValues.add( $paramName$ );
+
+ // for enabling the field interception
+ Set set = new HashSet<java.lang.String>();
+ set.addAll( _attrValues );
+ _attrValues = set;
+ }
+ $endif$
+
+ public boolean isObsolete()
+ {
+ return obsolete;
+ }
+
+
+ public boolean isSingleValue()
+ {
+ return singleValue;
+ }
+
+
+ public boolean isCollective()
+ {
+ return collective;
+ }
+
+
+ public boolean isNoUserModification()
+ {
+ return noUserModification;
+ }
+
+
+ public String getOid()
+ {
+ return OID;
+ }
+
+
+ public String getAttrName()
+ {
+ return "$paramName$";
+ }
+
+
+ public String getSyntax()
+ {
+ $if(syntax)$
+ return "$syntax$";
+ $else$
+ return null;
+ $endif$
+ }
+
+
+ public Class getJavaType()
+ {
+ return $argType$.class;
+ }
+
+
+ public Object getAttrValue()
+ {
+ return $paramName$;
+ }
+
+
+ public Iterator<$argType$> getAttrValues()
+ {
+ if( _attrValues == null )
+ {
+ return null;
+ }
+
+ return _attrValues.iterator();
+ }
+
+}
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/resources/ObjectClass.st
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/resources/ObjectClass.st?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/resources/ObjectClass.st (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/resources/ObjectClass.st Wed Oct 22 11:07:53 2008
@@ -0,0 +1,113 @@
+$!/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */!$
+package $package$;
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import java.util.Set;
+import java.util.HashSet;
+
+public $if(abstract)$ abstract $endif$ class $className$ implements Entry
+{
+ $allAttrs: { attr | private $attr.className$ $attr.name$;}; separator="\n\n"$
+
+ private String dn;
+
+ private String[] objClassSuperiors = { $superiorClassNames: { s | "$s$"}; separator=", "$ };
+
+ public $className$() { }
+
+ $if(mustAttrs)$
+ public $className$( $mustAttrs: { attr | $attr.javaType$ $attr.name$};separator=", "$ )
+ {
+ $mustAttrs: { attr | set$attr.classSimpleName$( $attr.name$ );}; separator="\n"$
+ }
+ $endif$
+
+
+ $allAttrs: { attr | public void set$attr.classSimpleName$( $attr.javaType$ $attr.name$ )
+ {
+ this.$attr.name$ = new $attr.className$( $attr.name$ );
+ }
+
+
+ public $attr.className$ get$attr.classSimpleName$()
+ {
+ return $attr.name$;
+ }
+ }$
+
+
+ public String getName()
+ {
+ return "$objClassName$";
+ }
+
+
+ public String getOid()
+ {
+ return "$oid$";
+ }
+
+ public ObjectClassTypeEnum getType()
+ {
+ return ObjectClassTypeEnum.$classType$;
+ }
+
+ public Set<Attribute> getAttributes()
+ {
+ Attribute[] attributes = { $allAttrs: { attr | $attr.name$}; separator=", "$ };
+
+ Set<Attribute> allAttrs = new HashSet<Attribute>();
+
+ for ( int i=0; i < attributes.length; i++ )
+ {
+ if( attributes[ i ] != null )
+ {
+ allAttrs.add( attributes[ i ] );
+ }
+ }
+
+ return allAttrs;
+ }
+
+ public Attribute[] getAllAttributes()
+ {
+ Attribute[] attributes = { $allAttrs: { attr | $attr.name$}; separator=", "$ };
+
+ return attributes;
+ }
+
+
+ public void setDN( String dn )
+ {
+ if( dn == null )
+ {
+ throw new IllegalArgumentException( "DN value cannot be null" );
+ }
+
+ this.dn = dn;
+ }
+
+
+ public String getDN()
+ {
+ return dn;
+ }
+}
\ No newline at end of file
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/resources/syntax.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/resources/syntax.properties?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/resources/syntax.properties (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/resources/syntax.properties Wed Oct 22 11:07:53 2008
@@ -0,0 +1,352 @@
+==============================================
+ system
+==============================================
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.48 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.55 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.11 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.49 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.38 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.13 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.57 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.35 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.21 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.52 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.43 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.1 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.59 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.22 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.37 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.44 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.3 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.15 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.56 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.12 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.45 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.34 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.2 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.23 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.8 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.53 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.42 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.47 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.19 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.32 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.41 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.33 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.26 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.40 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.6 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.39 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.16 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.17 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.7 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.27 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.24 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.46 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.4 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.58 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.30 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.9 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.36 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.14 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.51 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.18 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.28 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.50 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.29 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.20 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.31 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.5 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.10 = byte[]
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.25 = java.lang.String
+
+#Name: null
+#Desc: null
+#Schema: system
+1.3.6.1.4.1.1466.115.121.1.54 = java.lang.String
+
+==============================================
+ apache
+==============================================
+
+#Name: null
+#Desc: a syntax for java int values
+#Schema: apache
+1.3.6.1.4.1.18060.0.4.1.0.4 = java.lang.String
+
+#Name: null
+#Desc: a syntax for java byte values
+#Schema: apache
+1.3.6.1.4.1.18060.0.4.1.0.0 = java.lang.String
+
+#Name: null
+#Desc: a syntax for java long values
+#Schema: apache
+1.3.6.1.4.1.18060.0.4.1.0.3 = java.lang.String
+
+#Name: null
+#Desc: a syntax for java short values
+#Schema: apache
+1.3.6.1.4.1.18060.0.4.1.0.2 = java.lang.String
+
+==============================================
+ apachemeta
+==============================================
+
+#Name: null
+#Desc: The syntax for numericoids.
+#Schema: apachemeta
+1.3.6.1.4.1.18060.0.4.0.0.2 = java.lang.String
+
+#Name: null
+#Desc: The syntax for object names.
+#Schema: apachemeta
+1.3.6.1.4.1.18060.0.4.0.0.6 = java.lang.String
+
+#Name: null
+#Desc: The syntax for either numeric ids or names.
+#Schema: apachemeta
+1.3.6.1.4.1.18060.0.4.0.0.0 = java.lang.String
+
+#Name: null
+#Desc: The syntax for numeric strings.
+#Schema: apachemeta
+1.3.6.1.4.1.18060.0.4.0.0.4 = java.lang.String
+
+#Name: null
+#Desc: The syntax for either numeric ids or names.
+#Schema: apachemeta
+1.3.6.1.4.1.18060.0.4.0.0.1 = java.lang.String
+
Added: directory/sandbox/kayyagari/apacheds-olm/src/main/resources/test.schema
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/resources/test.schema?rev=707152&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/resources/test.schema (added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/resources/test.schema Wed Oct 22 11:07:53 2008
@@ -0,0 +1,37 @@
+attributetype ( 2.5.4.41 NAME 'name'
+ DESC 'RFC2256: common supertype of name attributes'
+ EQUALITY caseIgnoreMatch
+ SUBSTR caseIgnoreSubstringsMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
+
+attributetype ( 2.5.4.3 NAME ( 'cn' 'commonName' )
+ DESC 'RFC2256: common name(s) for which the entity is known by'
+ SUP name )
+
+attributetype ( 2.5.4.5 NAME ( 'xn' )
+ DESC 'testing another level of inheritance by extending already extended attributetype'
+ SUP cn
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{12} )
+
+attributetype ( 2.5.4.6 NAME ( 'yn' )
+ DESC 'testing another level of inheritance by extending already extended attributetype'
+ SUP cn
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{12} )
+
+attributetype ( 2.5.4.7 NAME ( 'zn' )
+ DESC 'testing another level of inheritance by extending already extended attributetype'
+ SUP cn
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{12} )
+
+objectclass ( 2.5.17.0 NAME 'xxx'
+ SUP top
+ STRUCTURAL
+ MUST ( yn )
+ MAY ( zn ) )
+
+objectclass ( 2.5.17.1 NAME 'subentry'
+ SUP xxx
+ STRUCTURAL
+ MUST ( cn )
+ MAY ( xn ) )
+
\ No newline at end of file