incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r630196 - in /incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client: Activator.java SlingClientRepository.java
Date Fri, 22 Feb 2008 13:28:48 GMT
Author: bdelacretaz
Date: Fri Feb 22 05:28:46 2008
New Revision: 630196

URL: http://svn.apache.org/viewvc?rev=630196&view=rev
Log:
SLING-260, use sling.repository.url.override property in jackrabbit-client as well

Modified:
    incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/Activator.java
    incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java

Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/Activator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/Activator.java?rev=630196&r1=630195&r2=630196&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/Activator.java
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/Activator.java
Fri Feb 22 05:28:46 2008
@@ -22,6 +22,8 @@
 
 import javax.naming.Context;
 
+import org.apache.sling.jcr.base.util.RepositoryAccessor;
+
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -71,14 +73,12 @@
         return SlingClientRepository.class.getName();
     }
 
-    protected Hashtable<String, Object>getDefaultConfiguration() {
-        Hashtable<String, Object> props = new Hashtable<String, Object>();
+    protected void initDefaultConfig(Hashtable<String, String> props) {
         props.put(SLING_CONTEXT, slingContext);
         props.put(SlingClientRepository.REPOSITORY_NAME, "jackrabbit");
         props.put(Context.PROVIDER_URL, "http://incubator.apache.org/sling");
         props.put(Context.INITIAL_CONTEXT_FACTORY,
             "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
-        return props;
     }
 
     public void start(BundleContext context) {
@@ -152,11 +152,21 @@
             }
 
             // we have no configuration, create from default settings
-            final Hashtable<String, Object> props = this.getDefaultConfiguration();
+            Hashtable<String, String> defaultConfig = new Hashtable<String, String>();
+            final String overrideUrl = bundleContext.getProperty(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
+            if(overrideUrl != null && overrideUrl.length() > 0) {
+                // Ignore other parameters if override URL (SLING-260) is set 
+                defaultConfig.put(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY, overrideUrl);
+                log.debug(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY + "=" + overrideUrl
+ 
+                    ", using it to create the default configuration");
+                
+            } else {
+               initDefaultConfig(defaultConfig); 
+            }
 
             // create the factory and set the properties
             Configuration config = ca.createFactoryConfiguration(this.getClientRepositoryFactoryPID());
-            config.update(props);
+            config.update(defaultConfig);
 
             log.debug("verifyConfiguration: Created configuration {} for {}",
                 config.getPid(), config.getFactoryPid());

Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java?rev=630196&r1=630195&r2=630196&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java
Fri Feb 22 05:28:46 2008
@@ -101,16 +101,34 @@
     private Repository getRepository() throws RepositoryException {
         @SuppressWarnings("unchecked")
         Dictionary<String, Object> environment = this.getComponentContext().getProperties();
+        Repository repo = null;
 
-        String repoName = (String) environment.get(REPOSITORY_NAME);
-        if (repoName == null) {
-            throw new RepositoryException("Missing property 'name'");
-        }
-
-        final Hashtable<String, Object> jndiContext = this.fromDictionary(environment);
-        final Repository repo = new RepositoryAccessor().getRepository(repoName, jndiContext);
-        if(repo == null) {
-            throw new RepositoryException("Cannot acquire repository '" + repoName + "'");
+        // if the environment provides a repository override URL, other settings are ignored
(SLING-260)
+        final String overrideUrl = (String) environment.get(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
+        
+        if(overrideUrl != null && overrideUrl.length() > 0) {
+            log.log(LogService.LOG_INFO, 
+                    "Will not use embedded repository due to property " + RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY

+                    + "=" + overrideUrl
+                    + ", acquiring repository using that URL"
+                    );
+            repo = new RepositoryAccessor().getRepositoryFromURL(overrideUrl);
+            
+        } else {
+            log.log(LogService.LOG_INFO, 
+                    "Repository URL override property (" +  RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY
+                    + ") not set, using name/context settings");
+            
+            String repoName = (String) environment.get(REPOSITORY_NAME);
+            if (repoName == null) {
+                throw new RepositoryException("Missing property 'name'");
+            }
+    
+            final Hashtable<String, Object> jndiContext = this.fromDictionary(environment);
+            repo = new RepositoryAccessor().getRepository(repoName, jndiContext);
+            if(repo == null) {
+                throw new RepositoryException("Cannot acquire repository '" + repoName +
"'");
+            }
         }
         return repo;
     }



Mime
View raw message