[exo-jcr-commits] exo-jcr SVN: r215 - in jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr: impl/config and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Oct 5 07:01:34 EDT 2009


Author: nfilotto
Date: 2009-10-05 07:01:34 -0400 (Mon, 05 Oct 2009)
New Revision: 215

Added:
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationPlugin.java
Modified:
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerEntryWrapper.java
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryEntry.java
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryInfo.java
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryServiceConfiguration.java
   jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
Log:
EXOJCR-166: Support separated ear delivery

Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerEntryWrapper.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerEntryWrapper.java	2009-10-05 10:55:42 UTC (rev 214)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerEntryWrapper.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -164,7 +164,8 @@
 	entry.putBooleanParameter(PARAM_DOCUMENT_ORDER, DEFAULT_DOCUMENTORDER);
 	entry.putParameterValue(PARAM_EXCERPTPROVIDER_CLASS,
 		DEDAULT_EXCERPTPROVIDER_CLASS);
-	entry.putParameterValue(PARAM_EXCLUDED_NODE_IDENTIFERS, null);
+// Null value is forbidden according to the binding.xml, it prevents marshalling 
+//	entry.putParameterValue(PARAM_EXCLUDED_NODE_IDENTIFERS, null);
 	entry.putIntegerParameter(PARAM_EXTRACTOR_BACKLOG,
 		DEFAULT_EXTRACTOR_BACKLOG);
 	entry.putIntegerParameter(PARAM_EXTRACTOR_POOLSIZE,

Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryEntry.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryEntry.java	2009-10-05 10:55:42 UTC (rev 214)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryEntry.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -19,6 +19,8 @@
 package org.exoplatform.services.jcr.config;
 
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * Created by The eXo Platform SAS .
@@ -68,4 +70,33 @@
       workspaces.add(ws);
    }
 
+   /**
+    * Merges the current {@link RepositoryEntry} with the given one. The current {@link RepositoryEntry}
+    * has the highest priority thus only absent data will be overrode
+    * @param entry the entry to merge with the current {@link RepositoryEntry}
+    */
+   void merge(RepositoryEntry entry)
+   {
+      merge((RepositoryInfo)entry);
+      ArrayList<WorkspaceEntry> workspaceEntries = entry.workspaces;
+      if (workspaceEntries == null || workspaceEntries.isEmpty())
+      {
+         return;
+      }
+      if (workspaces == null || workspaces.isEmpty())
+      {
+         this.workspaces = workspaceEntries;
+         return;
+      }
+      Map<String, WorkspaceEntry> mWorkspaceEntries = new LinkedHashMap<String, WorkspaceEntry>();
+      for (WorkspaceEntry wkEntry : workspaceEntries)
+      {
+         mWorkspaceEntries.put(wkEntry.getName(), wkEntry);
+      }
+      for (WorkspaceEntry wkEntry : workspaces)
+      {
+         mWorkspaceEntries.put(wkEntry.getName(), wkEntry);
+      }
+      this.workspaces = new ArrayList<WorkspaceEntry>(mWorkspaceEntries.values());
+   }
 }

Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryInfo.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryInfo.java	2009-10-05 10:55:42 UTC (rev 214)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryInfo.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -189,4 +189,18 @@
       this.sessionTimeOut = sessionTimeOut;
    }
 
+   /**
+    * Merges the current {@link RepositoryInfo} with the given one. The current {@link RepositoryInfo}
+    * has the highest priority thus only absent data will be overrode
+    * @param entry the entry to merge with the current {@link RepositoryInfo}
+    */
+   void merge(RepositoryInfo entry)
+   {
+      if (systemWorkspaceName == null) setSystemWorkspaceName(entry.systemWorkspaceName);
+      if (defaultWorkspaceName == null) setDefaultWorkspaceName(entry.defaultWorkspaceName);
+      if (accessControl == null) setAccessControl(entry.accessControl);
+      if (securityDomain == null) setSecurityDomain(entry.securityDomain);
+      if (authenticationPolicy == null) setAuthenticationPolicy(entry.authenticationPolicy);
+      if (sessionTimeOut == 0) setSessionTimeOut(entry.sessionTimeOut);
+   }   
 }

Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryServiceConfiguration.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryServiceConfiguration.java	2009-10-05 10:55:42 UTC (rev 214)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/config/RepositoryServiceConfiguration.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -24,6 +24,9 @@
 import org.jibx.runtime.JiBXException;
 
 import java.io.InputStream;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.jcr.RepositoryException;
 
@@ -66,11 +69,59 @@
       }
       catch (JiBXException e)
       {
-         e.printStackTrace();
-         throw new RepositoryConfigurationException("Error in config initialization " + e);
+         throw new RepositoryConfigurationException("Error in config initialization " + e, e);
       }
    }
 
+   protected final void merge(InputStream is) throws RepositoryConfigurationException
+   {
+      try
+      {
+         IBindingFactory factory = BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
+         IUnmarshallingContext uctx = factory.createUnmarshallingContext();
+         RepositoryServiceConfiguration conf = (RepositoryServiceConfiguration)uctx.unmarshalDocument(is, null);
+
+         if (defaultRepositoryName == null)
+         {
+            this.defaultRepositoryName = conf.getDefaultRepositoryName();            
+         }
+         
+         List<RepositoryEntry> repositoryEntries = conf.getRepositoryConfigurations();
+         if (repositoryEntries == null || repositoryEntries.isEmpty())
+         {
+            return;            
+         }
+         if (repositoryConfigurations == null || repositoryConfigurations.isEmpty())
+         {
+            this.repositoryConfigurations = repositoryEntries;
+            return;
+         }
+         Map<String, RepositoryEntry> mapRepoEntries = new LinkedHashMap<String, RepositoryEntry>();
+         for (RepositoryEntry entry : repositoryConfigurations)
+         {
+            mapRepoEntries.put(entry.getName(), entry);
+         }
+         for (RepositoryEntry entry : repositoryEntries)
+         {
+            RepositoryEntry currentEntry = mapRepoEntries.get(entry.getName());
+            if (currentEntry == null)
+            {
+               mapRepoEntries.put(entry.getName(), entry);
+            }
+            else
+            {
+               currentEntry.merge(entry);
+            }
+         }
+         getRepositoryConfigurations().clear();
+         getRepositoryConfigurations().addAll(mapRepoEntries.values());         
+      }
+      catch (JiBXException e)
+      {
+         throw new RepositoryConfigurationException("Error in config initialization " + e, e);
+      }
+   }
+   
    /**
     * Checks if current configuration can be saved.
     * 

Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2009-10-05 10:55:42 UTC (rev 214)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -29,6 +29,7 @@
 import org.jibx.runtime.IBindingFactory;
 import org.jibx.runtime.IMarshallingContext;
 import org.jibx.runtime.JiBXException;
+import org.picocontainer.Startable;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -41,6 +42,8 @@
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.jcr.RepositoryException;
 
@@ -51,7 +54,7 @@
  * @version $Id: RepositoryServiceConfigurationImpl.java 12841 2007-02-16 08:58:38Z peterit $
  */
 
-public class RepositoryServiceConfigurationImpl extends RepositoryServiceConfiguration
+public class RepositoryServiceConfigurationImpl extends RepositoryServiceConfiguration implements Startable
 {
 
    private ValueParam param;
@@ -59,6 +62,8 @@
    private ConfigurationManager configurationService;
 
    private ConfigurationPersister configurationPersister;
+   
+   private final List<String> configExtensionPaths = new CopyOnWriteArrayList<String>(); 
 
    public RepositoryServiceConfigurationImpl(InitParams params, ConfigurationManager configurationService,
       InitialContextInitializer initialContextInitializer) throws RepositoryConfigurationException
@@ -97,29 +102,6 @@
          }
       }
       this.configurationService = configurationService;
-
-      InputStream jcrConfigurationInputStream;
-      try
-      {
-         jcrConfigurationInputStream = configurationService.getInputStream(param.getValue());
-         if (configurationPersister != null)
-         {
-            if (!configurationPersister.hasConfig())
-            {
-               configurationPersister.write(jcrConfigurationInputStream);
-            }
-            init(configurationPersister.read());
-         }
-         else
-         {
-            init(jcrConfigurationInputStream);
-            jcrConfigurationInputStream.close();
-         }
-      }
-      catch (Exception e)
-      {
-         throw new RepositoryConfigurationException("Fail to init from xml! Reason: " + e, e);
-      }
    }
 
    public RepositoryServiceConfigurationImpl(InputStream is) throws RepositoryConfigurationException
@@ -127,6 +109,14 @@
       init(is);
    }
 
+   /**
+    * Allows to add new configuration paths
+    */
+   public void addConfig(RepositoryServiceConfigurationPlugin plugin)
+   {
+      configExtensionPaths.add(plugin.getConfPath());
+   }
+   
    /*
     * (non-Javadoc)
     * @see org.exoplatform.services.jcr.config.RepositoryServiceConfiguration#isRetainable()
@@ -220,4 +210,87 @@
       }
 
    }
+   
+   private void initFromStream(InputStream jcrConfigurationInputStream) throws RepositoryConfigurationException
+   {
+      try
+      {
+         if (configurationPersister != null)
+         {
+            if (!configurationPersister.hasConfig())
+            {
+               configurationPersister.write(jcrConfigurationInputStream);
+            }
+            init(configurationPersister.read());
+         }
+         else
+         {
+            init(jcrConfigurationInputStream);
+         }
+      }
+      finally
+      {
+         try
+         {
+            jcrConfigurationInputStream.close();
+         }
+         catch (IOException e)
+         {
+            // ignore me
+         }                     
+      }
+      
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void start()
+   {
+      try
+      {
+         if (configExtensionPaths.isEmpty())
+         {
+            initFromStream(configurationService.getInputStream(param.getValue()));            
+         }
+         else
+         {
+            
+            String[] paths = (String[]) configExtensionPaths.toArray(new String[configExtensionPaths.size()]);
+            for (int i = paths.length - 1 ; i >= 0 ; i--)
+            {
+               // We start from the last one because as it is the one with highest priority
+               if (i == paths.length - 1)
+               {
+                  init(configurationService.getInputStream(paths[i]));                  
+               }
+               else
+               {
+                  merge(configurationService.getInputStream(paths[i]));
+               }
+            }
+            merge(configurationService.getInputStream(param.getValue()));
+            // Store the merged configuration
+            if (configurationPersister != null && !configurationPersister.hasConfig())
+            {
+               retain();
+            }
+         }
+      }
+      catch (RepositoryConfigurationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(new RepositoryConfigurationException("Fail to init from xml! Reason: " + e, e));
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void stop()
+   {
+   }
 }

Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationPlugin.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationPlugin.java	                        (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationPlugin.java	2009-10-05 11:01:34 UTC (rev 215)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+package org.exoplatform.services.jcr.impl.config;
+
+import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.services.jcr.config.RepositoryServiceConfiguration;
+
+/**
+ * This class allows us to add new {@link RepositoryServiceConfiguration} thanks to the component plugins
+ * 
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto 
+ *          nicolas.filotto at exoplatform.com
+ * 28 sept. 2009  
+ */
+public class RepositoryServiceConfigurationPlugin extends BaseComponentPlugin
+{
+
+   private final String confPath;
+   
+   public RepositoryServiceConfigurationPlugin(InitParams params)
+   {
+      ValueParam param = params == null ? null : params.getValueParam("conf-path");
+      if (param == null || param.getValue() == null || param.getValue().trim().length() == 0)
+      {
+         throw new IllegalArgumentException("The value-param 'conf-path' is mandatory, please check your configuration");
+      }
+      else
+      {
+         this.confPath = param.getValue().trim();
+      }
+   }
+
+   /**
+    * @return the path of the configuration file to retrieve
+    */
+   public String getConfPath()
+   {
+      return confPath;
+   }
+}



More information about the exo-jcr-commits mailing list