You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2011/02/16 03:29:21 UTC
svn commit: r1071125 - in /directory/shared/branches/m1:
dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/
dsml-parser/ dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/
ldap-client-api/ ldap-client-api/src/main/java/org/...
Author: akarasulu
Date: Wed Feb 16 02:29:20 2011
New Revision: 1071125
URL: http://svn.apache.org/viewvc?rev=1071125&view=rev
Log:
DIRSHARED-91:
o added new LdapCodecServiceFactory which is initialized with the default
implemenation if the ldap-codec module bundle is loaded in an OSGi env
o factory is being used through out to select the standalone implementation
instead of directly referrencing it in the code
o only specific tests for the standalone implementation are still directly
calling the constructor for the standalone implemenation
o made the ldap-codec-standalone module a provided scope dependency or a
test scope dependency where appropriate so the dependency does not carry
over into studio modules
Added:
directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecServiceFactory.java
Modified:
directory/shared/branches/m1/dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/Dsmlv2Engine.java
directory/shared/branches/m1/dsml-parser/pom.xml
directory/shared/branches/m1/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/AbstractTest.java
directory/shared/branches/m1/ldap-client-api/pom.xml
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
directory/shared/branches/m1/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
directory/shared/branches/m1/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultActivator.java
Modified: directory/shared/branches/m1/dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/Dsmlv2Engine.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/Dsmlv2Engine.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/Dsmlv2Engine.java (original)
+++ directory/shared/branches/m1/dsml-engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/Dsmlv2Engine.java Wed Feb 16 02:29:20 2011
@@ -50,8 +50,8 @@ import org.apache.directory.shared.dsmlv
import org.apache.directory.shared.dsmlv2.request.BatchRequestDsml.Processing;
import org.apache.directory.shared.dsmlv2.request.BatchRequestDsml.ResponseOrder;
import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.ldap.codec.standalone.StandaloneLdapCodecService;
import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
import org.apache.directory.shared.ldap.model.cursor.Cursor;
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
@@ -115,7 +115,7 @@ public class Dsmlv2Engine
/** The batch response. */
private BatchResponseDsml batchResponse;
- private LdapCodecService codec = new StandaloneLdapCodecService();
+ private LdapCodecService codec = LdapCodecServiceFactory.getSingleton();
private Dsmlv2Grammar grammar = new Dsmlv2Grammar( codec );
Modified: directory/shared/branches/m1/dsml-parser/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/dsml-parser/pom.xml?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/dsml-parser/pom.xml (original)
+++ directory/shared/branches/m1/dsml-parser/pom.xml Wed Feb 16 02:29:20 2011
@@ -44,7 +44,8 @@
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>shared-i18n</artifactId>
+ <artifactId>shared-ldap-codec-standalone</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
@@ -54,11 +55,6 @@
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>shared-ldap-codec-standalone</artifactId>
- </dependency>
-
- <dependency>
- <groupId>${project.groupId}</groupId>
<artifactId>shared-ldap-model</artifactId>
</dependency>
Modified: directory/shared/branches/m1/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/AbstractTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/AbstractTest.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/AbstractTest.java (original)
+++ directory/shared/branches/m1/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/AbstractTest.java Wed Feb 16 02:29:20 2011
@@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
import org.apache.directory.shared.dsmlv2.request.Dsmlv2Grammar;
import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
-import org.apache.directory.shared.ldap.codec.standalone.StandaloneLdapCodecService;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
import org.xmlpull.v1.XmlPullParserException;
/**
@@ -37,7 +37,7 @@ import org.xmlpull.v1.XmlPullParserExcep
public abstract class AbstractTest
{
/** The LDAP encoder decoder service */
- private LdapCodecService codec = new StandaloneLdapCodecService();
+ private LdapCodecService codec = LdapCodecServiceFactory.getSingleton();
private Dsmlv2Grammar grammar = new Dsmlv2Grammar( codec );
Modified: directory/shared/branches/m1/ldap-client-api/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/pom.xml?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/pom.xml (original)
+++ directory/shared/branches/m1/ldap-client-api/pom.xml Wed Feb 16 02:29:20 2011
@@ -56,6 +56,12 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>shared-ldap-codec-standalone</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>shared-ldap-codec</artifactId>
</dependency>
<dependency>
Modified: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Wed Feb 16 02:29:20 2011
@@ -58,8 +58,8 @@ import org.apache.directory.ldap.client.
import org.apache.directory.shared.asn1.DecoderException;
import org.apache.directory.shared.asn1.util.OID;
import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
import org.apache.directory.shared.ldap.codec.api.MessageEncoderException;
-import org.apache.directory.shared.ldap.codec.standalone.StandaloneLdapCodecService;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
import org.apache.directory.shared.ldap.model.constants.SupportedSaslMechanisms;
import org.apache.directory.shared.ldap.model.cursor.Cursor;
@@ -214,7 +214,7 @@ public class LdapNetworkConnection exten
private SchemaManager schemaManager;
/** the ldap codec service */
- LdapCodecService codec = new StandaloneLdapCodecService();
+ LdapCodecService codec = LdapCodecServiceFactory.getSingleton();
/** The Ldap codec protocol filter */
private IoFilter ldapProtocolFilter = new ProtocolCodecFilter( codec.newProtocolCodecFactory( true ) );
Modified: directory/shared/branches/m1/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java (original)
+++ directory/shared/branches/m1/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java Wed Feb 16 02:29:20 2011
@@ -267,7 +267,7 @@ public class StandaloneLdapCodecService
/**
* Creates a new instance of StandaloneLdapCodecService.
*/
- public StandaloneLdapCodecService(File pluginDirectory, File cacheDirectory)
+ public StandaloneLdapCodecService( File pluginDirectory, File cacheDirectory )
{
// -------------------------------------------------------------------
Modified: directory/shared/branches/m1/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java (original)
+++ directory/shared/branches/m1/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java Wed Feb 16 02:29:20 2011
@@ -39,11 +39,8 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.Asn1Container;
import org.apache.directory.shared.ldap.codec.AbstractCodecServiceTest;
-import org.apache.directory.shared.ldap.codec.LdapEncoder;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.api.CodecControl;
-import org.apache.directory.shared.ldap.codec.standalone.StandaloneLdapCodecService;
-import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
import org.apache.directory.shared.ldap.codec.api.ResponseCarryingException;
import org.apache.directory.shared.ldap.codec.decorators.AddRequestDecorator;
import org.apache.directory.shared.ldap.codec.decorators.MessageDecorator;
@@ -65,13 +62,6 @@ import org.junit.runner.RunWith;
@Concurrency()
public class AddRequestTest extends AbstractCodecServiceTest
{
- /** the codec service used for tests */
- private LdapCodecService codec = new StandaloneLdapCodecService();
-
- /** The encoder instance */
- private LdapEncoder encoder = new LdapEncoder( codec );
-
-
/**
* Test the decoding of a AddRequest
*/
Added: directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecServiceFactory.java?rev=1071125&view=auto
==============================================================================
--- directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecServiceFactory.java (added)
+++ directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecServiceFactory.java Wed Feb 16 02:29:20 2011
@@ -0,0 +1,142 @@
+/*
+ * 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.shared.ldap.codec.api;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A factory that allows callers a means to get a handle on an LdapCodecService
+ * implementation regardless of the environment in which they're accessing it.
+ * In an OSGi environment, the BundleActivator binds the LdapCodecService
+ * class member forever to the {@link DefaultLdapCodecService}. If in
+ *
+ * In a standard standalone mode, the Bundle
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapCodecServiceFactory
+{
+ /** Logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( LdapCodecServiceFactory.class );
+
+ /** The LdapCodecService singleton bound to this factory */
+ private static LdapCodecService ldapCodecService;
+
+ /** Whether or not the standalone implementation is being used */
+ private static boolean usingStandaloneImplementation;
+
+
+ /**
+ * Checks to see if the factory is initialized.
+ *
+ * @return true if initialized, false otherwise
+ */
+ public static boolean isInitialized()
+ {
+ return ldapCodecService != null;
+ }
+
+
+ /**
+ * Checks to see if the factory is using the standalone implementation.
+ *
+ * @return true if using the standalone implementation, false otherwise.
+ */
+ public static boolean isUsingStandaloneImplementation()
+ {
+ if ( ! isInitialized() )
+ {
+ String msg = "Not initialized yet!";
+ LOG.error( msg );
+ throw new IllegalStateException( msg );
+ }
+
+ return usingStandaloneImplementation;
+ }
+
+
+ /**
+ * Gets the singleton instance of the LdapCodecService.
+ *
+ * @return a valid instance implementation based on environment and the
+ * availability of bindings.
+ */
+ public static LdapCodecService getSingleton()
+ {
+ if ( ldapCodecService == null )
+ {
+ initialize( null );
+ }
+
+ return ldapCodecService;
+ }
+
+
+ /**
+ * Initialization can only take place once. There after an exception
+ * results.
+ *
+ * @param ldapCodecService The LDAP Codec Service to initialize with.
+ */
+ public static void initialize( LdapCodecService ldapCodecService )
+ {
+ /*
+ * If the class member is already set we have problems.
+ */
+
+ if ( LdapCodecServiceFactory.ldapCodecService != null )
+ {
+ StringBuilder sb = new StringBuilder( "The LdapCodecService is already set to an instance of " );
+ sb.append( LdapCodecServiceFactory.class.getName() );
+ LOG.error( sb.toString() );
+ throw new IllegalStateException( sb.toString() );
+ }
+
+
+ /*
+ * If the argument is null, then we attempt discovery
+ */
+
+ if ( ldapCodecService == null )
+ {
+ try
+ {
+ @SuppressWarnings("unchecked")
+ Class<? extends LdapCodecService> serviceClass = ( Class<? extends LdapCodecService> )
+ Class.forName( "org.apache.directory.shared.ldap.codec.standalone.StandaloneLdapCodecService" );
+ LdapCodecServiceFactory.ldapCodecService = serviceClass.newInstance();
+ usingStandaloneImplementation = true;
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Failed to instantiate a viable instance, instantiating new instance of ", e );
+
+ }
+ }
+ else
+ {
+ usingStandaloneImplementation = false;
+ LdapCodecServiceFactory.ldapCodecService = ldapCodecService;
+ }
+ }
+}
Modified: directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultActivator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultActivator.java?rev=1071125&r1=1071124&r2=1071125&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultActivator.java (original)
+++ directory/shared/branches/m1/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultActivator.java Wed Feb 16 02:29:20 2011
@@ -22,6 +22,7 @@ package org.apache.directory.shared.ldap
import org.apache.directory.shared.ldap.codec.api.DefaultLdapCodecService;
import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -52,6 +53,7 @@ public class DefaultActivator implements
public void start( BundleContext bundleContext ) throws Exception
{
registration = bundleContext.registerService( LdapCodecService.class.getName(), codec, null );
+ LdapCodecServiceFactory.initialize( codec );
}