Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepository.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepository.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepository.java (working copy) @@ -16,9 +16,10 @@ */ package org.apache.jackrabbit.core.jndi; -import org.apache.jackrabbit.core.RepositoryImpl; -import org.apache.jackrabbit.core.config.RepositoryConfig; -import org.apache.jackrabbit.core.config.ConfigurationException; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import javax.jcr.Credentials; import javax.jcr.LoginException; @@ -29,35 +30,33 @@ import javax.naming.Reference; import javax.naming.Referenceable; import javax.naming.StringRefAddr; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.ConfigurationException; +import org.apache.jackrabbit.core.config.RepositoryConfig; + /** - * A referenceable and serializable content repository proxy. - * This class implements the Proxy design pattern (GoF) for the - * Jackrabbit Repository implementation. The proxy implementation - * delays the instantiation of the actual Repository instance and - * implements serialization and JNDI referenceability by keeping - * track of the repository configuration parameters. + * A referenceable and serializable content repository proxy. This class + * implements the Proxy design pattern (GoF) for the Jackrabbit Repository + * implementation. The proxy implementation delays the instantiation of the + * actual Repository instance and implements serialization and JNDI + * referenceability by keeping track of the repository configuration parameters. *

- * A BindableRepository instance contains the configuration file - * and home directory paths of a Jackrabbit repository. The separate + * A BindableRepository instance contains the configuration file and home + * directory paths of a Jackrabbit repository. The separate * {@link #init() init()} method is used to create a transient - * {@link RepositoryImpl RepositoryImpl} instance to which all the - * JCR API calls are delegated. + * {@link RepositoryImpl RepositoryImpl} instance to which all the JCR API calls + * are delegated. *

- * An instance of this class is normally always also initialized. - * The uninitialized state is only used briefly during the static - * {@link #create(String, String) create} method and during - * serialization and JNDI "referenciation". + * An instance of this class is normally always also + * initialized. The uninitialized state is only used briefly during the static + * {@link #create(String, String) create} method and during serialization and + * JNDI "referenciation". *

- * A JVM shutdown hook is used to make sure that the initialized - * repository is properly closed when the JVM shuts down. The + * A JVM shutdown hook is used to make sure that the + * initialized repository is properly closed when the JVM shuts down. The * {@link RegistryHelper#unregisterRepository(javax.naming.Context, String)} - * method should be used to explicitly close the repository if - * needed. + * method should be used to explicitly close the repository if needed. */ class BindableRepository implements Repository, Referenceable, Serializable { @@ -77,11 +76,14 @@ private final String repHomeDir; /** - * type of configFilePath reference address (@see {@link Reference#get(String)} + * type of configFilePath reference address (@see + * {@link Reference#get(String)} */ static final String CONFIGFILEPATH_ADDRTYPE = "configFilePath"; + /** - * type of repHomeDir reference address (@see {@link Reference#get(String)} + * type of repHomeDir reference address (@see + * {@link Reference#get(String)} */ static final String REPHOMEDIR_ADDRTYPE = "repHomeDir"; @@ -100,8 +102,10 @@ * Creates a BindableRepository instance with the given configuration * information, but does not create the underlying repository instance. * - * @param configFilePath repository configuration file path - * @param repHomeDir repository home directory path + * @param configFilePath + * repository configuration file path + * @param repHomeDir + * repository home directory path */ protected BindableRepository(String configFilePath, String repHomeDir) { this.configFilePath = configFilePath; @@ -113,27 +117,33 @@ * Creates an initialized BindableRepository instance using the given * configuration information. * - * @param configFilePath repository configuration file path - * @param repHomeDir repository home directory path + * @param configFilePath + * repository configuration file path + * @param repHomeDir + * repository home directory path * @return initialized repository instance - * @throws RepositoryException if the repository cannot be created + * @throws RepositoryException + * if the repository cannot be created */ static BindableRepository create(String configFilePath, String repHomeDir) throws RepositoryException { - BindableRepository rep = new BindableRepository(configFilePath, repHomeDir); + BindableRepository rep = new BindableRepository(configFilePath, + repHomeDir); rep.init(); return rep; } /** - * Creates the underlying repository instance. A shutdown hook is - * registered to make sure that the initialized repository gets closed - * when the JVM shuts down. + * Creates the underlying repository instance. A shutdown hook is registered + * to make sure that the initialized repository gets closed when the JVM + * shuts down. * - * @throws RepositoryException if the repository cannot be created + * @throws RepositoryException + * if the repository cannot be created */ protected void init() throws RepositoryException { - RepositoryConfig config = createRepositoryConfig(configFilePath, repHomeDir); + RepositoryConfig config = createRepositoryConfig(configFilePath, + repHomeDir); delegatee = createRepository(config); hook = new Thread() { public void run() { @@ -148,14 +158,16 @@ * Creates a repository configuration from a path to the repository.xml file * and the repository home directory. * - * @param configFilePath path to the repository.xml file. - * @param repHomeDir the repository home directory. + * @param configFilePath + * path to the repository.xml file. + * @param repHomeDir + * the repository home directory. * @return the repository configuration. - * @throws ConfigurationException on configuration error. + * @throws ConfigurationException + * on configuration error. */ protected RepositoryConfig createRepositoryConfig(String configFilePath, - String repHomeDir) - throws ConfigurationException { + String repHomeDir) throws ConfigurationException { return RepositoryConfig.create(configFilePath, repHomeDir); } @@ -163,96 +175,95 @@ * Creates a plain repository instance from a repository * config. * - * @param config the repository configuration. + * @param config + * the repository configuration. * @return the repository instance. - * @throws RepositoryException if an error occurs while creating the - * repository instance. + * @throws RepositoryException + * if an error occurs while creating the repository instance. */ protected Repository createRepository(RepositoryConfig config) throws RepositoryException { return RepositoryImpl.create(config); } - //-----------------------------------------------------------< Repository > + // -----------------------------------------------------------< Repository > /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ public Session login(Credentials credentials, String workspaceName) - throws LoginException, NoSuchWorkspaceException, RepositoryException { + throws LoginException, NoSuchWorkspaceException, + RepositoryException { return delegatee.login(credentials, workspaceName); } /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ - public Session login(String workspaceName) - throws LoginException, NoSuchWorkspaceException, RepositoryException { + public Session login(String workspaceName) throws LoginException, + NoSuchWorkspaceException, RepositoryException { return delegatee.login(workspaceName); } /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ public Session login() throws LoginException, RepositoryException { return delegatee.login(); } /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ - public Session login(Credentials credentials) - throws LoginException, RepositoryException { + public Session login(Credentials credentials) throws LoginException, + RepositoryException { return delegatee.login(credentials); } /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ public String getDescriptor(String key) { return delegatee.getDescriptor(key); } /** - * Delegated to the underlying repository instance. - * {@inheritDoc} + * Delegated to the underlying repository instance. {@inheritDoc} */ public String[] getDescriptorKeys() { return delegatee.getDescriptorKeys(); } - //--------------------------------------------------------< Referenceable > + // --------------------------------------------------------< Referenceable > /** * Creates a JNDI reference for this content repository. The returned - * reference holds the configuration information required to create a - * copy of this instance. + * reference holds the configuration information required to create a copy + * of this instance. * * @return the created JNDI reference */ public Reference getReference() { Reference ref = new Reference(BindableRepository.class.getName(), - BindableRepositoryFactory.class.getName(), - null); // no classpath defined + BindableRepositoryFactory.class.getName(), null); // no + // classpath + // defined ref.add(new StringRefAddr(CONFIGFILEPATH_ADDRTYPE, configFilePath)); ref.add(new StringRefAddr(REPHOMEDIR_ADDRTYPE, repHomeDir)); return ref; } - //-------------------------------------------------< Serializable support > + // -------------------------------------------------< Serializable support > /** * Serializes the repository configuration. The default serialization * mechanism is used, as the underlying delegate repository is referenced * using a transient variable. * - * @param out the serialization stream - * @throws IOException on IO errors + * @param out + * the serialization stream + * @throws IOException + * on IO errors * @see Serializable */ private void writeObject(ObjectOutputStream out) throws IOException { @@ -261,18 +272,21 @@ } /** - * Deserializes a repository instance. The repository configuration - * is deserialized using the standard deserialization mechanism, and - * the underlying delegate repository is created using the - * {@link #init() init} method. + * Deserializes a repository instance. The repository configuration is + * deserialized using the standard deserialization mechanism, and the + * underlying delegate repository is created using the {@link #init() init} + * method. * - * @param in the serialization stream - * @throws IOException if configuration information cannot be deserialized - * or if the configured repository cannot be created - * @throws ClassNotFoundException on deserialization errors + * @param in + * the serialization stream + * @throws IOException + * if configuration information cannot be deserialized or if the + * configured repository cannot be created + * @throws ClassNotFoundException + * on deserialization errors */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException { + private void readObject(ObjectInputStream in) throws IOException, + ClassNotFoundException { // delegate deserialization to default implementation in.defaultReadObject(); // initialize reconstructed instance Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepositoryFactory.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepositoryFactory.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/BindableRepositoryFactory.java (working copy) @@ -16,20 +16,21 @@ */ package org.apache.jackrabbit.core.jndi; -import org.apache.commons.collections.map.ReferenceMap; +import java.util.Hashtable; +import java.util.Map; import javax.jcr.RepositoryException; import javax.naming.Context; import javax.naming.Name; import javax.naming.Reference; import javax.naming.spi.ObjectFactory; -import java.util.Hashtable; -import java.util.Map; +import org.apache.commons.collections.map.ReferenceMap; + /** * BindableRepositoryFactory is an object factory that when given * a reference for a BindableRepository object, will create an - * instance of the corresponding BindableRepository. + * instance of the corresponding BindableRepository. */ public class BindableRepositoryFactory implements ObjectFactory { @@ -37,7 +38,8 @@ * cache using java.naming.Reference objects as keys and * storing soft references to BindableRepository instances */ - private static Map cache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT); + private static Map cache = new ReferenceMap(ReferenceMap.HARD, + ReferenceMap.SOFT); /** * empty default constructor @@ -49,35 +51,40 @@ * Creates an initialized BindableRepository instance using the given * configuration information and puts it in {@link #cache}. * - * @param configFilePath repository configuration file path - * @param repHomeDir repository home directory path + * @param configFilePath + * repository configuration file path + * @param repHomeDir + * repository home directory path * @return initialized repository instance - * @throws RepositoryException if the repository cannot be created + * @throws RepositoryException + * if the repository cannot be created */ - static BindableRepository createInstance(String configFilePath, String repHomeDir) - throws RepositoryException { - BindableRepository rep = BindableRepository.create(configFilePath, repHomeDir); + static BindableRepository createInstance(String configFilePath, + String repHomeDir) throws RepositoryException { + BindableRepository rep = BindableRepository.create(configFilePath, + repHomeDir); cache.put(rep.getReference(), rep); return rep; } - //--------------------------------------------------------< ObjectFactory > + // --------------------------------------------------------< ObjectFactory > /** * {@inheritDoc} */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, - Hashtable environment) - throws Exception { + Hashtable environment) throws Exception { if (obj instanceof Reference) { Reference ref = (Reference) obj; synchronized (cache) { if (cache.containsKey(ref)) { return cache.get(ref); } else { - String configFilePath = - (String) ref.get(BindableRepository.CONFIGFILEPATH_ADDRTYPE).getContent(); - String repHomeDir = - (String) ref.get(BindableRepository.REPHOMEDIR_ADDRTYPE).getContent(); + String configFilePath = (String) ref.get( + BindableRepository.CONFIGFILEPATH_ADDRTYPE) + .getContent(); + String repHomeDir = (String) ref.get( + BindableRepository.REPHOMEDIR_ADDRTYPE) + .getContent(); return createInstance(configFilePath, repHomeDir); } } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyContext.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyContext.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyContext.java (working copy) @@ -16,6 +16,10 @@ */ package org.apache.jackrabbit.core.jndi.provider; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; + import javax.naming.Binding; import javax.naming.CompositeName; import javax.naming.CompoundName; @@ -30,14 +34,11 @@ import javax.naming.NamingException; import javax.naming.NotContextException; import javax.naming.OperationNotSupportedException; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Properties; /** - * DummyContext is a simple service provider that - * implements a flat namespace in memory. It is intended to be used for - * testing purposes only. + * DummyContext is a simple service provider that implements a + * flat namespace in memory. It is intended to be used for testing purposes + * only. */ class DummyContext extends Hashtable implements Context, Cloneable { @@ -68,7 +69,8 @@ protected String getComponentName(Name name) throws NamingException { if (name instanceof CompositeName) { if (name.size() > 1) { - throw new InvalidNameException(name.toString() + " has more components than namespace can handle"); + throw new InvalidNameException(name.toString() + + " has more components than namespace can handle"); } return name.get(0); } else { @@ -92,7 +94,7 @@ return obj; } - //--------------------------------------------------------------< Context > + // --------------------------------------------------------------< Context > /** * {@inheritDoc} */ @@ -131,15 +133,18 @@ /** * {@inheritDoc} */ - public String composeName(String name, String prefix) throws NamingException { - return composeName(new CompositeName(name), new CompositeName(prefix)).toString(); + public String composeName(String name, String prefix) + throws NamingException { + return composeName(new CompositeName(name), new CompositeName(prefix)) + .toString(); } /** * {@inheritDoc} */ public Context createSubcontext(Name name) throws NamingException { - throw new OperationNotSupportedException("subcontexts are not supported"); + throw new OperationNotSupportedException("subcontexts are not " + + "supported"); } /** @@ -153,7 +158,8 @@ * {@inheritDoc} */ public void destroySubcontext(Name name) throws NamingException { - throw new OperationNotSupportedException("subcontexts are not supported"); + throw new OperationNotSupportedException("subcontexts are not " + + "supported"); } /** @@ -291,7 +297,8 @@ /** * {@inheritDoc} */ - public Object removeFromEnvironment(String propName) throws NamingException { + public Object removeFromEnvironment(String propName) + throws NamingException { return environment.remove(propName); } @@ -336,11 +343,12 @@ /** * {@inheritDoc} */ - public Object addToEnvironment(String propName, Object propVal) throws NamingException { + public Object addToEnvironment(String propName, Object propVal) + throws NamingException { return environment.put(propName, propVal); } - //--------------------------------------------------------< inner classes > + // --------------------------------------------------------< inner classes > /** * FlatNameParser ... */ @@ -366,6 +374,7 @@ */ class NamingEnum implements NamingEnumeration { protected Enumeration namesEnum; + protected Hashtable bindings; NamingEnum(Hashtable bindings) { Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java (working copy) @@ -16,11 +16,12 @@ */ package org.apache.jackrabbit.core.jndi.provider; +import java.util.HashMap; +import java.util.Hashtable; + import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; -import java.util.HashMap; -import java.util.Hashtable; /** * DummyInitialContextFactory ... @@ -35,11 +36,14 @@ /** * {@inheritDoc} */ - public Context getInitialContext(Hashtable environment) throws NamingException { + public Context getInitialContext(Hashtable environment) + throws NamingException { String url = (String) environment.get(Context.PROVIDER_URL); if (url == null) { - throw new NamingException("Unable to create context. Environment is missing a " + Context.PROVIDER_URL); + throw new NamingException( + "Unable to create context. Environment is missing a " + + Context.PROVIDER_URL); } synchronized (DummyInitialContextFactory.contexts) { Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/RegistryHelper.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/RegistryHelper.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jndi/RegistryHelper.java (working copy) @@ -21,9 +21,8 @@ import javax.naming.NamingException; /** - * JNDI helper functionality. This class contains static utility - * methods for binding and unbinding Jackarbbit repositories to and - * from a JNDI context. + * JNDI helper functionality. This class contains static utility methods for + * binding and unbinding Jackarbbit repositories to and from a JNDI context. */ public class RegistryHelper { @@ -34,30 +33,37 @@ } /** - * Binds a configured repository to the given JNDI context. - * This method creates a {@link BindableRepository BindableRepository} - * instance using the given configuration information, and binds - * it to the given JNDI context. + * Binds a configured repository to the given JNDI context. This method + * creates a {@link BindableRepository BindableRepository} instance using + * the given configuration information, and binds it to the given JNDI + * context. * - * @param ctx context where the repository should be registered (i.e. bound) - * @param name the name to register the repository with - * @param configFilePath path to the configuration file of the repository - * @param repHomeDir repository home directory - * @param overwrite if true, any existing binding with the given - * name will be overwritten; otherwise a NamingException will - * be thrown if the name is already bound - * @throws RepositoryException if the repository cannot be created - * @throws NamingException if the repository cannot be registered in JNDI + * @param ctx + * context where the repository should be registered (i.e. bound) + * @param name + * the name to register the repository with + * @param configFilePath + * path to the configuration file of the repository + * @param repHomeDir + * repository home directory + * @param overwrite + * if true, any existing binding with the given + * name will be overwritten; otherwise a + * NamingException will be thrown if the name is + * already bound + * @throws RepositoryException + * if the repository cannot be created + * @throws NamingException + * if the repository cannot be registered in JNDI */ public static void registerRepository(Context ctx, String name, - String configFilePath, - String repHomeDir, - boolean overwrite) + String configFilePath, String repHomeDir, boolean overwrite) throws NamingException, RepositoryException { // always create instance by using BindableRepositoryFactory // which maintains an instance cache; // see http://issues.apache.org/jira/browse/JCR-411 for details - Object obj = BindableRepositoryFactory.createInstance(configFilePath, repHomeDir); + Object obj = BindableRepositoryFactory.createInstance(configFilePath, + repHomeDir); if (overwrite) { ctx.rebind(name, obj); } else { @@ -67,12 +73,16 @@ /** * This method shutdowns a {@link BindableRepository BindableRepository} - * instance using the given configuration information, and unbinds - * it from the given JNDI context. + * instance using the given configuration information, and unbinds it from + * the given JNDI context. * - * @param ctx context where the repository should be unregistered (i.e. unbound) - * @param name the name of the repository to unregister - * @throws NamingException on JNDI errors + * @param ctx + * context where the repository should be unregistered (i.e. + * unbound) + * @param name + * the name of the repository to unregister + * @throws NamingException + * on JNDI errors */ public static void unregisterRepository(Context ctx, String name) throws NamingException {