[exo-jcr-commits] exo-jcr SVN: r3256 - in kernel/trunk/exo.kernel.component.common: src/main/java/org/exoplatform/services/naming and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Oct 7 03:25:24 EDT 2010


Author: tolusha
Date: 2010-10-07 03:25:24 -0400 (Thu, 07 Oct 2010)
New Revision: 3256

Modified:
   kernel/trunk/exo.kernel.component.common/pom.xml
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
   kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java
   kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml
Log:
EXOJCR-977: support different files for different InitialContextBinder instances

Modified: kernel/trunk/exo.kernel.component.common/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.common/pom.xml	2010-10-07 06:54:54 UTC (rev 3255)
+++ kernel/trunk/exo.kernel.component.common/pom.xml	2010-10-07 07:25:24 UTC (rev 3256)
@@ -105,7 +105,6 @@
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
                <excludes>
-                  <exclude>**/InitialContextTest.java</exclude>
                   <exclude>**/TransactionTest.java</exclude>
                </excludes>
             </configuration>

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java	2010-10-07 06:54:54 UTC (rev 3255)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java	2010-10-07 07:25:24 UTC (rev 3256)
@@ -25,8 +25,8 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Stack;
-import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NameAlreadyBoundException;
@@ -91,20 +91,16 @@
     *          initial context initializer
     * @param initParams
     *          initialization parameters
-    * @throws XMLStreamException 
     * @throws FileNotFoundException 
-    * @throws FileNotFoundException
     * @throws XMLStreamException
-    * @throws NamingException 
     * @throws NamingException
     */
-   InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
-      XMLStreamException, NamingException
+   InitialContextBinder(InitialContextInitializer initialContextInitializer, String bindingsStorePath)
+      throws FileNotFoundException, XMLStreamException, NamingException
    {
       this.initialContextInitializer = initialContextInitializer;
-
       this.bindings = new ConcurrentHashMap<String, Reference>();
-      this.bindingsStorePath = System.getProperty("java.io.tmpdir") + File.separator + "bind-references.xml";
+      this.bindingsStorePath = bindingsStorePath;
 
       if (new File(bindingsStorePath).exists())
       {
@@ -117,6 +113,15 @@
    }
 
    /**
+    * InitialContextBinder constructor.
+    */
+   InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
+      XMLStreamException, NamingException
+   {
+      this(initialContextInitializer, InitialContextInitializer.DEFAULT_BINDING_STORE_PATH);
+   }
+
+   /**
     * Constructs references from params, binds in initial contexts and persists list of all binded
     * references into file.
     * 

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java	2010-10-07 06:54:54 UTC (rev 3255)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java	2010-10-07 07:25:24 UTC (rev 3256)
@@ -23,9 +23,11 @@
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.container.xml.PropertiesParam;
 import org.exoplatform.container.xml.Property;
+import org.exoplatform.container.xml.ValueParam;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -55,6 +57,11 @@
 
    final public static String PROPERTIES_MANDATORY = "mandatory-properties";
 
+   final public static String BINDINGS_STORE_PATH = "bindings-store-path";
+
+   final public static String DEFAULT_BINDING_STORE_PATH = System.getProperty("java.io.tmpdir") + File.separator
+      + "bind-references.xml";
+
    private static Log LOG = ExoLogger.getLogger("exo.kernel.component.common.InitialContextInitializer");
 
    private List<BindReferencePlugin> bindReferencesPlugins;
@@ -107,8 +114,18 @@
       initialContext = new InitialContext();
       bindReferencesPlugins = new ArrayList<BindReferencePlugin>();
 
+      ValueParam bindingStorePathParam = params.getValueParam(BINDINGS_STORE_PATH);
+
       // binder
-      binder = new InitialContextBinder(this);
+      if (bindingStorePathParam == null)
+      {
+         binder = new InitialContextBinder(this, DEFAULT_BINDING_STORE_PATH);
+      }
+      else
+      {
+         binder = new InitialContextBinder(this, bindingStorePathParam.getValue());
+      }
+
    }
 
    private void setSystemProperty(String propName, String propValue, String propParamName)
@@ -133,7 +150,7 @@
       initialContext.rebind(name, reference);
 
       // binder
-      binder = new InitialContextBinder(this);
+      binder = new InitialContextBinder(this, DEFAULT_BINDING_STORE_PATH);
    }
 
    /**

Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java	2010-10-07 06:54:54 UTC (rev 3255)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/naming/InitialContextTest.java	2010-10-07 07:25:24 UTC (rev 3256)
@@ -18,18 +18,24 @@
  */
 package org.exoplatform.services.naming;
 
-import junit.framework.TestCase;
-
-import org.exoplatform.container.StandaloneContainer;
-
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.naming.CompositeName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.xml.stream.XMLStreamException;
 
+import junit.framework.TestCase;
+
+import org.exoplatform.container.PortalContainer;
+
 /**
  * Created by The eXo Platform SAS .<br/> Prerequisites: default-context-factory
  * = org.exoplatform.services.naming.impl.SimpleContextFactory
@@ -42,14 +48,14 @@
 
    private static String TEST_CONTEXT_FACTORY = "org.exoplatform.services.naming.SimpleContextFactory";
 
-   private StandaloneContainer container;
+   private PortalContainer container;
 
    public void setUp() throws Exception
    {
 
-      StandaloneContainer.setConfigurationPath("src/test/java/conf/standalone/test-configuration.xml");
+      //      StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml");
 
-      container = StandaloneContainer.getInstance();
+      container = PortalContainer.getInstance();
    }
 
    public void testConfig() throws Exception
@@ -98,4 +104,27 @@
       }
    }
 
+   /* 
+    * Tests if InitialContextInitializer correctly gets bindings-store-path from 
+    * param-value and pass it to InitialContexBinder, thus provides usage of different files
+    * for different instances of the class. 
+    */
+   public void testDifferentFileUsage() throws FileNotFoundException, NamingException, XMLStreamException
+   {
+
+      InitialContextInitializer initializer =
+         (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
+
+      Map<String, String> refAddr = new HashMap<String, String>();
+      refAddr.put("driverClassName", "org.hsqldb.jdbcDriver");
+      refAddr.put("url", "jdbc:hsqldb:file:target/temp/data/portal");
+      refAddr.put("username", "sa");
+      refAddr.put("password", "");
+
+      initializer.bind("testjdbcjcr1", "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null,
+         refAddr);
+
+      assertTrue(new File("target/store-path.xml").exists());
+   }
+
 }

Modified: kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml	2010-10-07 06:54:54 UTC (rev 3255)
+++ kernel/trunk/exo.kernel.component.common/src/test/resources/conf/portal/test-configuration.xml	2010-10-07 07:25:24 UTC (rev 3256)
@@ -52,11 +52,6 @@
    </component>
 
    <component>
-      <key>org.exoplatform.services.naming.InitialContextBinder</key>
-      <type>org.exoplatform.services.naming.InitialContextBinder</type>
-   </component>
-
-   <component>
       <key>org.exoplatform.services.mail.MailService</key>
       <type>org.exoplatform.services.mail.impl.MailServiceImpl</type>
       <init-params>
@@ -78,6 +73,84 @@
    </component>
 
    <component>
+      <key>org.exoplatform.services.naming.InitialContextInitializer</key>
+      <type>org.exoplatform.services.naming.InitialContextInitializer</type>
+      <component-plugins>
+         <component-plugin>
+            <name>bind.datasource</name>
+            <set-method>addPlugin</set-method>
+            <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+            <init-params>
+               <value-param>
+                  <name>bind-name</name>
+                  <value>jdbcjcr</value>
+               </value-param>
+               <value-param>
+                  <name>class-name</name>
+                  <value>javax.sql.DataSource</value>
+               </value-param>
+               <value-param>
+                  <name>factory</name>
+                  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+               </value-param>
+               <properties-param>
+                  <name>ref-addresses</name>
+                  <description>ref-addresses</description>
+                  <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+                  <property name="url" value="jdbc:hsqldb:file:target/temp/data/portal" />
+                  <property name="username" value="sa" />
+                  <property name="password" value="" />
+               </properties-param>
+            </init-params>
+         </component-plugin>
+
+         <component-plugin>
+            <name>tx.userTransaction</name>
+            <set-method>addPlugin</set-method>
+            <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+            <init-params>
+               <value-param>
+                  <name>bind-name</name>
+                  <value>UserTransaction</value>
+               </value-param>
+               <value-param>
+                  <name>class-name</name>
+                  <value>javax.transaction.UserTransaction</value>
+               </value-param>
+               <value-param>
+                  <name>factory</name>
+                  <value>org.objectweb.jotm.UserTransactionFactory</value>
+                  <!-- value>org.exoplatform.services.transaction.UserTransactionFactory</value -->
+               </value-param>
+               <properties-param>
+                  <name>ref-addresses</name>
+                  <description>ref-addresses</description>
+                  <property name="timeout" value="60" />
+               </properties-param>
+            </init-params>
+         </component-plugin>
+      </component-plugins>
+      <init-params>
+         <value-param> 
+            <name>bindings-store-path</name> 
+            <value>target/store-path.xml</value> 
+         </value-param> 
+         <properties-param>
+            <name>default-properties</name>
+            <description>Default initial context properties</description>
+            <property name="java.naming.factory.initial" value="org.exoplatform.services.naming.SimpleContextFactory" />
+         </properties-param>
+         <!-- properties-param>
+            <name>mandatory-properties</name>
+            <description>Mandatory initial context properties</description>
+            <property name="java.naming.factory.initial" value="org.exoplatform.services.naming.SimpleContextFactory" />
+            <property name="java.naming.provider.url" value="rmi://localhost:9999" />
+         </properties-param -->
+      </init-params>
+   </component>
+
+
+   <component>
       <key>org.exoplatform.services.scheduler.JobSchedulerService</key>
       <type>org.exoplatform.services.scheduler.impl.JobSchedulerServiceImpl</type>
       <component-plugins>



More information about the exo-jcr-commits mailing list