You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2010/08/28 22:04:26 UTC
svn commit: r990428 [1/3] - in
/directory/sandbox/studio-persistence-tooling: ./ persistence-core/
persistence-core/src/ persistence-core/src/main/
persistence-core/src/main/java/ persistence-core/src/main/java/org/
persistence-core/src/main/java/org/a...
Author: seelmann
Date: Sat Aug 28 20:04:24 2010
New Revision: 990428
URL: http://svn.apache.org/viewvc?rev=990428&view=rev
Log:
Import GSoC 2010 work of Kasun Lakpriya
Added:
directory/sandbox/studio-persistence-tooling/
directory/sandbox/studio-persistence-tooling/persistence-core/
directory/sandbox/studio-persistence-tooling/persistence-core/pom.xml
directory/sandbox/studio-persistence-tooling/persistence-core/src/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Activator.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Cardinality.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGenerator.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGeneratorContext.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/EntryProperties.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/GeneratorUtility.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaType.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaUtils.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzer.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/SchemaUtils2.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/dao_template.vm
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/genericLdapDao_template.vm
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/java_template.vm
directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/velocity.properties
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/CodeGenIntegrationTest.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/CodeGeneratorTest.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/JavaUtilsTest.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzerTest.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/java/org/apache/directory/studio/persistence/core/SchemaUtilsTest.java
directory/sandbox/studio-persistence-tooling/persistence-core/src/test/resources/
directory/sandbox/studio-persistence-tooling/persistence-example/
directory/sandbox/studio-persistence-tooling/persistence-example/pom.xml
directory/sandbox/studio-persistence-tooling/persistence-example/src/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/dao/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/dao/GenericLdapDao.java
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/dao/InetOrgPersonDao.java
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/domain/
directory/sandbox/studio-persistence-tooling/persistence-example/src/main/java/com/example/domain/InetOrgPerson.java
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/java/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/java/com/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/java/com/example/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/java/com/example/dao/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/java/com/example/dao/InetOrgPersonDaoTest.java
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/resources/
directory/sandbox/studio-persistence-tooling/persistence-example/src/test/resources/log4j.properties
directory/sandbox/studio-persistence-tooling/persistence-ui/
directory/sandbox/studio-persistence-tooling/persistence-ui/plugin.xml
directory/sandbox/studio-persistence-tooling/persistence-ui/pom.xml
directory/sandbox/studio-persistence-tooling/persistence-ui/src/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/ui/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/ui/Activator.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/ui/actions/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/ui/actions/NewAction.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/AddMembersWizardPage.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/AttributeEditingSupport.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/DaoRequiredParametersWizardPage.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/EntryContentProvider.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/EntryLabelProvider.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/NewPersistenceCodeWizard.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/NewPersistenceCodeWizardPage.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/java/org/apache/directory/studio/persistence/view/wizards/TableColumnSorter.java
directory/sandbox/studio-persistence-tooling/persistence-ui/src/main/resources/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/test/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/test/java/
directory/sandbox/studio-persistence-tooling/persistence-ui/src/test/resources/
directory/sandbox/studio-persistence-tooling/pom.xml
Added: directory/sandbox/studio-persistence-tooling/persistence-core/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/pom.xml?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/pom.xml (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/pom.xml Sat Aug 28 20:04:24 2010
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ 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.
+ -->
+ <!--
+ @author <a href="mailto:dev@directory.apache.org">Apache Directory
+ Project</a>
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>persistence-parent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>persistence.core</artifactId>
+ <name>Apache Directory Studio LDAP Persistence Tooling Core</name>
+
+ <description />
+
+
+
+ <build>
+ <resources>
+ <resource>
+ <directory>.</directory>
+ <includes>
+ <include>plugin*.properties</include>
+ <include>plugin.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ <pde>true</pde>
+ <additionalProjectnatures>
+ <projectnature>org.eclipse.pde.PluginNature</projectnature>
+ <projectnature>org.eclipse.jdt.core.javanature</projectnature>
+ </additionalProjectnatures>
+ <classpathContainers>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ <classpathContainer>org.eclipse.jdt.junit.JUNIT_CONTAINER/4.5</classpathContainer>
+ <classpathContainer>org.eclipse.pde.core.requiredPlugins</classpathContainer>
+ </classpathContainers>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>studio-maven-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ <createManifest>true</createManifest>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>prepare-jar-package</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>META-INF/MANIFEST.MF</manifestFile>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ </archive>
+ </configuration>
+ </plugin>
+ <!-- MANIFEST.MF Generation -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <manifestLocation>META-INF</manifestLocation>
+ <instructions>
+ <Bundle-SymbolicName>${project.groupId}.${project.artifactId};singleton:=true</Bundle-SymbolicName>
+ <Bundle-Localization>plugin</Bundle-Localization>
+ <Eclipse-LazyStart>true</Eclipse-LazyStart>
+ <Bundle-Activator>org.apache.directory.studio.persistence.core.Activator</Bundle-Activator>
+ <Require-Bundle>org.eclipse.core.runtime,
+ org.eclipse.search,
+ org.apache.directory.studio.jars,
+ org.apache.directory.studio.ldifparser,
+ org.apache.directory.studio.connection.core,
+ org.apache.directory.studio.ldapbrowser.core
+ </Require-Bundle>
+ <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
+ <Embed-Directory>lib</Embed-Directory>
+ <Embed-StripGroup>true</Embed-StripGroup>
+ <Export-Package>org.apache.directory.studio.persistence.core.*</Export-Package>
+ <Import-Package>!</Import-Package>
+ <Private-Package>!</Private-Package>
+ </instructions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- Apache Directory Studio plugins dependencies -->
+ <dependency>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>ldapbrowser.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>jars</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>ldifparser</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.studio</groupId>
+ <artifactId>connection.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Eclipse plugins dependencies -->
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>jobs</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>runtime</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>common</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>preferences</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- JUnit for test only -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock.modules</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock.api</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Activator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Activator.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Activator.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Activator.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * The activator class controls the plug-in life cycle.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class Activator extends Plugin
+{
+
+ /** The plug-in ID */
+ public static final String PLUGIN_ID = "org.apache.directory.studio.persistence.core";
+
+ /** The shared instance */
+ private static Activator plugin;
+
+
+ /**
+ * The constructor
+ */
+ public Activator()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start( BundleContext context ) throws Exception
+ {
+ super.start( context );
+ plugin = this;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop( BundleContext context ) throws Exception
+ {
+ plugin = null;
+ super.stop( context );
+ }
+
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault()
+ {
+ return plugin;
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Cardinality.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Cardinality.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Cardinality.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/Cardinality.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,115 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.ArrayUtils;
+
+
+/**
+ * This is a Enum to keep track of Cardinality of an attribute
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum Cardinality
+{
+ ZERO_OR_ONE,
+
+ ONE,
+
+ ZERO_OR_MANY_SET,
+
+ ZERO_OR_MANY_LIST,
+
+ ZERO_OR_MANY_ARRAY,
+
+ ONE_OR_MANY_SET,
+
+ ONE_OR_MANY_LIST,
+
+ ONE_OR_MANY_ARRAY;
+
+ /**
+ * Check if the given cardinality is of the type array
+ *
+ * @param cardinality the cardinality of an attribute
+ * @return true if the given cardinality is of the type array
+ * if not false
+ */
+ public static boolean isArray( Cardinality cardinality )
+ {
+ if ( cardinality == Cardinality.ONE_OR_MANY_ARRAY || cardinality == Cardinality.ZERO_OR_MANY_ARRAY )
+ {
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+ /**
+ * Check if the given cardinality is of the type Set
+ *
+ * @param cardinality the cardinality of an entry
+ * @return true if the given cardinality is of the type Set
+ * if not false
+ */
+ public static boolean isSet( Cardinality cardinality )
+ {
+ if ( cardinality == Cardinality.ONE_OR_MANY_SET || cardinality == Cardinality.ZERO_OR_MANY_SET )
+ {
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+ /**
+ * Check if the given cardinality is of the type List
+ *
+ * @param cardinality the cardinality of an entry
+ * @return true if the given cardinality is of the type List
+ * if not false
+ */
+ public static boolean isList( Cardinality cardinality )
+ {
+ if ( cardinality == Cardinality.ONE_OR_MANY_LIST || cardinality == Cardinality.ZERO_OR_MANY_LIST )
+ {
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+ public static String[] getStrings()
+ {
+ List<String> strings = new ArrayList<String>();
+ for ( Cardinality value : values() )
+ {
+ strings.add( value.toString() );
+ }
+ return strings.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
+ }
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGenerator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGenerator.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGenerator.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGenerator.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,353 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.Template;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+
+public class CodeGenerator
+{
+ Collection<String> imports;
+
+
+ /**
+ * This is the method responsible for generating Java bean code from a analyzed entry
+ * in LDAP directory
+ *
+ * @param generatorContext the object with all required information about
+ * the entry to generate the Java bean class code
+ * @param templateFile the Apache Velocity template to be used to generate
+ * Java bean code for the selected entry
+ */
+ public void generateCode( CodeGeneratorContext generatorContext, String templateFile )
+ {
+ GeneratorUtility utility = new GeneratorUtility();
+ generateClassTemplate( generatorContext );
+ try
+ {
+ Properties properties = new Properties();
+ properties.load( getClass().getResourceAsStream( "/velocity.properties" ) );
+ Velocity.init( properties );
+ VelocityContext context = new VelocityContext();
+ context.put( "package", generatorContext.getPackageName() );
+ context.put( "class", generatorContext.getClassName() );
+ context.put( "utility", utility );
+ context.put( "imports", imports );
+ context.put( "entryProps", generateClassTemplate( generatorContext ) );
+
+ Template template = null;
+ try
+ {
+ template = Velocity.getTemplate( templateFile );
+ }
+ catch ( ResourceNotFoundException rnfe )
+ {
+ System.out.println( "CodeGenerator : error : cannot find template " + templateFile );
+ }
+ catch ( ParseErrorException pee )
+ {
+ System.out.println( "CodeGenerator : Syntax error in template " + templateFile );
+ }
+ String path = generatorContext.getProjectFolderPath() + "/"
+ + generatorContext.getPackageName().replace( ".", "/" );
+ new File( path ).mkdirs();
+ File javaFile = new File( path + "/" + generatorContext.getClassName() + ".java" );
+ BufferedWriter writer = new BufferedWriter( new FileWriter( javaFile ) );
+ if ( template != null )
+ template.merge( context, writer );
+ writer.flush();
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e );
+ }
+ }
+
+
+ /**
+ * This generates the Dao class for the bean class generated for an entry
+ *
+ * @param generatorContext the object with all required information about
+ * the entry to generate the Dao class for bean generated from an entry
+ * @param templateFile the Apache Velocity template to be used to generate
+ * Dao class
+ */
+ public void generateDaoCode( CodeGeneratorContext generatorContext, String templateFile )
+ {
+ GeneratorUtility utility1 = new GeneratorUtility();
+ generateClassTemplate( generatorContext );
+ try
+ {
+ Properties properties = new Properties();
+ properties.load( getClass().getResourceAsStream( "/velocity.properties" ) );
+ Velocity.init( properties );
+ VelocityContext context = new VelocityContext();
+ context.put( "package", generatorContext.getPackageName() );
+ context.put( "utility", utility1 );
+ context.put( "generator", generatorContext );
+ context.put( "entryProps", generateClassTemplate( generatorContext ) );
+ Template template = null;
+ try
+ {
+ template = Velocity.getTemplate( templateFile );
+ }
+ catch ( ResourceNotFoundException rnfe )
+ {
+ System.out.println( "CodeGenerator : error : cannot find template " + templateFile );
+ }
+ catch ( ParseErrorException pee )
+ {
+ System.out.println( "CodeGenerator : Syntax error in template " + templateFile );
+ }
+ String path = generatorContext.getProjectFolderPath() + "/"
+ + generatorContext.getPackageName().replace( ".", "/" );
+ new File( path + "/dao" ).mkdirs();
+ File javaFile = new File( path + "/dao/" + generatorContext.getClassName() + "Dao.java" );
+ BufferedWriter writer = new BufferedWriter( new FileWriter( javaFile ) );
+ if ( template != null )
+ template.merge( context, writer );
+ writer.flush();
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e );
+ }
+ }
+
+
+ /**
+ * This generates the GenericLdapDao abstract class and all the Dao classes generated
+ * are inherited from this one
+ *
+ * @param generatorContext the object with all required information about
+ * the entry to generate the JGenericLdapDao class
+ * @param templateFile the Apache Velocity template to be used to generate
+ * GenericLdapDao code for the selected entry
+ */
+ public void generateGenericDaoCode( CodeGeneratorContext generatorContext, String templateFile )
+ {
+ GeneratorUtility utility1 = new GeneratorUtility();
+ generateClassTemplate( generatorContext );
+ try
+ {
+ Properties properties = new Properties();
+ properties.load( getClass().getResourceAsStream( "/velocity.properties" ) );
+ Velocity.init( properties );
+ VelocityContext context = new VelocityContext();
+ context.put( "package", generatorContext.getPackageName() );
+ context.put( "utility", utility1 );
+ context.put( "generator", generatorContext );
+ Template template = null;
+ try
+ {
+ template = Velocity.getTemplate( templateFile );
+ }
+ catch ( ResourceNotFoundException rnfe )
+ {
+ System.out.println( "CodeGenerator : error : cannot find template " + templateFile );
+ }
+ catch ( ParseErrorException pee )
+ {
+ System.out.println( "CodeGenerator : Syntax error in template " + templateFile );
+ }
+ String path = generatorContext.getProjectFolderPath() + "/"
+ + generatorContext.getPackageName().replace( ".", "/" );
+ new File( path + "/dao" ).mkdirs();
+ File javaFile = new File( path + "/dao/" + "GenericLdapDao.java" );
+ BufferedWriter writer = new BufferedWriter( new FileWriter( javaFile ) );
+ if ( template != null )
+ template.merge( context, writer );
+ writer.flush();
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e );
+ }
+ }
+
+ /**
+ * Setup the EntryProperties objects with appropriate writtenJavaType,
+ * writtenMapFromEntry and writtenMapToEntry values. But this method logic
+ * should be moved in to velocity templates later
+ *
+ * @param generatorContext the generator
+ * @return the list of EntryProperties to be generated
+ */
+ public List<EntryProperties> generateClassTemplate( CodeGeneratorContext generatorContext )
+ {
+ List<EntryProperties> entryDetails = new ArrayList<EntryProperties>();
+ for ( EntryProperties entryProperty : generatorContext.getEntryProperties() )
+ {
+ if ( entryProperty.isGen() == true )
+ {
+ entryDetails.add( entryProperty );
+ }
+ }
+ collectImports( entryDetails );
+ for ( EntryProperties properties : entryDetails )
+ {
+ Cardinality cardinality = properties.getCardinality();
+ JavaType javaType = properties.getJavaType();
+ if ( cardinality == Cardinality.ONE || cardinality == Cardinality.ZERO_OR_ONE )
+ {
+ if ( javaType == JavaType.BYTE_ARRAY )
+ {
+ properties.setWrittenJavaType( properties.getJavaType().toString() );
+ properties.setWrittenMapFromEntry( "getBytes" );
+ properties.setWrittenMapToEntry( "setBytes" );
+ }
+ else if ( javaType == JavaType.CALENDAR )
+ {
+ properties.setWrittenJavaType( properties.getJavaType().toString() );
+ properties.setWrittenMapFromEntry( "getCalendar" );
+ properties.setWrittenMapToEntry( "setCalendar" );
+ }
+ else
+ {
+ properties.setWrittenJavaType( properties.getJavaType().toString() );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) );
+ properties.setWrittenMapToEntry( "set"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) );
+ }
+ }
+ else if ( Cardinality.isArray( cardinality )
+ && ( ( javaType == JavaType.STRING ) || ( javaType == JavaType.CALENDAR )
+ || ( javaType == JavaType.INT ) || ( javaType == JavaType.LONG ) || ( javaType == JavaType.BOOLEAN ) || ( javaType == JavaType.BYTE_ARRAY ) ) )
+ {
+ properties.setWrittenJavaType( javaType + "[]" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "Array" );
+ }
+ else if ( Cardinality.isList( cardinality )
+ && ( javaType == JavaType.STRING || javaType == JavaType.CALENDAR ) )
+ {
+ properties.setWrittenJavaType( "List<" + javaType + ">" );
+ if ( javaType == JavaType.CALENDAR )
+ {
+ properties.setWrittenMapFromEntry( "getCalendarList" );
+ }
+ else
+ {
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "List" );
+ }
+ }
+ else if ( Cardinality.isSet( cardinality )
+ && ( javaType == JavaType.STRING || javaType == JavaType.CALENDAR ) )
+ {
+ properties.setWrittenJavaType( "Set<" + javaType + ">" );
+ if ( javaType == JavaType.CALENDAR )
+ {
+ properties.setWrittenMapFromEntry( "getCalendarSet" );
+ }
+ else
+ {
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "Set" );
+ }
+ }
+ else if ( ( Cardinality.isSet( cardinality ) ) && ( javaType == JavaType.INT ) )
+ {
+ properties.setWrittenJavaType( "Set<Integer>" );
+ properties.setWrittenMapFromEntry( "getIntegerSet" );
+ }
+ else if ( ( Cardinality.isSet( cardinality ) ) && ( javaType == JavaType.LONG ) )
+ {
+ properties.setWrittenJavaType( "Set<Long>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "Set" );
+ }
+ else if ( ( Cardinality.isSet( cardinality ) ) && ( javaType == JavaType.BOOLEAN ) )
+ {
+ properties.setWrittenJavaType( "Set<Boolean>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "Set" );
+ }
+ else if ( ( Cardinality.isSet( cardinality ) ) && ( javaType == JavaType.BYTE_ARRAY ) )
+ {
+ properties.setWrittenJavaType( "Set<byte[]>" );
+ properties.setWrittenMapFromEntry( "getByteArraySet" );
+ }
+ else if ( ( Cardinality.isList( cardinality ) ) && ( javaType == JavaType.INT ) )
+ {
+ properties.setWrittenJavaType( "List<Integer>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "List" );
+ }
+ else if ( ( Cardinality.isList( cardinality ) ) && ( javaType == JavaType.LONG ) )
+ {
+ properties.setWrittenJavaType( "List<Long>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "List" );
+ }
+ else if ( ( Cardinality.isList( cardinality ) ) && ( javaType == JavaType.BOOLEAN ) )
+ {
+ properties.setWrittenJavaType( "List<Boolean>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "List" );
+ }
+ else if ( ( Cardinality.isList( cardinality ) ) && ( javaType == JavaType.BYTE_ARRAY ) )
+ {
+ properties.setWrittenJavaType( "List<Byte[]>" );
+ properties.setWrittenMapFromEntry( "get"
+ + GeneratorUtility.firstToUpperCase( properties.getJavaType().toString() ) + "List" );
+ }
+ }
+ return entryDetails;
+ }
+
+
+ /**
+ * Analyzes for the required packages need to be imported to the class
+ * and add them to a HashSet
+ *
+ * @param entryDetails the entry details
+ */
+ private void collectImports( List<EntryProperties> entryDetails )
+ {
+ imports = new HashSet<String>();
+ for ( EntryProperties properties : entryDetails )
+ {
+ if ( Cardinality.isList( properties.getCardinality() ) )
+ {
+ imports.add( "java.util.List" );
+ }
+ if ( Cardinality.isSet( properties.getCardinality() ) )
+ {
+ imports.add( "java.util.Set" );
+ }
+ }
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGeneratorContext.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGeneratorContext.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGeneratorContext.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/CodeGeneratorContext.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,200 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import java.util.List;
+
+
+/**
+ * TODO EntryInformation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CodeGeneratorContext
+{
+ private String className;
+ private String packageName;
+ private List<EntryProperties> entryProperties;
+ private String server;
+ private int port;
+ private String bindDn;
+ private String bindPassword;
+ private String rdnAttribute;
+ private String parentDn;
+ private String[] objectClasses;
+ private String projectFolderPath;
+
+
+ /**
+ * Creates a new instance of EntryInformation.
+ *
+ */
+ public CodeGeneratorContext()
+ {
+ super();
+ }
+
+
+ /**
+ * @return the className
+ */
+ public String getClassName()
+ {
+ return className;
+ }
+
+
+ /**
+ * @param className the className to set
+ */
+ public void setClassName( String className )
+ {
+ this.className = className;
+ }
+
+
+ /**
+ * @return the packageName
+ */
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+
+ /**
+ * @param packageName the packageName to set
+ */
+ public void setPackageName( String packageName )
+ {
+ this.packageName = packageName;
+ }
+
+
+ public List<EntryProperties> getEntryProperties()
+ {
+ return entryProperties;
+ }
+
+
+ public void setEntryProperties( List<EntryProperties> entryProperties )
+ {
+ this.entryProperties = entryProperties;
+ }
+
+
+ public String getServer()
+ {
+ return server;
+ }
+
+
+ public void setServer( String server )
+ {
+ this.server = server;
+ }
+
+
+ public int getPort()
+ {
+ return port;
+ }
+
+
+ public void setPort( int port )
+ {
+ this.port = port;
+ }
+
+
+ public String getBindDn()
+ {
+ return bindDn;
+ }
+
+
+ public void setBindDn( String bindDn )
+ {
+ this.bindDn = bindDn;
+ }
+
+
+ public String getBindPassword()
+ {
+ return bindPassword;
+ }
+
+
+ public void setBindPassword( String bindPassword )
+ {
+ this.bindPassword = bindPassword;
+ }
+
+
+ public String getRdnAttribute()
+ {
+ return rdnAttribute;
+ }
+
+
+ public void setRdnAttribute( String rdnAttribute )
+ {
+ this.rdnAttribute = rdnAttribute;
+ }
+
+
+ public String getParentDn()
+ {
+ return parentDn;
+ }
+
+
+ public void setParentDn( String parentDn )
+ {
+ this.parentDn = parentDn;
+ }
+
+
+ public String[] getObjectClasses()
+ {
+ return objectClasses;
+ }
+
+
+ public void setObjectClasses( String[] objectClasses )
+ {
+ this.objectClasses = objectClasses;
+ }
+
+
+ public String getProjectFolderPath()
+ {
+ return projectFolderPath;
+ }
+
+
+ public void setProjectFolderPath( String projectFolderPath )
+ {
+ this.projectFolderPath = projectFolderPath;
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/EntryProperties.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/EntryProperties.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/EntryProperties.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/EntryProperties.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,143 @@
+/*
+ * 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.studio.persistence.core;
+
+
+/**
+ * TODO EntryProperties.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryProperties
+{
+ private String ldapAttributeName;
+ private String javaMemberName;
+ private JavaType javaType;
+ private boolean isGen = false;
+ private Cardinality cardinality;
+ private String writtenJavaType;
+ private String writtenMapFromEntry;
+ private String writtenMapToEntry;
+
+
+ public String getWrittenJavaType()
+ {
+ return writtenJavaType;
+ }
+
+
+ public void setWrittenJavaType( String writtenJavaType )
+ {
+ this.writtenJavaType = writtenJavaType;
+ }
+
+
+ public Cardinality getCardinality()
+ {
+ return cardinality;
+ }
+
+
+ public void setCardinality( Cardinality cardinality )
+ {
+ this.cardinality = cardinality;
+ }
+
+
+ public String getLdapAttributeName()
+ {
+ return ldapAttributeName;
+ }
+
+
+ public void setLdapAttributeName( String ldapAttributeName )
+ {
+ this.ldapAttributeName = ldapAttributeName;
+ }
+
+
+ public String getJavaMemberName()
+ {
+ return javaMemberName;
+ }
+
+
+ public void setJavaMemberName( String javaMemberName )
+ {
+ this.javaMemberName = javaMemberName;
+ }
+
+
+ public JavaType getJavaType()
+ {
+ return javaType;
+ }
+
+
+ public void setJavaType( JavaType javaType )
+ {
+ this.javaType = javaType;
+ }
+
+
+ public boolean isGen()
+ {
+ return isGen;
+ }
+
+
+ public void setGen( boolean isGen )
+ {
+ this.isGen = isGen;
+ }
+
+
+ public String getWrittenMapFromEntry()
+ {
+ return writtenMapFromEntry;
+ }
+
+
+ public void setWrittenMapFromEntry( String writtenMapFromEntry )
+ {
+ this.writtenMapFromEntry = writtenMapFromEntry;
+ }
+
+
+ public String getWrittenMapToEntry()
+ {
+ return writtenMapToEntry;
+ }
+
+
+ public void setWrittenMapToEntry( String writtenMapToEntry )
+ {
+ this.writtenMapToEntry = writtenMapToEntry;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "EntryProperties [ldapAttributeName=" + ldapAttributeName + ", javaMemberName=" + javaMemberName
+ + ", javaType=" + javaType + ", isGen=" + isGen + ", cardinality=" + cardinality + "]";
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/GeneratorUtility.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/GeneratorUtility.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/GeneratorUtility.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/GeneratorUtility.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.studio.persistence.core;
+
+
+public class GeneratorUtility
+{
+ /**
+ * This utility class responsible for computing the first letter upper cased
+ * String from a given String
+ *
+ * @param string the string to be upper cased the first letter
+ * @return the string with the first letter upper cased
+ */
+ public static String firstToUpperCase( String string )
+ {
+ String post = string.substring( 1, string.length() );
+ String first = ( "" + string.charAt( 0 ) ).toUpperCase();
+ return first + post;
+ }
+
+}
\ No newline at end of file
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaType.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaType.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaType.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaType.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.ArrayUtils;
+
+
+/**
+ * This is a Enum to keep track of Java Type of an attribute
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum JavaType
+{
+ STRING("String"),
+
+ INT("int"),
+
+ LONG("long"),
+
+ BOOLEAN("boolean"),
+
+ BYTE_ARRAY("byte[]"),
+
+ CALENDAR("java.util.Calendar");
+
+ private final String string;
+
+
+ private JavaType( String string )
+ {
+ this.string = string;
+ }
+
+
+ public String toString()
+ {
+ return string;
+ }
+
+
+ public static String[] getStrings()
+ {
+ List<String> strings = new ArrayList<String>();
+ for ( JavaType value : values() )
+ {
+ strings.add( value.toString() );
+ }
+ return strings.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaUtils.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaUtils.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/JavaUtils.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,119 @@
+package org.apache.directory.studio.persistence.core;
+
+
+import java.util.Arrays;
+import java.util.List;
+
+
+public class JavaUtils
+{
+ // Array of Java reserved words up to Java 6
+ public static final String[] keywords =
+ { "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "continue", "default",
+ "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for", "if", "implements",
+ "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private", "protected",
+ "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw",
+ "throws", "transient", "true", "try", "void", "volatile", "while" };
+
+
+ /**
+ * Compute the valid identifier from a given string by removing
+ * illegal characters if it is not a Java reserved word.
+ *
+ * @param value the value of the string
+ * @return the valid value from the given value if it can be existed
+ * @throws IllegalArgumentException if the given string is null
+ */
+ public static String getValidValue( String value ) throws IllegalArgumentException
+ {
+ StringBuffer validValue = new StringBuffer();
+ if ( value == null )
+ {
+ throw new IllegalArgumentException();
+ }
+ else if ( value.length() > 1 && !( isKeyword( value ) ) )
+ {
+ char[] chars = value.toCharArray();
+ boolean isChecked = false;
+ for ( int i = 1; i < chars.length; i++ )
+ {
+ if ( isChecked == false && ( Character.isJavaIdentifierStart( chars[0] ) ) )
+ {
+ validValue.append( chars[0] );
+ isChecked = true;
+ }
+ if ( Character.isJavaIdentifierPart( chars[i] ) )
+ {
+ validValue.append( chars[i] );
+ }
+ }
+ }
+ else if ( value.length() == 0 )
+ {
+ validValue.append( "" );
+ }
+ else if ( value.length() == 1 && Character.isJavaIdentifierStart( value.charAt( 0 ) ) )
+ {
+ validValue.append( value.charAt( 0 ) );
+ }
+ return validValue.toString();
+ }
+
+
+ /**
+ * check if a given string is a Java reserved word or not.
+ *
+ * @param value the value of the string to be checked
+ * @return true if the given value is a Java reserved word, false if not
+ *
+ */
+ public static boolean isKeyword( String value )
+ {
+ boolean isKeyword = false;
+ if ( Arrays.asList( keywords ).contains( value ) )
+ {
+ isKeyword = true;
+ }
+ return isKeyword;
+ }
+
+
+ /**
+ * Check if same Java identifier is repeated
+ *
+ * @param javaMembers is a list of Java identifiers
+ * @param value is a value to be checked with the list of identifiers
+ * @return true if collides and false if not
+ */
+ public static boolean isCollide( List<String> javaMembers, String value )
+ {
+ boolean isCollide = false;
+ if ( javaMembers.contains( value ) )
+ {
+ isCollide = true;
+ }
+ return isCollide;
+ }
+
+
+ /**
+ * Check if a given string is a valid Java identifier or not both according to the
+ * existence of legal characters and reserved words.
+ *
+ * @param value string value to be checked for validness
+ * @return true if valid else false
+ */
+ public static boolean isValid( String value )
+ {
+ boolean isValid = true;
+ if ( getValidValue( value ).equals( value ) && !( value.length() == 0 ) )
+ {
+ isValid = true;
+ }
+ else
+ {
+ isValid = false;
+ }
+ return isValid;
+ }
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzer.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzer.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/LdapEntryAnalyzer.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,249 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.parsers.ObjectClassDescription;
+import org.apache.directory.studio.connection.core.DnUtils;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
+
+
+/**
+ * TODO LdapEntryAnalyzer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapEntryAnalyzer
+{
+
+ /**
+ * Analyze the entry and set all the values to a
+ * @CodeGeneratorContext object
+ *
+ *
+ * @param entry the entry to be analyzed
+ * @return CodeGeneratorContext with all required values injected
+ */
+ public CodeGeneratorContext analyze( IEntry entry )
+ {
+ CodeGeneratorContext codeGeneratorContext = new CodeGeneratorContext();
+ Collection<ObjectClassDescription> ocds = entry.getObjectClassDescriptions();
+ Schema schema = entry.getBrowserConnection().getSchema();
+
+ String packageName = computePackageName( entry.getDn() );
+ codeGeneratorContext.setPackageName( packageName );
+
+ ObjectClassDescription strucObjClass = SchemaUtils2.getStructuralObjectClass( ocds, schema );
+ String className = getClassName( strucObjClass );
+ codeGeneratorContext.setClassName( className );
+
+ codeGeneratorContext.setParentDn( DnUtils.getParent( entry.getDn() ).toString() );
+ codeGeneratorContext.setRdnAttribute( entry.getRdn().getUpType() );
+ codeGeneratorContext.setServer( entry.getBrowserConnection().getConnection().getHost() );
+ codeGeneratorContext.setPort( entry.getBrowserConnection().getConnection().getPort() );
+ codeGeneratorContext.setBindDn( entry.getBrowserConnection().getConnection().getBindPrincipal() );
+ List<String> objClasses = new ArrayList<String>();
+ for ( ObjectClassDescription ocd : ocds )
+ {
+ objClasses.add( ocd.getNames().get( 0 ) );
+ }
+ String[] objectClasses = new String[objClasses.toArray().length];
+ for ( int i = 0; i < objectClasses.length; i++ )
+ {
+ objectClasses[i] = objClasses.get( i );
+ }
+ codeGeneratorContext.setBindPassword( entry.getBrowserConnection().getConnection().getBindPassword() );
+ codeGeneratorContext.setObjectClasses( objectClasses );
+ List<EntryProperties> enList = new ArrayList<EntryProperties>();
+ Collection<String> attributes = extractAttributes( ocds, schema );
+ for ( String attrib : attributes )
+ {
+ AttributeTypeDescription atd = schema.getAttributeTypeDescription( attrib );
+ EntryProperties entryProperties = new EntryProperties();
+ entryProperties.setLdapAttributeName( attrib );
+ entryProperties.setJavaMemberName( attrib );
+ boolean hasEntryAttribute = entry.getAttribute( attrib ) != null;
+ entryProperties.setGen( hasEntryAttribute );
+ entryProperties.setJavaType( getJavaType( atd, schema ) );
+ entryProperties.setCardinality( getCardinality( atd, ocds, schema ) );
+ enList.add( entryProperties );
+ }
+ codeGeneratorContext.setEntryProperties( enList );
+
+ return codeGeneratorContext;
+ }
+
+
+ /**
+ * Compute the Java type according to the syntax oid of the attribute
+ *
+ * @param atd the attribute type description of the attribute of the selected entry
+ * @param schema the schema of the entry
+ * @return the Java type of the attribute
+ */
+ public static JavaType getJavaType( AttributeTypeDescription atd, Schema schema )
+ {
+ String syntaxOid = SchemaUtils.getSyntaxNumericOidTransitive( atd, schema );
+ boolean isBinary = SchemaUtils.isBinary( atd, schema );
+
+ if ( SchemaConstants.INTEGER_SYNTAX.equals( syntaxOid ) )
+ {
+ return JavaType.INT;
+ }
+ else if ( SchemaConstants.BOOLEAN_SYNTAX.equals( syntaxOid ) )
+ {
+ return JavaType.BOOLEAN;
+ }
+ else if ( SchemaConstants.GENERALIZED_TIME_SYNTAX.equals( syntaxOid ) )
+ {
+ return JavaType.CALENDAR;
+ }
+ else if ( isBinary )
+ {
+ return JavaType.BYTE_ARRAY;
+ }
+ else
+ {
+ return JavaType.STRING;
+ }
+ }
+
+ /**
+ * Compute the cardinality of the given attribute
+ *
+ * @param atd the attribute type description of the attribute of the selected entry
+ * @param ocds the Object Class Descriptions of the entry
+ * @param schema the schema of the entry
+ * @return the cardinality of the attribute
+ */
+ public static Cardinality getCardinality( AttributeTypeDescription atd, Collection<ObjectClassDescription> ocds,
+ Schema schema )
+ {
+ boolean isLowerBoundOne = SchemaUtils2.isMustAttribute( atd, ocds, schema );
+ boolean isUpperBoundOne = atd.isSingleValued();
+
+ if ( isLowerBoundOne && isUpperBoundOne )
+ {
+ return Cardinality.ONE;
+ }
+ else if ( isLowerBoundOne && !isUpperBoundOne )
+ {
+ return Cardinality.ONE_OR_MANY_SET;
+ }
+ else if ( !isLowerBoundOne && isUpperBoundOne )
+ {
+ return Cardinality.ZERO_OR_ONE;
+ }
+ else
+ //if(!isLowerBoundOne && !isUpperBoundOne)
+ {
+ return Cardinality.ZERO_OR_MANY_SET;
+ }
+ }
+
+
+ public static String firstToUpperCase( String string )
+ {
+ String post = string.substring( 1, string.length() );
+ String first = ( "" + string.charAt( 0 ) ).toUpperCase();
+ return first + post;
+ }
+
+
+ /**
+ * Computes the default package name for an DN. The package name is
+ * composed of all RDN values of the DN's parent. If the given DN or
+ * it's parent is null or empty the empty string is returned.
+ *
+ * @param dn the DN
+ * @return the computed package name
+ */
+ public static String computePackageName( LdapDN dn )
+ {
+ if ( dn == null || dn.isEmpty() )
+ {
+ return "";
+ }
+
+ // get the parent DN
+ LdapDN parentDn = DnUtils.getParent( dn );
+ if ( parentDn == null || parentDn.isEmpty() )
+ {
+ return "";
+ }
+
+ // now concatenate all RDN values to the package name
+ List<Rdn> rdns = parentDn.getRdns();
+ Collections.reverse( rdns );
+ String packageName = "";
+ for ( Rdn rdn : rdns )
+ {
+ String rdnVal = rdn.getUpValue();
+ String validValue = JavaUtils.getValidValue( rdnVal );
+ packageName += "." + validValue.toString().toLowerCase();
+ }
+ return packageName.substring( 1, packageName.length() );
+ }
+
+
+ /**
+ * Computes the class name for the bean class to be generated from
+ * structural object class of the given entry
+ *
+ * @param strucObjClass structural object class of the given entry
+ * @return the structural object class as the name of the bean class
+ * to be generated with first letter capitalized
+ */
+ public static String getClassName( ObjectClassDescription strucObjClass )
+ {
+ String objClassName = strucObjClass.getNames().get( 0 );
+ return firstToUpperCase( JavaUtils.getValidValue( objClassName ) );
+ }
+
+
+ /**
+ * Extracts the attributes for an entry from its object class descriptions
+ * and the schema
+ *
+ * @param ocd Object class descriptions of the given entry
+ * @param schema the schema of the entry
+ * @return all the attributes of the entry
+ */
+ public static Collection<String> extractAttributes( Collection<ObjectClassDescription> ocd, Schema schema )
+ {
+ List<String> attributes = new ArrayList<String>();
+ attributes.addAll( SchemaUtils2.getAllAttributes( ocd, schema ) );
+ attributes.remove( "objectClass" );
+ return attributes;
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/SchemaUtils2.java
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/SchemaUtils2.java?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/SchemaUtils2.java (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/java/org/apache/directory/studio/persistence/core/SchemaUtils2.java Sat Aug 28 20:04:24 2010
@@ -0,0 +1,171 @@
+/*
+ * 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.studio.persistence.core;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.parsers.ObjectClassDescription;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
+
+
+/**
+ * This is only a temporary utils class, should be merged into
+ * org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaUtils2
+{
+
+ private SchemaUtils2()
+ {
+
+ }
+
+
+ /**
+ * Gets the structural object class from a given set of object
+ * class descriptions and a Schema
+ *
+ * @param ocds the object class descriptions
+ * @param schema the schema
+ * @return structuralObjectClass the structural object class
+ *
+ * @throws IllegalArgumentException if @param ocds is empty or null or does not
+ * contain object classes which are structural and if the selected structural object
+ * is not in the same super class tree hierarchy as the super classes -this happens
+ * when the object class description list contains values which are not in the same
+ * superclass chain
+ */
+ public static ObjectClassDescription getStructuralObjectClass( Collection<ObjectClassDescription> ocds, Schema schema )
+ throws IllegalArgumentException
+ {
+ if ( ocds == null || ocds.isEmpty() )
+ {
+ throw new IllegalArgumentException();
+ }
+ List<ObjectClassDescription> strucObjClasses = new ArrayList<ObjectClassDescription>();
+ List<ObjectClassDescription> superiorObjClasses = new ArrayList<ObjectClassDescription>();
+ ObjectClassDescription specificObjectClass;
+ for ( ObjectClassDescription objClassDesc : ocds )
+ {
+ if ( objClassDesc.getKind().equals( ObjectClassTypeEnum.STRUCTURAL ) )
+ {
+ strucObjClasses.add( objClassDesc );
+ }
+ superiorObjClasses.addAll( SchemaUtils.getSuperiorObjectClassDescriptions( objClassDesc, schema ) );
+ }
+
+ if ( strucObjClasses.isEmpty() )
+ {
+ throw new IllegalArgumentException();
+ }
+
+ for ( ObjectClassDescription objClass : superiorObjClasses )
+ {
+ if ( strucObjClasses.contains( objClass ) )
+ {
+ strucObjClasses.remove( objClass );
+ }
+ }
+
+ specificObjectClass = strucObjClasses.get( 0 );
+ strucObjClasses.remove( 0 );
+ if ( specificObjectClass.getSuperiorObjectClasses().containsAll( strucObjClasses ) )
+ {
+ return specificObjectClass;
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+
+ }
+
+
+ /**
+ * Gets the attributes of all given object class descriptions including all
+ * attributes of all superior object class descriptions (transitively).
+ *
+ * @param ocds the object class descriptions
+ * @param schema the schema
+ * @return the list of all attributes
+ */
+ public static Collection<String> getAllAttributes( Collection<ObjectClassDescription> ocds, Schema schema )
+ {
+ // Use a hash set here because the same attribute can be defined in different object classes
+ // and we don't want duplicate attributes.
+ Collection<String> attributes = new HashSet<String>();
+
+ for ( ObjectClassDescription ocd : ocds )
+ {
+ Collection<String> mayAttributes = SchemaUtils.getMayAttributeTypeDescriptionNamesTransitive( ocd, schema );
+ Collection<String> mustAttributes = SchemaUtils
+ .getMustAttributeTypeDescriptionNamesTransitive( ocd, schema );
+ attributes.addAll( mayAttributes );
+ attributes.addAll( mustAttributes );
+ }
+
+ return attributes;
+ }
+
+
+ /**
+ * Checks if the given attribute type is defined as MUST attribute in one of the
+ * object classes.
+ *
+ * @param atd the attribute type description
+ * @param ocds the object class descriptions
+ * @param schema the schema
+ * @return true if the attribute is defined as MUST in one of the object classes
+ */
+ public static boolean isMustAttribute( AttributeTypeDescription atd, Collection<ObjectClassDescription> ocds,
+ Schema schema )
+ {
+ if ( atd == null || ocds == null || schema == null )
+ {
+ throw new IllegalArgumentException();
+ }
+
+ for ( ObjectClassDescription ocd : ocds )
+ {
+ Collection<String> musts = SchemaUtils.getMustAttributeTypeDescriptionNamesTransitive( ocd, schema );
+ for ( String must : musts )
+ {
+ AttributeTypeDescription mustAtd = schema.getAttributeTypeDescription( must );
+ if ( atd.getNumericOid().equals( mustAtd.getNumericOid() ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
Added: directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/dao_template.vm
URL: http://svn.apache.org/viewvc/directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/dao_template.vm?rev=990428&view=auto
==============================================================================
--- directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/dao_template.vm (added)
+++ directory/sandbox/studio-persistence-tooling/persistence-core/src/main/resources/dao_template.vm Sat Aug 28 20:04:24 2010
@@ -0,0 +1,120 @@
+#*
+ * 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.
+ *
+ *#
+
+#set( $this = "Velocity" )
+#set( $dao = ".dao" )
+
+package $package$dao;
+
+import java.text.ParseException;
+
+import javax.naming.NamingException;
+
+
+import org.apache.directory.shared.ldap.entry.Entry;
+
+import $package.$utility.firstToUpperCase($generator.ClassName);
+
+
+public class $utility.firstToUpperCase($generator.ClassName)Dao extends GenericLdapDao<$utility.firstToUpperCase($generator.ClassName)>
+{
+
+ public $utility.firstToUpperCase($generator.ClassName)Dao()
+ {
+ super.server = "$generator.Server";
+ super.port = $generator.Port;
+ super.name = "$generator.BindDn";
+ super.credentials = "$generator.BindPassword";
+ super.rdnAttribute = "$generator.RdnAttribute";
+ super.parentDn = "$generator.ParentDn";
+ super.attributes = new String[]
+ { #foreach( $entry in $generator.EntryProperties) #if( $entry.Gen == true ) "$entry.JavaMemberName", #end #end };
+ super.objectClasses = new String[]
+ { #foreach( $objClass in $generator.ObjectClasses) #if( $objClass == "" ) "$objClass" #else "$objClass", #end #end };
+ }
+
+ protected $utility.firstToUpperCase($generator.ClassName) mapFromEntry( Entry entry ) throws ParseException
+ {
+ $utility.firstToUpperCase($generator.ClassName) attribute = new $utility.firstToUpperCase($generator.ClassName)();
+#foreach( $entryPro in $entryProps )
+#set( $javaAttrName = $entryPro.JavaMemberName )
+#if( $entryPro.WrittenJavaType == "java.util.Calendar" )
+ try
+ {
+ attribute.set$utility.firstToUpperCase($javaAttrName)( getCalendar( entry, "$entryPro.LdapAttributeName" ) );
+ }
+ catch ( ParseException e )
+ {
+ e.printStackTrace();
+ }
+#else
+ attribute.set$utility.firstToUpperCase($javaAttrName)( $entryPro.WrittenMapFromEntry ( entry, "$entryPro.LdapAttributeName" ) );
+#end
+#end
+ return attribute;
+ }
+
+ protected void mapToEntry( $utility.firstToUpperCase($generator.ClassName) attribute, Entry entry ) throws NamingException
+ {
+#foreach( $entryPro in $entryProps )
+#set( $javaAttrName = $entryPro.JavaMemberName )
+#set( $javaType = $utility.firstToUpperCase($entryPro.JavaType) )
+#if( $entryPro.WrittenJavaType == "Set<String>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setString( entry, "$entryPro.LdapAttributeName", val );
+ }
+#elseif( $entryPro.WrittenJavaType == "Set<Integer>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setInt( entry, "$entryPro.LdapAttributeName", val );
+ }
+#elseif( $entryPro.WrittenJavaType == "Set<Long>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setLong( entry, "$entryPro.LdapAttributeName", val );
+ }
+#elseif( $entryPro.WrittenJavaType == "Set<Boolean>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setBoolean( entry, "$entryPro.LdapAttributeName", val );
+ }
+#elseif( $entryPro.WrittenJavaType == "Set<java.util.Calendar>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setCalendar( entry, "$entryPro.LdapAttributeName", val );
+ }
+#elseif( $entryPro.WrittenJavaType == "Set<byte[]>" )
+ for ( $entryPro.JavaType val : attribute.get$utility.firstToUpperCase($javaAttrName)() )
+ {
+ setBytes( entry, "$entryPro.LdapAttributeName", val );
+ }
+#else
+#if ( $entryPro.WrittenJavaType == "boolean" )
+ $entryPro.WrittenMapToEntry ( entry, "$entryPro.LdapAttributeName", attribute.is$utility.firstToUpperCase($javaAttrName)() );
+#else
+ $entryPro.WrittenMapToEntry ( entry, "$entryPro.LdapAttributeName", attribute.get$utility.firstToUpperCase($javaAttrName)() );
+#end
+#end
+#end
+ }
+
+}