This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.models.api-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-api.git
commit 1df4b0ed1519d24bd0793331867f93404ebf6951 Author: Justin Edelson <[email protected]> AuthorDate: Fri Aug 29 18:53:41 2014 +0000 SLING-3886 - adding support for adapter indirection where the adapting target is a superclass or implemented interface of the implementation class. Thanks to Stefan for the patch! git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/api@1621361 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/sling/models/annotations/Model.java | 16 +++++++- .../sling/models/spi/ImplementationPicker.java | 48 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/models/annotations/Model.java b/src/main/java/org/apache/sling/models/annotations/Model.java index 595b312..6b5616e 100644 --- a/src/main/java/org/apache/sling/models/annotations/Model.java +++ b/src/main/java/org/apache/sling/models/annotations/Model.java @@ -23,16 +23,30 @@ import java.lang.annotation.Target; /** * Mark a class as adaptable via Sling Models. - * */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Model { + /** + * @return List of classes from which can be adapted. + */ public Class<?>[] adaptables(); + /** + * @return List of classes to which can be adapted. If missing, the class that is annotated is used. + * If classes are given, they have to be either the annotated class itself, or interfaces or super classes of the class. + */ + public Class<?>[] adapters() default {}; + + /** + * @return Default injection strategy (optional or required) + */ public DefaultInjectionStrategy defaultInjectionStrategy() default DefaultInjectionStrategy.REQUIRED; + /** + * @return Condition that is displayed in the felix console adapter plugin + */ public String condition() default ""; } diff --git a/src/main/java/org/apache/sling/models/spi/ImplementationPicker.java b/src/main/java/org/apache/sling/models/spi/ImplementationPicker.java new file mode 100644 index 0000000..3a56b5a --- /dev/null +++ b/src/main/java/org/apache/sling/models/spi/ImplementationPicker.java @@ -0,0 +1,48 @@ +/* + * 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.models.spi; + +/** + * Defines a strategy to choose an implementation for a model if multiple are registered + * for the same interface or super class. + * <p> + * With using the @Model.adapters attribute it is possible to define interfaces or super + * classes to which the model implementation is an adaption target. It is possible that + * multiple models implement the same type. + * </p> + * <p> + * In this case services implementing the {@link ImplementationPicker} interface are + * queried to decide which implementation should be chosen. If multiple implementations + * of this interface exists they are queried one after another by service ranking. + * The first that picks an implementation is the winner. + * </p> + */ +public interface ImplementationPicker { + + /** + * Select an implementation for the adapter class to which the adaptable should be adapted to. + * @param adapterType Adapter type. Never null. + * @param implementationsTypes Available implementations. It is guaranteed that they can be assigned to the adapter type. + * Never null and has always at least one entry. + * @param adaptable For reference: the adaptable. May be enquired to detect the context of the adaption. Never null. + * @return If an implementation is chosen the class is returned, otherwise null. + */ + Class<?> pick(Class<?> adapterType, Class<?>[] implementationsTypes, Object adaptable); + +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
