[exo-jcr-commits] exo-jcr SVN: r2110 - core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Mar 24 12:19:39 EDT 2010
Author: pnedonosko
Date: 2010-03-24 12:19:38 -0400 (Wed, 24 Mar 2010)
New Revision: 2110
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.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
Log:
EXOJCR-573 binder used inside InitialContextInitializer (new method bind); cleanup and some renaming.
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -22,7 +22,7 @@
* Class contains needed database connection information.
*
* @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBConnectionInfo.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBConnectionInfo
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -33,7 +33,7 @@
/**
* @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBCreator
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -20,7 +20,7 @@
/**
* @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreatorException.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBCreatorException extends Exception
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -18,10 +18,11 @@
*/
package org.exoplatform.services.database;
+import junit.framework.TestCase;
+
import org.exoplatform.container.PortalContainer;
import org.exoplatform.services.database.creator.DBConnectionInfo;
import org.exoplatform.services.database.creator.DBCreator;
-import org.exoplatform.services.naming.InitialContextBinder;
import org.exoplatform.services.naming.InitialContextInitializer;
import java.sql.Connection;
@@ -30,19 +31,15 @@
import javax.sql.DataSource;
-import junit.framework.TestCase;
-
/**
* @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: TestDBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class TestDBCreator extends TestCase
{
protected DBCreator dbCreator;
- private InitialContextBinder initialContextBinder;
-
private InitialContextInitializer initContext;
public void setUp() throws Exception
@@ -51,7 +48,6 @@
dbCreator = (DBCreator)container.getComponentInstanceOfType(DBCreator.class);
initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
- initialContextBinder = (InitialContextBinder)container.getComponentInstanceOfType(InitialContextBinder.class);
}
public void testDBCreate() throws Exception
@@ -66,7 +62,7 @@
refAddr.put("username", dbInfo.getUsername());
refAddr.put("password", dbInfo.getPassword());
- initialContextBinder.bind("testjdbcjcr", "javax.sql.DataSource",
+ initContext.bind("testjdbcjcr", "javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
DataSource ds = (DataSource)initContext.getInitialContext().lookup("testjdbcjcr");
Property changes on: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 16:19:38 UTC (rev 2110)
@@ -73,11 +73,6 @@
</component>
<component>
- <key>org.exoplatform.services.naming.InitialContextBinder</key>
- <type>org.exoplatform.services.naming.InitialContextBinder</type>
- </component>
-
- <component>
<key>org.exoplatform.services.naming.InitialContextInitializer</key>
<type>org.exoplatform.services.naming.InitialContextInitializer</type>
<component-plugins>
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-03-24 15:42:01 UTC (rev 2109)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -78,12 +78,12 @@
/**
* Absolute file path to references's storage.
*/
- protected final String bindReferencesPath;
+ protected final String bindingsStorePath;
/**
* All current binded references.
*/
- protected Map<String, Reference> bindReferences;
+ protected Map<String, Reference> bindings;
/**
* InitialContextBinder constructor.
@@ -99,17 +99,17 @@
* @throws NamingException
* @throws NamingException
*/
- public InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
+ InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
XMLStreamException, NamingException
{
this.initialContextInitializer = initialContextInitializer;
- this.bindReferences = new HashMap<String, Reference>();
- this.bindReferencesPath = System.getProperty("java.io.tmpdir") + File.separator + "bind-references.xml";
+ this.bindings = new HashMap<String, Reference>();
+ this.bindingsStorePath = System.getProperty("java.io.tmpdir") + File.separator + "bind-references.xml";
- if (new File(bindReferencesPath).exists())
+ if (new File(bindingsStorePath).exists())
{
- Map<String, Reference> importedRefs = doImport();
+ Map<String, Reference> importedRefs = readBindings();
for (Entry<String, Reference> entry : importedRefs.entrySet())
{
bind(entry.getKey(), entry.getValue());
@@ -141,20 +141,20 @@
Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException
{
Reference reference = new Reference(className, factory, factoryLocation);
- for (Entry entry : refAddr.entrySet())
+ for (Map.Entry<String, String> entry : refAddr.entrySet())
{
- reference.add(new StringRefAddr((String)entry.getKey(), (String)entry.getValue()));
+ reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
bind(bindName, reference);
- doExport();
+ saveBindings();
}
private void bind(String bindName, Reference reference) throws NamingException
{
initialContextInitializer.getInitialContext().bind(bindName, reference);
- bindReferences.put(bindName, reference);
+ bindings.put(bindName, reference);
}
/**
@@ -165,15 +165,15 @@
* @throws FileNotFoundException
* if can't open output stream from file
*/
- protected void doExport() throws FileNotFoundException, XMLStreamException
+ protected void saveBindings() throws FileNotFoundException, XMLStreamException
{
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream(bindReferencesPath), "UTF-8");
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream(bindingsStorePath), "UTF-8");
writer.writeStartDocument("UTF-8", "1.0");
writer.writeStartElement(BIND_REFERENCES_ELEMENT);
- for (Entry<String, Reference> entry : bindReferences.entrySet())
+ for (Entry<String, Reference> entry : bindings.entrySet())
{
String bindName = entry.getKey();
Reference reference = entry.getValue();
@@ -218,14 +218,14 @@
* @throws FileNotFoundException
* if can't open input stream from file
*/
- protected Map<String, Reference> doImport() throws FileNotFoundException, XMLStreamException
+ protected Map<String, Reference> readBindings() throws FileNotFoundException, XMLStreamException
{
Stack<RefEntity> stack = new Stack<RefEntity>();
Map<String, Reference> importedRefs = new HashMap<String, Reference>();
XMLInputFactory factory = XMLInputFactory.newInstance();
- XMLEventReader reader = factory.createXMLEventReader(new FileInputStream(bindReferencesPath), "UTF-8");
+ XMLEventReader reader = factory.createXMLEventReader(new FileInputStream(bindingsStorePath), "UTF-8");
while (reader.hasNext())
{
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-03-24 15:42:01 UTC (rev 2109)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -26,16 +26,23 @@
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;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NamingException;
import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.xml.stream.XMLStreamException;
/**
* Created by The eXo Platform SAS.<br/> Initializer for
@@ -59,13 +66,18 @@
private final InitialContext initialContext;
+ private final InitialContextBinder binder;
+
/**
* @param params
* @throws NamingException
* @throws ConfigurationException if no context factory initialized and no
* context-factory nor default-context-factory configured
+ * @throws XMLStreamException if error of serialized bindings read
+ * @throws FileNotFoundException if cannot open file with serialized bindings
*/
- public InitialContextInitializer(InitParams params) throws NamingException, ConfigurationException
+ public InitialContextInitializer(InitParams params) throws NamingException, ConfigurationException,
+ FileNotFoundException, XMLStreamException
{
for (Iterator propsParams = params.getPropertiesParamIterator(); propsParams.hasNext();)
{
@@ -97,6 +109,9 @@
}
initialContext = new InitialContext();
bindReferencesPlugins = new ArrayList<BindReferencePlugin>();
+
+ // binder
+ binder = new InitialContextBinder(this);
}
private void setSystemProperty(String propName, String propValue, String propParamName)
@@ -110,13 +125,17 @@
}
// for out-of-container testing
- private InitialContextInitializer(String name, Reference reference) throws NamingException
+ private InitialContextInitializer(String name, Reference reference) throws NamingException, FileNotFoundException, XMLStreamException
{
if (System.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, defaultContextFactory);
+ }
initialContext = new InitialContext();
initialContext.rebind(name, reference);
+ // binder
+ binder = new InitialContextBinder(this);
}
/**
@@ -191,8 +210,34 @@
}
// for out-of-container testing
- public static void initialize(String name, Reference reference) throws NamingException
+ public static void initialize(String name, Reference reference) throws NamingException, FileNotFoundException, XMLStreamException
{
new InitialContextInitializer(name, reference);
}
+
+ /**
+ * Constructs references from params, binds in initial contexts and persists list of all binded
+ * references into file.
+ *
+ * @param bindName
+ * bind name
+ * @param className
+ * class name
+ * @param factory
+ * factory name
+ * @param factoryLocation
+ * factory location
+ * @param refAddr
+ * map of references's properties
+ *
+ * @throws NamingException
+ * if error occurs due to binding
+ * @throws XMLStreamException
+ * @throws FileNotFoundException
+ */
+ public void bind(String bindName, String className, String factory, String factoryLocation,
+ Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException
+ {
+ binder.bind(bindName, className, factory, factoryLocation, refAddr);
+ }
}
More information about the exo-jcr-commits
mailing list