sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-models-api] 03/11: SLING-3716 SLING-3718 - adding support for constructor injection and self injection based on a patch from Stefan Seifert
Date Tue, 07 Nov 2017 09:54:31 GMT
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 58c47ddd3abacceb8bfd86b6f865c449b322a224
Author: Justin Edelson <justin@apache.org>
AuthorDate: Tue Aug 19 22:51:36 2014 +0000

    SLING-3716 SLING-3718 - adding support for constructor injection and self injection based
on a patch from Stefan Seifert
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/api@1619007
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/models/annotations/Default.java   |  2 +-
 .../apache/sling/models/annotations/Filter.java    |  2 +-
 .../apache/sling/models/annotations/Optional.java  |  2 +-
 .../apache/sling/models/annotations/Required.java  |  2 +-
 .../apache/sling/models/annotations/Source.java    |  2 +-
 .../org/apache/sling/models/annotations/Via.java   |  2 +-
 .../injectorspecific/ChildResource.java            |  5 ++--
 .../annotations/injectorspecific/OSGiService.java  |  5 ++--
 .../injectorspecific/RequestAttribute.java         |  5 ++--
 .../injectorspecific/ScriptVariable.java           |  5 ++--
 .../{RequestAttribute.java => Self.java}           | 22 +++++++-----------
 .../injectorspecific/ValueMapValue.java            |  6 +++--
 .../annotations/injectorspecific/package-info.java |  2 +-
 .../sling/models/annotations/package-info.java     |  2 +-
 .../apache/sling/models/spi/AcceptsNullName.java   | 27 ++++++++++++++++++++++
 .../org/apache/sling/models/spi/package-info.java  |  2 +-
 16 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/sling/models/annotations/Default.java b/src/main/java/org/apache/sling/models/annotations/Default.java
index aa0cc25..963a480 100644
--- a/src/main/java/org/apache/sling/models/annotations/Default.java
+++ b/src/main/java/org/apache/sling/models/annotations/Default.java
@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
 /**
  * Default value for an injection.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Default {
 
diff --git a/src/main/java/org/apache/sling/models/annotations/Filter.java b/src/main/java/org/apache/sling/models/annotations/Filter.java
index 355314c..c91f296 100644
--- a/src/main/java/org/apache/sling/models/annotations/Filter.java
+++ b/src/main/java/org/apache/sling/models/annotations/Filter.java
@@ -26,7 +26,7 @@ import javax.inject.Qualifier;
 /**
  * Provide a filter on an @Inject.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 @Source("osgi-services")
 @Qualifier
diff --git a/src/main/java/org/apache/sling/models/annotations/Optional.java b/src/main/java/org/apache/sling/models/annotations/Optional.java
index 5743495..39e068a 100644
--- a/src/main/java/org/apache/sling/models/annotations/Optional.java
+++ b/src/main/java/org/apache/sling/models/annotations/Optional.java
@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
 /**
  * Marker annotation for optional injections.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Optional {
 
diff --git a/src/main/java/org/apache/sling/models/annotations/Required.java b/src/main/java/org/apache/sling/models/annotations/Required.java
index 4bd87e7..8992377 100644
--- a/src/main/java/org/apache/sling/models/annotations/Required.java
+++ b/src/main/java/org/apache/sling/models/annotations/Required.java
@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
 /**
  * Marker annotation for required injections.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Required {
 
diff --git a/src/main/java/org/apache/sling/models/annotations/Source.java b/src/main/java/org/apache/sling/models/annotations/Source.java
index 0a23c0d..403b4ea 100644
--- a/src/main/java/org/apache/sling/models/annotations/Source.java
+++ b/src/main/java/org/apache/sling/models/annotations/Source.java
@@ -28,7 +28,7 @@ import javax.inject.Qualifier;
  * Can also be used as a meta-annotation to declare that some other annotation implies
  * a source.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE
})
 @Retention(RetentionPolicy.RUNTIME)
 @Qualifier
 public @interface Source {
diff --git a/src/main/java/org/apache/sling/models/annotations/Via.java b/src/main/java/org/apache/sling/models/annotations/Via.java
index 75683f7..e8b5b07 100644
--- a/src/main/java/org/apache/sling/models/annotations/Via.java
+++ b/src/main/java/org/apache/sling/models/annotations/Via.java
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
  * Indicate that this injection point should be handled using a projected
  * property of the adaptable.
  */
-@Target({ ElementType.FIELD, ElementType.METHOD })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Via {
 
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ChildResource.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ChildResource.java
index bce2cc2..26f32ce 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ChildResource.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ChildResource.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,10 +28,10 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject a child resource
+ * Annotation to be used on either methods, fields or constructor parameters to let Sling
Models inject a child resource
  *
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
 @Source("child-resources")
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/OSGiService.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/OSGiService.java
index 92b31bd..a4363c9 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/OSGiService.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/OSGiService.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,10 +28,10 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject an OSGi service
+ * Annotation to be used on either methods, fields or constructor parameters to let Sling
Models inject an OSGi service
  *
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
 @Source("osgi-services")
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
index 6b4d1a6..07626d4 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,11 +28,11 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject a
+ * Annotation to be used on either methods, fields or constructor parameters to let Sling
Models inject a
  * request attribute.
  *
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
 @Source("request-attributes")
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ScriptVariable.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ScriptVariable.java
index b08cece..d25c0e3 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ScriptVariable.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ScriptVariable.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,11 +28,11 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject a
+ * Annotation to be used on either methods, fields or constructor parameters to let Sling
Models inject a
  * script variable (from the {@link org.apache.sling.api.scripting.SlingBindings})
  *
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
 @Source("script-bindings")
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/Self.java
similarity index 76%
copy from src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
copy to src/main/java/org/apache/sling/models/annotations/injectorspecific/Self.java
index 6b4d1a6..b452a76 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/RequestAttribute.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/Self.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,26 +28,19 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject a
- * request attribute.
- *
+ * Annotation to be used on either methods, fields or constructor parameters to let Sling
Models
+ * inject the adaptable itself, or an object that can be adapted from it. 
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
-@Source("request-attributes")
-public @interface RequestAttribute {
+@Source("self")
+public @interface Self {
 
     /**
-     * Specifies the name of the request attribute. If empty or not set, then the name
-     * is derived from the method or field.
-     */
-    public String name() default "";
-
-    /**
-     * If set to true, the model can be instantiated even if there is no request attribute
-     * with the given name found.
+     * If set to true, the model can be instantiated even if there is no object that can
be adapted from the adaptable itself. 
      * Default = false.
      */
     public boolean optional() default false;
+
 }
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ValueMapValue.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ValueMapValue.java
index bbdaf80..4511d59 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ValueMapValue.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ValueMapValue.java
@@ -18,6 +18,7 @@ package org.apache.sling.models.annotations.injectorspecific;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -27,10 +28,11 @@ import org.apache.sling.models.annotations.Source;
 import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
 
 /**
- * Annotation to be used on either methods or fields to let Sling Models inject a value from
the ValueMap of the current resource.
+ * Annotation to be used on either methods, fields or constructor parameter to let Sling
Models
+ * inject a value from the ValueMap of the current resource.
  *
  */
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, PARAMETER })
 @Retention(RUNTIME)
 @InjectAnnotation
 @Source("valuemap")
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/package-info.java
b/src/main/java/org/apache/sling/models/annotations/injectorspecific/package-info.java
index da4fcdb..52eee68 100644
--- a/src/main/java/org/apache/sling/models/annotations/injectorspecific/package-info.java
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.0.0")
+@Version("1.0.2")
 package org.apache.sling.models.annotations.injectorspecific;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/models/annotations/package-info.java b/src/main/java/org/apache/sling/models/annotations/package-info.java
index 1413f05..59b91d4 100644
--- a/src/main/java/org/apache/sling/models/annotations/package-info.java
+++ b/src/main/java/org/apache/sling/models/annotations/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.1.0")
+@Version("1.1.2")
 package org.apache.sling.models.annotations;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/models/spi/AcceptsNullName.java b/src/main/java/org/apache/sling/models/spi/AcceptsNullName.java
new file mode 100644
index 0000000..3f0e80e
--- /dev/null
+++ b/src/main/java/org/apache/sling/models/spi/AcceptsNullName.java
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+/**
+ * Marker interface for an injector to declare that it ignores the name
+ * parameter.
+ *
+ */
+public interface AcceptsNullName {
+}
diff --git a/src/main/java/org/apache/sling/models/spi/package-info.java b/src/main/java/org/apache/sling/models/spi/package-info.java
index e63fa96..93327e5 100644
--- a/src/main/java/org/apache/sling/models/spi/package-info.java
+++ b/src/main/java/org/apache/sling/models/spi/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.0.0")
+@Version("1.0.2")
 package org.apache.sling.models.spi;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message