jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1344921 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/osgi/ main/java/org/apache/jackrabbit/oak/spi/commit/ test/java/org/apache/jackrabbit/oak/query/
Date Thu, 31 May 2012 21:35:33 GMT
Author: mduerig
Date: Thu May 31 21:35:33 2012
New Revision: 1344921

URL: http://svn.apache.org/viewvc?rev=1344921&view=rev
Log:
OAK-68: Extension point for commit validation
 - expose through OSGi

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
      - copied, changed from r1344774, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1344921&r1=1344920&r2=1344921&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Thu May 31 21:35:33 2012
@@ -68,7 +68,7 @@ public class ContentRepositoryImpl imple
      * test cases only.
      */
     public ContentRepositoryImpl() {
-        this(new MicroKernelImpl(), null);
+        this(new MicroKernelImpl(), null, null);
     }
 
     /**
@@ -78,14 +78,18 @@ public class ContentRepositoryImpl imple
      * @param microKernel underlying kernel instance
      * @param indexProvider index provider
      */
-    public ContentRepositoryImpl(MicroKernel microKernel, QueryIndexProvider indexProvider)
{
-        List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
-        providers.add(new NameValidatorProvider());
-        providers.add(new TypeValidatorProvider());
-        CompositeValidatorProvider compositeProvider = new CompositeValidatorProvider(providers);
+    public ContentRepositoryImpl(MicroKernel microKernel, QueryIndexProvider indexProvider,
+            ValidatorProvider validatorProvider) {
+
+        if (validatorProvider == null) {
+            List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
+            providers.add(new NameValidatorProvider());
+            providers.add(new TypeValidatorProvider());
+            validatorProvider = new CompositeValidatorProvider(providers);
+        }
 
         List<CommitHook> hooks = new ArrayList<CommitHook>();
-        hooks.add(new ValidatingCommitHook(compositeProvider));
+        hooks.add(new ValidatingCommitHook(validatorProvider));
         CompositeCommitHook compositeHook = new CompositeCommitHook(hooks);
 
         nodeStore = new KernelNodeStore(microKernel, compositeHook);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java?rev=1344921&r1=1344920&r2=1344921&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
Thu May 31 21:35:33 2012
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
@@ -30,6 +26,10 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
 public class Activator implements BundleActivator, ServiceTrackerCustomizer {
 
     private BundleContext context;
@@ -38,6 +38,8 @@ public class Activator implements Bundle
 
     private final OsgiIndexProvider indexProvider = new OsgiIndexProvider();
 
+    private final OsgiValidatorProvider validatorProvider = new OsgiValidatorProvider();
+
     private final Map<ServiceReference, ServiceRegistration> services =
             new HashMap<ServiceReference, ServiceRegistration>();
 
@@ -48,6 +50,7 @@ public class Activator implements Bundle
         context = bundleContext;
 
         indexProvider.start(bundleContext);
+        validatorProvider.start(bundleContext);
 
         tracker = new ServiceTracker(
                 context, MicroKernel.class.getName(), this);
@@ -59,6 +62,7 @@ public class Activator implements Bundle
         tracker.close();
 
         indexProvider.stop();
+        validatorProvider.stop();
     }
 
     //-------------------------------------------< ServiceTrackerCustomizer >---
@@ -70,7 +74,7 @@ public class Activator implements Bundle
             MicroKernel kernel = (MicroKernel) service;
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
-                    new ContentRepositoryImpl(kernel, indexProvider),
+                    new ContentRepositoryImpl(kernel, indexProvider, validatorProvider),
                     new Properties()));
             return service;
         } else {

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
(from r1344774, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java&r1=1344774&r2=1344921&rev=1344921&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
Thu May 31 21:35:33 2012
@@ -18,36 +18,35 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.oak.spi.QueryIndex;
-import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 /**
- * This index provider combines all indexes of all available OSGi index
+ * This validator provider combines all validators of all available OSGi validator
  * providers.
  */
-public class OsgiIndexProvider implements ServiceTrackerCustomizer, QueryIndexProvider {
+public class OsgiValidatorProvider implements ServiceTrackerCustomizer, ValidatorProvider
{
 
     private BundleContext context;
 
     private ServiceTracker tracker;
 
-    private final Map<ServiceReference, QueryIndexProvider> providers =
-        new HashMap<ServiceReference, QueryIndexProvider>();
+    private final Map<ServiceReference, ValidatorProvider> providers =
+        new HashMap<ServiceReference, ValidatorProvider>();
 
     public void start(BundleContext bundleContext) throws Exception {
         context = bundleContext;
         tracker = new ServiceTracker(
-                bundleContext, QueryIndexProvider.class.getName(), this);
+                bundleContext, ValidatorProvider.class.getName(), this);
         tracker.open();
     }
 
@@ -55,11 +54,13 @@ public class OsgiIndexProvider implement
         tracker.close();
     }
 
+    //------------------------------------------------------------< ServiceTrackerCustomizer
>---
+
     @Override
     public Object addingService(ServiceReference reference) {
         Object service = context.getService(reference);
-        if (service instanceof QueryIndexProvider) {
-            QueryIndexProvider provider = (QueryIndexProvider) service;
+        if (service instanceof ValidatorProvider) {
+            ValidatorProvider provider = (ValidatorProvider) service;
             providers.put(reference, provider);
             return service;
         } else {
@@ -79,16 +80,11 @@ public class OsgiIndexProvider implement
         context.ungetService(reference);
     }
 
+    //------------------------------------------------------------< ValidatorProvider
>---
+
     @Override
-    public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
-        if (providers.isEmpty()) {
-            return Collections.emptyList();
-        } else if (providers.size() == 1) {
-            return providers.get(0).getQueryIndexes(mk);
-        } else {
-            // TODO combine indexes
-            return null;
-        }
+    public Validator getRootValidator(NodeState before, NodeState after) {
+        return new CompositeValidatorProvider(providers.values())
+                .getRootValidator(before, after);
     }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java?rev=1344921&r1=1344920&r2=1344921&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
Thu May 31 21:35:33 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.spi.co
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -26,9 +27,9 @@ import java.util.List;
  * a single validator provider.
  */
 public class CompositeValidatorProvider implements ValidatorProvider {
-    private final List<ValidatorProvider> providers;
+    private final Collection<ValidatorProvider> providers;
 
-    public CompositeValidatorProvider(List<ValidatorProvider> providers) {
+    public CompositeValidatorProvider(Collection<ValidatorProvider> providers) {
         this.providers = providers;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1344921&r1=1344920&r2=1344921&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
Thu May 31 21:35:33 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.query;
 
-import javax.jcr.GuestCredentials;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.index.IndexWrapper;
@@ -26,6 +25,8 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 
+import javax.jcr.GuestCredentials;
+
 /**
  * AbstractQueryTest...
  */
@@ -41,7 +42,7 @@ public abstract class AbstractQueryTest 
         MicroKernel rawMk = new MicroKernelImpl();
         mk = new IndexWrapper(rawMk);
         Indexer indexer = new Indexer(mk, rawMk, Indexer.INDEX_CONFIG_ROOT);
-        rep = new ContentRepositoryImpl(mk, indexer);
+        rep = new ContentRepositoryImpl(mk, indexer, null);
         try {
             session = rep.login(new GuestCredentials(), "default");
             vf = session.getCoreValueFactory();



Mime
View raw message