Author: tolusha
Date: 2010-04-30 05:37:45 -0400 (Fri, 30 Apr 2010)
New Revision: 2344
Added:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/AddNamespacePluginHolder.java
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java
Log:
EXOJCR-570: registers namespace before repository start and persists it
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2010-04-29
14:34:43 UTC (rev 2343)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2010-04-30
09:37:45 UTC (rev 2344)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.impl;
import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.jmx.MX4JComponentAdapterFactory;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
@@ -31,6 +32,7 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.impl.core.AddNamespacePluginHolder;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceDataPersister;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
@@ -100,17 +102,52 @@
private final Log log =
ExoLogger.getLogger("exo.jcr.component.core.RepositoryContainer");
/**
+ * List of AddNamespacePlugin.
+ */
+ private List<ComponentPlugin> addNamespacePlugins;
+
+ /**
* RepositoryContainer constructor.
*
* @param parent
* container
* @param config
* Repository configuration
+ * @param addNamespacePlugins
+ * list of addNamespacePlugin
* @throws RepositoryException
* container initialization error
* @throws RepositoryConfigurationException
* configuration error
*/
+ public RepositoryContainer(ExoContainer parent, RepositoryEntry config,
List<ComponentPlugin> addNamespacePlugins)
+ throws RepositoryException, RepositoryConfigurationException
+ {
+
+ super(new MX4JComponentAdapterFactory(), parent);
+
+ // Defaults:
+ if (config.getAccessControl() == null)
+ config.setAccessControl(AccessControlPolicy.OPTIONAL);
+
+ this.config = config;
+ this.addNamespacePlugins = addNamespacePlugins;
+
+ registerComponents();
+ }
+
+ /**
+ * RepositoryContainer constructor.
+ *
+ * @param parent
+ * container
+ * @param config
+ * Repository configuration
+ * @throws RepositoryException
+ * container initialization error
+ * @throws RepositoryConfigurationException
+ * configuration error
+ */
public RepositoryContainer(ExoContainer parent, RepositoryEntry config) throws
RepositoryException,
RepositoryConfigurationException
{
@@ -503,7 +540,6 @@
private void registerRepositoryComponents() throws RepositoryConfigurationException,
RepositoryException
{
-
registerComponentImplementation(IdGenerator.class);
registerComponentImplementation(RepositoryIndexSearcherHolder.class);
@@ -512,6 +548,8 @@
registerComponentImplementation(LocationFactory.class);
registerComponentImplementation(ValueFactoryImpl.class);
+ registerComponentInstance(new AddNamespacePluginHolder(addNamespacePlugins));
+
registerComponentImplementation(JCRNodeTypeDataPersister.class);
registerComponentImplementation(NamespaceDataPersister.class);
registerComponentImplementation(NamespaceRegistryImpl.class);
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2010-04-29
14:34:43 UTC (rev 2343)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2010-04-30
09:37:45 UTC (rev 2344)
@@ -31,6 +31,7 @@
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener;
+import org.exoplatform.services.jcr.impl.core.AddNamespacePluginHolder;
import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.log.ExoLogger;
@@ -147,7 +148,7 @@
throw new RepositoryConfigurationException("Repository container " +
rEntry.getName() + " already started");
}
- RepositoryContainer repositoryContainer = new RepositoryContainer(parentContainer,
rEntry);
+ RepositoryContainer repositoryContainer = new RepositoryContainer(parentContainer,
rEntry, addNamespacesPlugins);
// Storing and starting the repository container under
// key=repository_name
@@ -156,8 +157,6 @@
repositoryContainers.put(rEntry.getName(), repositoryContainer);
managerStartChanges.registerListeners(repositoryContainer);
- addNamespaces(rEntry.getName());
-
repositoryContainer.start();
}
catch (Throwable t)
@@ -299,53 +298,6 @@
managerStartChanges.cleanup();
}
- private void addNamespaces() throws RepositoryException
- {
-
- for (RepositoryEntry repoConfig : config.getRepositoryConfigurations())
- {
- addNamespaces(repoConfig.getName());
- }
- }
-
- private void addNamespaces(String repositoryName) throws RepositoryException
- {
-
- ManageableRepository repository = getRepository(repositoryName);
- NamespaceRegistry nsRegistry = repository.getNamespaceRegistry();
-
- for (int j = 0; j < addNamespacesPlugins.size(); j++)
- {
- AddNamespacesPlugin plugin = (AddNamespacesPlugin)addNamespacesPlugins.get(j);
- Map<String, String> namespaces = plugin.getNamespaces();
- try
- {
- for (Map.Entry<String, String> namespace : namespaces.entrySet())
- {
-
- String prefix = namespace.getKey();
- String uri = namespace.getValue();
-
- // register namespace if not found
- try
- {
- nsRegistry.getURI(prefix);
- }
- catch (NamespaceException e)
- {
- nsRegistry.registerNamespace(prefix, uri);
- }
- if (log.isDebugEnabled())
- log.debug("Namespace is registered " + prefix + " =
" + uri);
- }
- }
- catch (Exception e)
- {
- log.error("Error load namespaces ", e);
- }
- }
- }
-
private void init(ExoContainer container) throws RepositoryConfigurationException,
RepositoryException
{
this.parentContainer = container;
Added:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/AddNamespacePluginHolder.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/AddNamespacePluginHolder.java
(rev 0)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/AddNamespacePluginHolder.java 2010-04-30
09:37:45 UTC (rev 2344)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core;
+
+import org.exoplatform.container.component.ComponentPlugin;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * AddNamespacePluginHolder is used in NamespaceRegistryImpl for registration
+ * namespaces from xml-configuration after repository start.
+ *
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy
Bazko</a>
+ * @version $Id: AddNamespacePluginHolder.java 111 2010-11-11 11:11:11Z tolusha $
+ */
+public class AddNamespacePluginHolder
+{
+ private final List<ComponentPlugin> addNamespacesPlugins;
+
+ /**
+ * AddNamespacePluginHolder constructor.
+ *
+ * @param componentPlugins
+ * list of AddNamespacesPlugins
+ */
+ public AddNamespacePluginHolder(List<ComponentPlugin> componentPlugins)
+ {
+ this.addNamespacesPlugins = new
ArrayList<ComponentPlugin>(componentPlugins);
+ }
+
+ /**
+ * @return unmodifiable list of AddNamespacesPlugins
+ */
+ public List<ComponentPlugin> getAddNamespacesPlugins()
+ {
+ return Collections.unmodifiableList(addNamespacesPlugins);
+ }
+}
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java 2010-04-29
14:34:43 UTC (rev 2343)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java 2010-04-30
09:37:45 UTC (rev 2344)
@@ -18,8 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.services.jcr.dataflow.DataManager;
import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.impl.AddNamespacesPlugin;
import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -99,6 +101,8 @@
private NamespaceDataPersister persister;
+ private AddNamespacePluginHolder addNamespacePluginHolder;
+
/**
* for tests.
*/
@@ -106,19 +110,35 @@
{
this.namespaces = new HashMap<String, String>(DEF_NAMESPACES);
this.prefixes = new HashMap<String, String>(DEF_PREFIXES);
+
this.dataManager = null;
this.indexSearcherHolder = null;
+ this.persister = null;
+ this.addNamespacePluginHolder = null;
}
public NamespaceRegistryImpl(NamespaceDataPersister persister, DataManager
dataManager,
RepositoryIndexSearcherHolder indexSearcherHolder)
{
+ this.namespaces = new HashMap<String, String>(DEF_NAMESPACES);
+ this.prefixes = new HashMap<String, String>(DEF_PREFIXES);
this.dataManager = dataManager;
this.indexSearcherHolder = indexSearcherHolder;
+ this.persister = persister;
+ this.addNamespacePluginHolder = null;
+ }
+
+ public NamespaceRegistryImpl(NamespaceDataPersister persister, DataManager
dataManager,
+ RepositoryIndexSearcherHolder indexSearcherHolder, AddNamespacePluginHolder
addNamespacePluginHolder)
+ {
this.namespaces = new HashMap<String, String>(DEF_NAMESPACES);
this.prefixes = new HashMap<String, String>(DEF_PREFIXES);
+
+ this.dataManager = dataManager;
+ this.indexSearcherHolder = indexSearcherHolder;
this.persister = persister;
+ this.addNamespacePluginHolder = addNamespacePluginHolder;
}
/**
@@ -257,7 +277,6 @@
{
if (!started)
{
-
// save default
if (persister != null)
{
@@ -278,6 +297,12 @@
throw new RuntimeException(e.getLocalizedMessage(), e);
}
}
+
+ if (addNamespacePluginHolder != null)
+ {
+ addPendingNamespaces();
+ }
+
started = true;
}
}
@@ -370,4 +395,37 @@
}
+ private void addPendingNamespaces()
+ {
+ for (ComponentPlugin plugin : addNamespacePluginHolder.getAddNamespacesPlugins())
+ {
+ Map<String, String> namespaces =
((AddNamespacesPlugin)plugin).getNamespaces();
+ try
+ {
+ for (Map.Entry<String, String> namespace : namespaces.entrySet())
+ {
+
+ String prefix = namespace.getKey();
+ String uri = namespace.getValue();
+
+ // register namespace if not found
+ try
+ {
+ getURI(prefix);
+ }
+ catch (NamespaceException e)
+ {
+ registerNamespace(prefix, uri);
+ }
+ if (log.isDebugEnabled())
+ log.debug("Namespace is registered " + prefix + " =
" + uri);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Error load namespaces ", e);
+ }
+ }
+ }
+
}