You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/01/17 16:14:35 UTC
svn commit: r612839 - in
/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter:
AdapterFactory.java AdapterManager.java
Author: fmeschbe
Date: Thu Jan 17 07:13:35 2008
New Revision: 612839
URL: http://svn.apache.org/viewvc?rev=612839&view=rev
Log:
Move AdapterFactory and AdapterManager interfaces to the Sling API
(out of osgi/commons) as suggested by Carsten
Added:
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterManager.java
Added: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java?rev=612839&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java (added)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java Thu Jan 17 07:13:35 2008
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+/**
+ * The <code>AdapterFactory</code> interface defines the API for helpers which
+ * may be provided to enhance the adaptability of adaptable objects.
+ * <p>
+ * Implementations of this interface are registered as OSGi services and are
+ * used by the {@link AdapterManager} to adapt objects on demand. The
+ * <code>AdapterFactory</code> services are not really intended to be used by
+ * clients directly.
+ */
+public interface AdapterFactory {
+
+ /**
+ * The service name to use when registering implementations of this
+ * interface as services (value is
+ * "org.apache.sling.osgi.commons.AdapterFactory").
+ */
+ static final String SERVICE_NAME = AdapterFactory.class.getName();
+
+ /**
+ * The service registration property listing the fully qualified names of
+ * classes which can be adapted by this adapter factory (value is
+ * "adaptables"). The "adaptable" parameters of the
+ * {@link #getAdapter(Object, Class)} method must be an instance of any of
+ * these classes for this factory to be able to adapt the object.
+ */
+ static final String ADAPTABLE_CLASSES = "adaptables";
+
+ /**
+ * The service registration property listing the fully qualified names of
+ * classes to which this factory can adapt adaptables (value is "adapters").
+ */
+ static final String ADAPTER_CLASSES = "adapters";
+
+ /**
+ * Adapt the given object to the adaptable type. The adaptable object is
+ * guaranteed to be an instance of one of the classes listed in the
+ * {@link #ADAPTABLE_CLASSES} services registration property. The type
+ * parameter is on of the classes listed in the {@link #ADAPTER_CLASSES}
+ * service registration properties.
+ * <p>
+ * This method may return <code>null</code> if the adaptable object may
+ * not be adapted to the adapter (target) type for any reason. In this case,
+ * the implementation should log a message to the log facility noting the
+ * cause for not being able to adapt.
+ * <p>
+ * Note that the <code>adaptable</code> object is not required to
+ * implement the <code>Adaptable</code> interface, though most of the time
+ * this method is called by means of calling the
+ * {@link SlingAdaptable#adaptTo(Class)} method.
+ *
+ * @param <AdapterType> The generic type of the adapter (target) type.
+ * @param adaptable The object to adapt to the adapter type.
+ * @param type The type to which the object is to be adapted.
+ * @return The adapted object or <code>null</code> if this factory
+ * instance cannot adapt the object.
+ */
+ <AdapterType> AdapterType getAdapter(Object adaptable,
+ Class<AdapterType> type);
+
+}
Added: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterManager.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterManager.java?rev=612839&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterManager.java (added)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/AdapterManager.java Thu Jan 17 07:13:35 2008
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+/**
+ * The <code>AdapterManager</code> defines the service interface for a manager
+ * for object adaption. The adapter manager coordinates the registered
+ * {@link AdapterFactory} services on behalf of clients wishing to adapt objects
+ * to other types. One such client is the {@link SlingAdaptable} class, which
+ * uses the implementation of this bundle to adapt "itself".
+ * <p>
+ * This interface is not intended to be implemented by clients.
+ */
+public interface AdapterManager {
+
+ /**
+ * Returns an adapter object of the requested <code>AdapterType</code> for
+ * the given <code>adaptable</code> object.
+ * <p>
+ * The <code>adaptable</code> object may be any non-<code>null</code>
+ * object and is not required to implement the <code>Adaptable</code>
+ * interface.
+ *
+ * @param <AdapterType> The generic type of the adapter (target) type.
+ * @param adaptable The object to adapt to the adapter type.
+ * @param type The type to which the object is to be adapted.
+ * @return The adapted object or <code>null</code> if no factory exists to
+ * adapt the <code>adaptable</code> to the
+ * <code>AdapterType</code> or if the <code>adaptable</code>
+ * cannot be adapted for any other reason.
+ */
+ <AdapterType> AdapterType getAdapter(Object adaptable,
+ Class<AdapterType> type);
+
+}
\ No newline at end of file