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 2010/09/01 12:11:03 UTC
svn commit: r991494 - in /sling/trunk: bundles/api/
bundles/api/src/main/java/org/apache/sling/api/adapter/
bundles/api/src/main/java/org/apache/sling/api/resource/
bundles/extensions/adapter/
bundles/extensions/adapter/src/main/java/org/apache/sling/a...
Author: cziegeler
Date: Wed Sep 1 10:11:02 2010
New Revision: 991494
URL: http://svn.apache.org/viewvc?rev=991494&view=rev
Log:
SLING-1711 : Move SlingAdaptable from adapter bundle to api
Added:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java (with props)
Modified:
sling/trunk/bundles/api/pom.xml
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
sling/trunk/bundles/extensions/adapter/pom.xml
sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java
sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java
sling/trunk/launchpad/builder/src/main/bundles/list.xml
Modified: sling/trunk/bundles/api/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/pom.xml?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/api/pom.xml (original)
+++ sling/trunk/bundles/api/pom.xml Wed Sep 1 10:11:02 2010
@@ -88,8 +88,8 @@
http://sling.apache.org/site/sling-api.html
</Bundle-DocURL>
<Export-Package>
- org.apache.sling.api;version=2.1, <!-- 2.0.8 -->
- org.apache.sling.api.adapter;version=2.1,
+ org.apache.sling.api;version=2.1,
+ org.apache.sling.api.adapter;version=2.2,
org.apache.sling.api.auth;version=1.0,
org.apache.sling.api.request;version=2.1,
org.apache.sling.api.resource;version=2.1,
Added: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java?rev=991494&view=auto
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java (added)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java Wed Sep 1 10:11:02 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.api.adapter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The <code>SlingAdaptable</code> class is an (abstract) default
+ * implementation of the <code>Adaptable</code> interface. It just uses the
+ * default {@link org.apache.sling.api.adapter.AdapterManager} implemented
+ * to adapt itself to the requested type.
+ * <p>
+ * Extensions of this class may overwrite the {@link #adaptTo(Class)} method
+ * using their own knowledge of adapters and may call this base class
+ * implementation to fall back to an extended adapters.
+ *
+ * @since 2.2
+ */
+public abstract class SlingAdaptable implements Adaptable {
+
+ /** The adapter manager used for adapting the synthetic resource. */
+ private static volatile AdapterManager ADAPTER_MANAGER;
+
+ /**
+ * Set the adapter manager to be used by a synthetic resource. A bundle
+ * implementing the adapter manager can set the manager through this method.
+ * The set adapter manager will be used in the {@link #adaptTo(Class)}
+ * method of a synthetic resource.
+ *
+ * @param adapterMgr The adapter manager.
+ */
+ public static void setAdapterManager(final AdapterManager adapterMgr) {
+ ADAPTER_MANAGER = adapterMgr;
+ }
+
+ /**
+ * Unset an adapter manager previously set with
+ * {@link #setAdapterManager(AdapterManager)}. If this method is called with
+ * an <code>AdapterManager</code> different from the currently set one it
+ * has no effect.
+ *
+ * @param adapterMgr The adapter manager
+ */
+ public static void unsetAdapterManager(final AdapterManager adapterMgr) {
+ if (ADAPTER_MANAGER == adapterMgr) {
+ ADAPTER_MANAGER = null;
+ }
+ }
+
+ /** Cache */
+ private Map<Class<?>, Object> adaptersCache;
+
+ /**
+ * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ AdapterType result = null;
+ synchronized ( this ) {
+ if ( adaptersCache != null ) {
+ result = (AdapterType) adaptersCache.get(type);
+ }
+ if ( result == null ) {
+ final AdapterManager mgr = ADAPTER_MANAGER;
+ result = (mgr == null ? null : mgr.getAdapter(this, type));
+ if ( result != null ) {
+ if ( adaptersCache == null ) {
+ adaptersCache = new HashMap<Class<?>, Object>();
+ }
+ adaptersCache.put(type, result);
+ }
+ }
+ }
+ return result;
+ }
+}
Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java Wed Sep 1 10:11:02 2010
@@ -20,7 +20,7 @@ package org.apache.sling.api.resource;
import java.util.Iterator;
-import org.apache.sling.api.adapter.AdapterManager;
+import org.apache.sling.api.adapter.SlingAdaptable;
/**
* The <code>AbstractResource</code> is an abstract implementation of the
@@ -34,36 +34,9 @@ import org.apache.sling.api.adapter.Adap
*
* @since 2.1.0
*/
-public abstract class AbstractResource implements Resource {
-
- /** The adapter manager used for adapting the synthetic resource. */
- private static volatile AdapterManager ADAPTER_MANAGER;
-
- /**
- * Set the adapter manager to be used by a synthetic resource. A bundle
- * implementing the adapter manager can set the manager through this method.
- * The set adapter manager will be used in the {@link #adaptTo(Class)}
- * method of a synthetic resource.
- *
- * @param adapterMgr The adapter manager.
- */
- public static void setAdapterManager(final AdapterManager adapterMgr) {
- ADAPTER_MANAGER = adapterMgr;
- }
-
- /**
- * Unset an adapter manager previously set with
- * {@link #setAdapterManager(AdapterManager)}. If this method is called with
- * an <code>AdapterManager</code> different from the currently set one it
- * has no effect.
- *
- * @param adapterMgr The adapter manager
- */
- public static void unsetAdapterManager(final AdapterManager adapterMgr) {
- if (ADAPTER_MANAGER == adapterMgr) {
- ADAPTER_MANAGER = null;
- }
- }
+public abstract class AbstractResource
+ extends SlingAdaptable
+ implements Resource {
/**
* Returns the name of this resource.
@@ -85,12 +58,12 @@ public abstract class AbstractResource i
*/
@SuppressWarnings("deprecation")
public Resource getParent() {
- /*
- * Implemented calling the deprecated ResourceUtil.getParent method
- * (which actually has the implementation) to prevent problems if there
- * are implementations of the pre-2.1.0 Resource interface in the
- * framework.
- */
+ //
+ // Implemented calling the deprecated ResourceUtil.getParent method
+ // (which actually has the implementation) to prevent problems if there
+ // are implementations of the pre-2.1.0 Resource interface in the
+ // framework.
+ //
return ResourceUtil.getParent(this);
}
@@ -134,31 +107,11 @@ public abstract class AbstractResource i
* methods.
*/
public boolean isResourceType(String resourceType) {
- /*
- * Implemented calling the ResourceUtil.isA method (which actually has
- * the implementation) to prevent problems if there are implementations
- * of the pre-2.1.0 Resource interface in the framework.
- */
+ //
+ // Implemented calling the ResourceUtil.isA method (which actually has
+ // the implementation) to prevent problems if there are implementations
+ // of the pre-2.1.0 Resource interface in the framework.
+ //
return ResourceUtil.isA(this, resourceType);
}
-
- /**
- * If a adapter manager has been set through
- * {@link #setAdapterManager(AdapterManager)} this adapter manager is used
- * to adapt the resource to the given type. Otherwise this method returns
- * <code>null</code>.
- * <p>
- * This default base implementation is intended to be overwritten by
- * extensions. Overwriting implementations are are encouraged to call this
- * base class implementation if they themselves cannot adapt to the
- * requested type.
- */
- public <Type> Type adaptTo(Class<Type> type) {
- final AdapterManager adapterMgr = ADAPTER_MANAGER;
- if (adapterMgr != null) {
- return adapterMgr.getAdapter(this, type);
- }
- return null;
- }
-
}
Modified: sling/trunk/bundles/extensions/adapter/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/pom.xml?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/pom.xml (original)
+++ sling/trunk/bundles/extensions/adapter/pom.xml Wed Sep 1 10:11:02 2010
@@ -68,7 +68,7 @@
org.apache.sling.adapter.internal
</Private-Package>
<Import-Package>
- org.apache.sling.api.adapter;version="[2.0,2.3)",
+ org.apache.sling.api.adapter;version="[2.2,2.3)",
*
</Import-Package>
</instructions>
@@ -93,7 +93,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.8</version>
+ <version>2.1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java (original)
+++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java Wed Sep 1 10:11:02 2010
@@ -18,49 +18,19 @@
*/
package org.apache.sling.adapter;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.sling.adapter.internal.AdapterManagerImpl;
-import org.apache.sling.api.adapter.Adaptable;
-import org.apache.sling.api.adapter.AdapterManager;
/**
* The <code>SlingAdaptable</code> class is an (abstract) default
* implementation of the <code>Adaptable</code> interface. It just uses the
- * default {@link org.apache.sling.api.adapter.AdapterManager} implemented in this bundle to adapt the itself
- * to the requested type.
+ * default {@link org.apache.sling.api.adapter.AdapterManager} implemented
+ * in this bundle to adapt the itself to the requested type.
* <p>
* Extensions of this class may overwrite the {@link #adaptTo(Class)} method
* using their own knowledge of adapters and may call this base class
* implementation to fall back to an extended adapters.
+ * @deprecated Use the {@link org.apache.sling.api.adapter.SlingAdaptable} instead
*/
-public abstract class SlingAdaptable implements Adaptable {
-
- /** Cache */
- private Map<Class<?>, Object> adaptersCache;
+@Deprecated
+public abstract class SlingAdaptable extends org.apache.sling.api.adapter.SlingAdaptable {
- /**
- * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
- AdapterType result = null;
- synchronized ( this ) {
- if ( adaptersCache != null ) {
- result = (AdapterType) adaptersCache.get(type);
- }
- if ( result == null ) {
- final AdapterManager mgr = AdapterManagerImpl.getInstance();
- result = (mgr == null ? null : mgr.getAdapter(this, type));
- if ( result != null ) {
- if ( adaptersCache == null ) {
- adaptersCache = new HashMap<Class<?>, Object>();
- }
- adaptersCache.put(type, result);
- }
- }
- }
- return result;
- }
}
Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java (original)
+++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java Wed Sep 1 10:11:02 2010
@@ -55,26 +55,6 @@ import org.osgi.service.log.LogService;
*/
public class AdapterManagerImpl implements AdapterManager {
- /**
- * The singleton instance of this manager. This field is set when the
- * instance is {@link #activate(ComponentContext) activated} and cleared
- * when the instance is {@link #deactivate(ComponentContext) deactivated}.
- *
- * This field is set to public to make it easier for testing to provide
- * an own adapter manager implementation which can be used together
- * with {@link org.apache.sling.adapter.SlingAdaptable}s. (see SLING-1195).
- * As this class is private this field is not accessible in an OSGi environment!
- */
- public static AdapterManager INSTANCE;
-
- /**
- * Returns the instance of this class or <code>null</code> if no activate
- * yet.
- */
- public static AdapterManager getInstance() {
- return INSTANCE;
- }
-
/** @scr.reference cardinality="0..1" policy="dynamic" */
private LogService log;
@@ -171,15 +151,6 @@ public class AdapterManagerImpl implemen
}
// final "enable" this manager by setting the instance
- // do not overwrite the field if already set (this is unexpected
- // actually)
- if (AdapterManagerImpl.INSTANCE == null) {
- AdapterManagerImpl.INSTANCE = this;
- } else {
- log(LogService.LOG_WARNING,
- "Not setting Instance field: Set to another manager "
- + AdapterManagerImpl.INSTANCE, null);
- }
SyntheticResource.setAdapterManager(this);
}
@@ -188,15 +159,6 @@ public class AdapterManagerImpl implemen
*/
protected void deactivate(ComponentContext context) {
SyntheticResource.unsetAdapterManager(this);
- // "disable" the manager by clearing the instance
- // do not clear the field if not set to this instance
- if (AdapterManagerImpl.INSTANCE == this) {
- AdapterManagerImpl.INSTANCE = null;
- } else {
- log(LogService.LOG_WARNING,
- "Not clearing instance field: Set to another manager "
- + AdapterManagerImpl.INSTANCE, null);
- }
this.context = null;
}
Modified: sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java (original)
+++ sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java Wed Sep 1 10:11:02 2010
@@ -25,9 +25,9 @@ import static org.junit.Assert.assertTru
import java.util.Map;
-import org.apache.sling.adapter.SlingAdaptable;
import org.apache.sling.adapter.mock.MockAdapterFactory;
import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.adapter.SlingAdaptable;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -53,9 +53,7 @@ public class AdapterManagerTest {
}
@org.junit.After public void tearDown() {
- if (AdapterManagerImpl.getInstance() == am) {
- am.deactivate(null); // not correct, but argument unused
- }
+ am.deactivate(null); // not correct, but argument unused
}
/**
Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=991494&r1=991493&r2=991494&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Wed Sep 1 10:11:02 2010
@@ -41,7 +41,7 @@
<bundle>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.1.0</version>
+ <version>2.1.1-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.sling</groupId>
@@ -76,7 +76,7 @@
<bundle>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.adapter</artifactId>
- <version>2.0.6</version>
+ <version>2.0.7-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.sling</groupId>