You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/01/29 10:55:54 UTC

svn commit: r616230 - in /incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl: ObjectContentManagerFactoryImpl.java OcmFactoryAdapterFactory.java

Author: cziegeler
Date: Tue Jan 29 01:55:53 2008
New Revision: 616230

URL: http://svn.apache.org/viewvc?rev=616230&view=rev
Log:
RESOLVED - issue SLING-209: ResourceResource is not adaptable to OCM 
https://issues.apache.org/jira/browse/SLING-209

Added:
    incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java   (with props)
Modified:
    incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/ObjectContentManagerFactoryImpl.java

Modified: incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/ObjectContentManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/ObjectContentManagerFactoryImpl.java?rev=616230&r1=616229&r2=616230&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/ObjectContentManagerFactoryImpl.java (original)
+++ incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/ObjectContentManagerFactoryImpl.java Tue Jan 29 01:55:53 2008
@@ -66,6 +66,7 @@
  * The <code>ObjectContentManagerFactory</code> TODO
  *
  * @scr.component metadata="no"
+ * @scr.service name="org.apache.sling.jcr.ocm.ObjectContentManagerFactory"
  * @scr.property name="service.description"
  *               value="Sling Object Content Manager Factory"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
@@ -95,6 +96,8 @@
 
     private OcmAdapterFactory adapterFactory;
 
+    private OcmFactoryAdapterFactory factoryAdapterFactory;
+
     public ObjectContentManagerFactoryImpl() {
 
         // prepare the data converters and query manager
@@ -343,6 +346,7 @@
                 : new String[0];
         adapterFactory = new OcmAdapterFactory(this,
             componentContext.getBundleContext(), mappedClasses);
+        factoryAdapterFactory = new OcmFactoryAdapterFactory(this, componentContext.getBundleContext());
     }
 
     /** Deativates this component, called by SCR to take out of service */
@@ -350,6 +354,10 @@
         if (adapterFactory != null) {
             adapterFactory.dispose();
             adapterFactory = null;
+        }
+        if ( factoryAdapterFactory != null ) {
+            factoryAdapterFactory.dispose();
+            factoryAdapterFactory = null;
         }
 
         componentContext.getBundleContext().removeBundleListener(this);

Added: incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java?rev=616230&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java (added)
+++ incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java Tue Jan 29 01:55:53 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.ocm.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+class OcmFactoryAdapterFactory implements AdapterFactory {
+
+    private final ObjectContentManagerFactoryImpl ocmFactory;
+
+    private ServiceRegistration registration;
+
+    OcmFactoryAdapterFactory(ObjectContentManagerFactoryImpl factory, BundleContext bundleContext) {
+        this.ocmFactory = factory;
+
+        final Dictionary<String, Object> registrationProperties = new Hashtable<String, Object>();
+        registrationProperties.put(ADAPTABLE_CLASSES, ResourceResolver.class.getName());
+        registrationProperties.put(ADAPTER_CLASSES, ObjectContentManager.class.getName());
+        registrationProperties.put(Constants.SERVICE_DESCRIPTION, "Sling OCM Adapter Factory");
+        registrationProperties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        registration = bundleContext.registerService(SERVICE_NAME, this, registrationProperties);
+    }
+
+    void dispose() {
+        if (registration != null) {
+            registration.unregister();
+            registration = null;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public <AdapterType> AdapterType getAdapter(Object adaptable,
+            Class<AdapterType> type) {
+
+        // must work, we only support ResourceResolver
+        final ResourceResolver factory = (ResourceResolver) adaptable;
+
+        // the resource resolver must be adaptable to a session
+        final Session session = factory.adaptTo(Session.class);
+        if (session == null) {
+            return null;
+        }
+
+        return (AdapterType)this.ocmFactory.getObjectContentManager(session);
+    }
+}

Propchange: incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/jcr/ocm/src/main/java/org/apache/sling/jcr/ocm/impl/OcmFactoryAdapterFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url