You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2013/11/06 15:29:49 UTC
svn commit: r1539345 [2/2] - in /sling/whiteboard/dklco: dynamic-proxy/
dynamic-proxy/src/main/java/org/apache/sling/commons/
dynamic-proxy/src/main/java/org/apache/sling/extensions/
dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/...
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/reflection/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/reflection/package-info.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/reflection/package-info.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/reflection/package-info.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides helper classes for interacting with Classes, Annotations and Methods.
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+package org.apache.sling.extensions.dynamicproxy.impl.reflection;
+
+import aQute.bnd.annotation.Version;
+
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedChildrenTO.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedChildrenTO.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedChildrenTO.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedChildrenTO.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,79 @@
+/*
+ * 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.extensions.dynamicproxy.impl.to;
+
+import java.lang.reflect.Method;
+
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingChildren;
+
+/**
+ * Transfer object for SlingChildren method invocations.
+ */
+public final class InvokedChildrenTO extends PathBasedInvokedTO {
+
+ /**
+ * Returns a new instance of the InvokedChildrenTO
+ *
+ * @param method
+ * the method being invoked
+ * @return the InvokedChildrenTO
+ */
+ public static InvokedChildrenTO newInstance(Method method) {
+ SlingChildren sc = method.getAnnotation(SlingChildren.class);
+ String path = sc.path();
+ InvokedChildrenTO to = new InvokedChildrenTO(method, sc, path);
+ return to;
+ }
+
+ /**
+ * The generic type to return when constructing the Iterator of children.
+ */
+ private final Class<?> returnType;
+
+ /**
+ * Constructs a new Invoked Children Transfer Object.
+ *
+ * @param method
+ * the invoked method
+ * @param args
+ * the method arguments
+ * @param path
+ * the path specified in the annotation
+ * @param returnType
+ * the return type specified in the annotation
+ * @param mt
+ * the method type
+ */
+ protected InvokedChildrenTO(final Method method, final SlingChildren sc,
+ final String path) {
+ super(method, path);
+ this.returnType = sc.returnType();
+ }
+
+ /**
+ * Gets the generic type to return when constructing the Iterator of
+ * children.
+ *
+ * @return the returnType
+ */
+ public final Class<?> getReturnType() {
+ return this.returnType;
+ }
+
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedPropertyTO.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedPropertyTO.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedPropertyTO.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedPropertyTO.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,207 @@
+/*
+ * 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.extensions.dynamicproxy.impl.to;
+
+import java.lang.reflect.Method;
+
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingProperty;
+
+/**
+ * InvokedPropertyTO - Transfer Object Meant as a convenient way to maintain and
+ * pass a method invocation around The members are not private because the class
+ * is package protected and they are final.
+ */
+public final class InvokedPropertyTO extends PathBasedInvokedTO {
+
+ /**
+ * Returns a new instance of the InvokedPropertyTO
+ *
+ * @param method
+ * the method being invoked
+ * @return the InvokedPropertyTO
+ */
+ public static InvokedPropertyTO newInstance(Method method) {
+ SlingProperty sp = method.getAnnotation(SlingProperty.class);
+ InvokedPropertyTO to = new InvokedPropertyTO(method, sp, sp.path());
+ return to;
+ }
+
+ /** The default bytes. */
+ private final byte[] defaultBytes;
+
+ /** The default date. */
+ private final long defaultDate;
+
+ /** The default double. */
+ private final double defaultDouble;
+
+ /** The default int. */
+ private final int defaultInt;
+
+ /** The default long. */
+ private final long defaultLong;
+
+ /** The default string. */
+ private final String defaultString;
+
+ /** The default strings. */
+ private final String[] defaultStrings;
+
+ /** The property name specified in the annotation. */
+ private final String name;
+
+ /**
+ * The full property name, calculated from the path and name from the
+ * annotation parameters.
+ */
+ private final String propertyName;
+
+ /** The use default flag. */
+ private final boolean useDefault;
+
+ /** The default boolean value */
+ private final boolean defaultBoolean;
+
+ /**
+ * Constructs a new Invoked Transfer Object.
+ *
+ * @param method
+ * the invoked method
+ * @param sp
+ * the sling property annotation
+ * @param path
+ * the path annotation value
+ */
+ protected InvokedPropertyTO(final Method method, SlingProperty sp,
+ String path) {
+ super(method, path);
+ this.name = sp.name();
+ this.propertyName = (path != null ? path + "/" : "") + name;
+ this.defaultBoolean = sp.defaultBoolean();
+ this.defaultBytes = sp.defaultBytes();
+ this.defaultDate = sp.defaultDate();
+ this.defaultDouble = sp.defaultDouble();
+ this.defaultInt = sp.defaultInt();
+ this.defaultLong = sp.defaultLong();
+ this.defaultString = sp.defaultString();
+ this.defaultStrings = sp.defaultStrings();
+ this.useDefault = sp.useDefault();
+
+ }
+
+ /**
+ * Gets the default boolean value.
+ *
+ * @return the default boolean
+ */
+ public boolean getDefaultBoolean() {
+ return this.defaultBoolean;
+ }
+
+ /**
+ * Gets the default bytes.
+ *
+ * @return the default bytes
+ */
+ public byte[] getDefaultBytes() {
+ return this.defaultBytes;
+ }
+
+ /**
+ * Gets the default date.
+ *
+ * @return the default date
+ */
+ public long getDefaultDate() {
+ return this.defaultDate;
+ }
+
+ /**
+ * Gets the default double.
+ *
+ * @return the default double
+ */
+ public double getDefaultDouble() {
+ return this.defaultDouble;
+ }
+
+ /**
+ * Gets the default integer.
+ *
+ * @return the default integer
+ */
+ public Integer getDefaultInt() {
+ return this.defaultInt;
+ }
+
+ /**
+ * Gets the default long.
+ *
+ * @return the default long
+ */
+ public long getDefaultLong() {
+ return this.defaultLong;
+ }
+
+ /**
+ * Gets the default string.
+ *
+ * @return the default string
+ */
+ public String getDefaultString() {
+ return this.defaultString;
+ }
+
+ /**
+ * Gets the default strings.
+ *
+ * @return the default strings
+ */
+ public String[] getDefaultStrings() {
+ return this.defaultStrings;
+ }
+
+ /**
+ * Get the name annotation value.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Get the property name to retrieve, this is calculated from the annotation
+ * name and path.
+ *
+ * @return the property name
+ */
+ public String getPropertyName() {
+ return this.propertyName;
+ }
+
+ /**
+ * Checks if is use default.
+ *
+ * @return true, if is use default
+ */
+ public boolean isUseDefault() {
+ return this.useDefault;
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedTO.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedTO.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedTO.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/InvokedTO.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,101 @@
+/*
+ * 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.extensions.dynamicproxy.impl.to;
+
+import java.lang.reflect.Method;
+
+import org.apache.sling.extensions.dynamicproxy.impl.lang.MethodType;
+
+/**
+ * Represents a method invocation on the InvocationHandler.
+ */
+public class InvokedTO {
+
+ /**
+ * The method which was invokedF
+ */
+ private Method method;
+
+ /**
+ * The type of the method being invoked.
+ */
+ private MethodType mt;
+
+ /**
+ * Constructs a new InvokedTO from the method.
+ *
+ * @param method
+ * the method being invoked
+ */
+ protected InvokedTO(Method method) {
+ this.method = method;
+ this.mt = MethodType.getMethodType(method);
+ }
+
+ /**
+ * Gets the method which was invoked.
+ *
+ * @return the invoked method
+ */
+ public Method getMethod() {
+ return method;
+ }
+
+ /**
+ * Gets the type of method which was invoked.
+ *
+ * @return the type of method invoked
+ */
+ public MethodType getMethodType() {
+ return mt;
+ }
+
+ /**
+ * Checks whether or not the method invoked was a getter.
+ *
+ * @return true if the method is a JavaBean getter
+ */
+ public boolean isGetter() {
+ return MethodType.contains(new MethodType[] { MethodType.JavaBeanIs,
+ MethodType.JavaBeanGet }, this.mt);
+ }
+
+ /**
+ * Checks whether or not the method invoked is compliant with JavaBean
+ * naming conventions.
+ *
+ * @return true if the method is a valid JavaBean method
+ */
+ public boolean isJavaBean() {
+ return MethodType.contains(new MethodType[] { MethodType.JavaBeanIs,
+ MethodType.JavaBeanGet, MethodType.JavaBeanSet }, this.mt);
+ }
+
+ /**
+ * Checks if the method is of the specified type.
+ *
+ * @param _mt
+ * the type to check
+ * @return if the method invoked is the same type as the specified method
+ * type
+ */
+ public boolean isType(final MethodType _mt) {
+ return this.mt == _mt;
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/PathBasedInvokedTO.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/PathBasedInvokedTO.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/PathBasedInvokedTO.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/PathBasedInvokedTO.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.extensions.dynamicproxy.impl.to;
+
+import java.lang.reflect.Method;
+
+/**
+ * PathBasedInvokedTO - Transfer Object Meant as a convenient way to maintain and
+ * pass a method invocation around The members are not private because the class
+ * is package protected and they are final.
+ */
+public class PathBasedInvokedTO extends InvokedTO {
+
+ /**
+ * The path from the annotations
+ */
+ private final String path;
+
+ /**
+ * Constructs a new Base Invoked Transfer Object.
+ *
+ * @param method
+ * the method being invoked
+ * @param path
+ * the path from the annotations
+ * @param mt
+ * the type of method being invoked
+ */
+ public PathBasedInvokedTO(final Method method, final String path) {
+ super(method);
+ this.path = path;
+ }
+
+ /**
+ * Gets the path specified in the annotation.
+ *
+ * @return the path
+ */
+ public final String getPath() {
+ return this.path;
+ }
+
+ /**
+ * Checks whether or not the path is absolute (starts with '/').
+ *
+ * @return true if the path is relative
+ */
+ public boolean isAbsolute() {
+ return (this.path != null) && this.path.startsWith("/");
+ }
+
+ /**
+ * Checks whether or not the path is relative (does not start with '/').
+ *
+ * @return true if the path is relative
+ */
+ public boolean isRelative() {
+ return (this.path != null) && !this.isAbsolute()
+ && this.path.contains("/");
+ }
+
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/SlingServiceInvocationTO.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/SlingServiceInvocationTO.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/SlingServiceInvocationTO.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/SlingServiceInvocationTO.java Wed Nov 6 14:29:48 2013
@@ -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.extensions.dynamicproxy.impl.to;
+
+import java.lang.reflect.Method;
+
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingServiceInvocation;
+
+/**
+ * Transfer object for SlingServiceInvocation method invocations.
+ */
+public final class SlingServiceInvocationTO extends InvokedTO {
+
+ /**
+ * The service to invoke
+ */
+ private final Class<?> service;
+
+ /**
+ * The method arguments
+ */
+ private Object[] args;
+
+ /**
+ * Gets a new instance of the SlingServiceInvocationTO.
+ *
+ * @param method
+ * the method being invoked
+ * @param args
+ * the method arguments
+ * @return a new SlingServiceInvocationTO
+ */
+ public static SlingServiceInvocationTO newInstance(Method method,
+ Object[] args) {
+ SlingServiceInvocationTO to = new SlingServiceInvocationTO(method, args);
+ return to;
+ }
+
+ /**
+ * Constructs a new Invoked Children Transfer Object.
+ *
+ * @param method
+ * the invoked method
+ * @param args
+ * the method arguments
+ * @param service
+ * the service to invoke
+ * @param mt
+ * the method type
+ */
+ protected SlingServiceInvocationTO(final Method method, Object[] args) {
+ super(method);
+ SlingServiceInvocation ssi = method
+ .getAnnotation(SlingServiceInvocation.class);
+ this.service = ssi.service();
+ this.args = args;
+ }
+
+ /**
+ * Gets the parameters passed into the method
+ *
+ * @return the arguments
+ */
+ public Object[] getArgs() {
+ return args;
+ }
+
+ /**
+ * Gets the service to invoke
+ *
+ * @return the service
+ */
+ public final Class<?> getService() {
+ return this.service;
+ }
+
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/package-info.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/package-info.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/impl/to/package-info.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides the Transfer Objects for transferring method invocation data.
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+package org.apache.sling.extensions.dynamicproxy.impl.to;
+
+import aQute.bnd.annotation.Version;
+
Added: sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/package-info.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/package-info.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/main/java/org/apache/sling/extensions/dynamicproxy/package-info.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides an implementation of the Java Dynamic Proxy API for Apache Sling.
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+package org.apache.sling.extensions.dynamicproxy;
+
+import aQute.bnd.annotation.Version;
+
Modified: sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/annotations.md
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/annotations.md?rev=1539345&r1=1534883&r2=1539345&view=diff
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/annotations.md (original)
+++ sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/annotations.md Wed Nov 6 14:29:48 2013
@@ -28,7 +28,6 @@ Annotation used to mark a Method as retr
The child Resources at the path will be returned as an Iterator of either a resource or the type specified in the returnType property, according to the following rules (in order):
-
* If the return type is an instance of a Resource, the resource at the path will be returned
* If adapting the resource into the return class returns a non-null, this object will be returned
* If using the ProxyService to retrieve a proxy instance does not throw and error and does not return null, the resulting object will returned
@@ -87,6 +86,11 @@ The following return types are supported
| Calendar | defaultDate |
| Date | defaultDate |
| Double | defaultDouble |
+| Integer | defaultInteger |
+| int | defaultInteger |
+| int | defaultInteger |
+| Long | defaultLong |
+| long | defaultLong |
| String | defaultString |
| String[] | defaultStrings |
@@ -137,4 +141,35 @@ The following parameters can be specifie
| Name | Description | Type | Default |
|--|--|--|--|
-| path | The path to the resource being referenced, if it begins with '/' it will be treated as an absolute path, otherwise, it will be treated as a relative path. | String | |
\ No newline at end of file
+| path | The path to the resource being referenced, if it begins with '/' it will be treated as an absolute path, otherwise, it will be treated as a relative path. | String | |
+
+## SlingServiceInvocation
+
+Annotation used to mark a Method as returning the result of a method on another service. When the method on the proxy interface is invoked, it will retrieve an instance of the Service and attempt to find a method matching the signature of the proxy method. If the first parameter of the method is the proxy interface, the proxy will inject an instance of itself.
+
+Below are two examples, showing configurations, they assume you have a service with the interface:
+
+ public interface MyCustomService {
+ Resource doStuff();
+ Resource doOtherStuff(MyProxy proxy);
+ Resource doEvenMoreStuff(MyProxy proxy, String path);
+ }
+
+
+
+ @SlingServiceInvocation(service = MyCustomService.class)
+ Resource doStuff();
+
+ @SlingServiceInvocation(service = MyCustomService.class)
+ Resource doOtherStuff();
+
+ @SlingServiceInvocation(service = MyCustomService.class)
+ Resource doEvenMoreStuff(String path);
+
+### Parameters
+
+The following parameters can be specified for the `@SlingServiceInvocation` annotation to configure how the properties is retrieved.
+
+| Name | Description | Type | Default |
+|--|--|--|--|
+| service | The service interface to reference. This service should have a single implementation and should have a method matching the signature of the method upon which this annotation is added. | Class<?> | |
\ No newline at end of file
Modified: sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/index.md
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/index.md?rev=1539345&r1=1534883&r2=1539345&view=diff
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/index.md (original)
+++ sling/whiteboard/dklco/dynamic-proxy/src/site/markdown/index.md Wed Nov 6 14:29:48 2013
@@ -24,7 +24,7 @@ Sling Proxy allows you to develop interf
## Creating a Sling Proxy
-To create a Sling Proxy, simply create an interface which extends the SlingProxy interface. All methods on the interface should be annotated with one of the [Sling Proxy Annotations](annotations.html)
+To create a Sling Proxy, simply create an interface which extends the SlingProxy interface. All methods on the interface should be annotated with one of the [Sling Proxy Annotations](annotations.html).
## Retrieving a Sling Proxy Instance
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/BaseSlingProxyTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/BaseSlingProxyTest.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/BaseSlingProxyTest.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/BaseSlingProxyTest.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,82 @@
+/*
+ * 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.extensions.dynamicproxy;
+
+import org.apache.sling.commons.testing.sling.MockResource;
+import org.apache.sling.commons.testing.sling.MockResourceResolver;
+import org.apache.sling.extensions.dynamicproxy.SlingProxy;
+import org.apache.sling.extensions.dynamicproxy.SlingProxyService;
+import org.apache.sling.extensions.dynamicproxy.impl.DefaultSlingProxyServiceImpl;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base SlingProxy test class. Sets up the Sling mock objects.
+ */
+public class BaseSlingProxyTest {
+ public static final String TITLE = "My Title";
+ public static final String CONTENT_RESOURCE_TYPE = "myapp/components/page";
+ public static final String PAGE_RESOURCE_TYPE = "myapp:Page";
+ private final static Logger log = LoggerFactory
+ .getLogger(TestSlingPropertyProxy.class);
+ protected final MockResourceResolver resolver = new MockResourceResolver();
+ protected final SlingProxyService slingProxyService = new DefaultSlingProxyServiceImpl();
+
+ /**
+ * Sets up the Sling mock objects
+ *
+ * @throws Exception
+ */
+ @Before
+ public void init() throws Exception {
+ log.info("init");
+
+ log.info("Creating Mock Resources");
+ final MockResource pageResource = new MockResource(resolver,
+ "/content/test", PAGE_RESOURCE_TYPE) {
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ if (SlingProxy.class.isAssignableFrom(type)) {
+ return slingProxyService.getProxy(this, type);
+ } else {
+ return super.adaptTo(type);
+ }
+ }
+ };
+ pageResource.addProperty("sling:resourceType", PAGE_RESOURCE_TYPE);
+ resolver.addResource(pageResource);
+ final MockResource contentResource = new MockResource(resolver,
+ "/content/test/jcr:content", CONTENT_RESOURCE_TYPE) {
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ if (SlingProxy.class.isAssignableFrom(type)) {
+ return slingProxyService.getProxy(this, type);
+ } else {
+ return super.adaptTo(type);
+ }
+ }
+ };
+ contentResource.addProperty("jcr:title", TITLE);
+ contentResource
+ .addProperty("sling:resourceType", CONTENT_RESOURCE_TYPE);
+ contentResource.addProperty("active", false);
+ resolver.addResource(contentResource);
+
+ log.info("Initialization complete");
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingDefaultProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingDefaultProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingDefaultProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingDefaultProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,98 @@
+/*
+ * 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.extensions.dynamicproxy;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.extensions.dynamicproxy.samples.SlingDefaultsProxy;
+import org.apache.tika.io.IOUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests the default value capability in the Sling Proxy.
+ */
+public class TestSlingDefaultProxy extends BaseSlingProxyTest {
+
+ private static final Logger log = LoggerFactory
+ .getLogger(TestSlingDefaultProxy.class);
+
+ /**
+ * This test checks all of the default value options, ensuring the correct
+ * default value is returned.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testDefaults() throws IOException {
+
+ log.info("Testing defaults");
+
+ Resource resource = resolver.getResource("/content/test/jcr:content");
+
+ SlingDefaultsProxy sdp = this.slingProxyService.getProxy(resource,
+ SlingDefaultsProxy.class);
+
+ assertFalse(sdp.getBoolean());
+ assertArrayEquals(new byte[0], sdp.getBytes());
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(0);
+ assertEquals(cal, sdp.getCalendarDate());
+ assertEquals(new Date(0), sdp.getDate());
+ assertEquals(1.0, sdp.getDouble(), 1.0);
+ byte[] data = IOUtils.toByteArray(sdp.getInputStream());
+ assertArrayEquals(new byte[0], data);
+
+ assertEquals(10, sdp.getInt());
+ assertEquals(10, sdp.getLong());
+ assertEquals("bob", sdp.getString());
+ assertArrayEquals(new String[] { "bob", "jones" }, sdp.getStrings());
+
+ log.info("Tests successful");
+ }
+
+ /**
+ * This test checks to ensure the proxy returns the original value if a
+ * value is set instead of the default value.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testDefaultWithValue() throws IOException {
+ log.info("Testing default with a value");
+
+ Resource resource = resolver.getResource("/content/test");
+
+ SlingDefaultsProxy sdp = this.slingProxyService.getProxy(resource,
+ SlingDefaultsProxy.class);
+
+ assertEquals(BaseSlingProxyTest.TITLE, sdp.getBackupTitle());
+
+ log.info("Test successful");
+ }
+
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingPropertyProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingPropertyProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingPropertyProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/TestSlingPropertyProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,68 @@
+/*
+ * 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.extensions.dynamicproxy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.extensions.dynamicproxy.samples.NoAnnotationSlingProxy;
+import org.apache.sling.extensions.dynamicproxy.samples.SlingPropertyProxy;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests the Sling Proxy retrieval of properties.
+ */
+public class TestSlingPropertyProxy extends BaseSlingProxyTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(TestSlingPropertyProxy.class);
+
+ @Test
+ public void runTests() {
+
+ log.info("runTests");
+
+ Resource resource = resolver.getResource("/content/test/jcr:content");
+ try {
+ NoAnnotationSlingProxy simpleSlingProxy = resource
+ .adaptTo(NoAnnotationSlingProxy.class);
+ fail("Expected UnsupportedOperationException getting: "
+ + simpleSlingProxy);
+ } catch (UnsupportedOperationException uoe) {
+ log.debug("Passed initial test");
+ }
+
+ Resource pageResource = resolver.getResource("/content/test");
+ SlingPropertyProxy pageProxy = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+
+ log.info("Testing backing resource");
+ assertEquals(pageProxy.getBackingResource(), pageResource);
+
+ log.info("Testing property retrieval");
+ assertEquals(TITLE, pageProxy.getTitle());
+ assertEquals(PAGE_RESOURCE_TYPE, pageProxy.getSlingResourceType());
+ assertEquals(null, pageProxy.getNonExistentProperty());
+ assertEquals(false, pageProxy.isActive());
+
+ log.info("Tests Successful");
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPEquals.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPEquals.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPEquals.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPEquals.java Wed Nov 6 14:29:48 2013
@@ -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.extensions.dynamicproxy.lang;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.extensions.dynamicproxy.BaseSlingProxyTest;
+import org.apache.sling.extensions.dynamicproxy.SlingProxyService;
+import org.apache.sling.extensions.dynamicproxy.impl.DefaultSlingProxyServiceImpl;
+import org.apache.sling.extensions.dynamicproxy.samples.DuplicateSlingPropertyProxy;
+import org.apache.sling.extensions.dynamicproxy.samples.SlingPropertyProxy;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for the Sling Proxy hashCode implementation.
+ */
+public class TestJDPEquals extends BaseSlingProxyTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(TestJDPEquals.class);
+
+ /**
+ * All of the tests for the hashCode implementation.
+ */
+ @Test
+ public void runTests() {
+
+ log.info("runTests");
+
+ Resource pageResource = resolver.getResource("/content/test");
+ SlingPropertyProxy pageProxy = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+
+ log.info("Testing Equals functionality");
+
+ log.info("Ensuring the same proxy interface from the same resource are equal");
+ SlingPropertyProxy pageProxy2 = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+ assertTrue(pageProxy.equals(pageProxy2));
+
+ log.info("Ensuring different proxy interfaces from the same resource are not equal");
+ DuplicateSlingPropertyProxy pageProxy3 = pageResource
+ .adaptTo(DuplicateSlingPropertyProxy.class);
+ assertFalse(pageProxy.equals(pageProxy3));
+
+
+ log.info("Ensuring retrieving the same proxy from different proxy services are equal");
+ SlingProxyService slingProxyService2 = new DefaultSlingProxyServiceImpl();
+ SlingPropertyProxy pageProxy4 = slingProxyService2.getProxy(
+ pageResource, SlingPropertyProxy.class);
+ assertTrue(pageProxy.equals(pageProxy4));
+
+ log.info("Ensuring the same proxy interfaces from the differet resources are not equal");
+ Resource pageContentResource = resolver.getResource("/content/test/jcr:content");
+ SlingPropertyProxy pageProxy5 = pageContentResource
+ .adaptTo(SlingPropertyProxy.class);
+ assertFalse(pageProxy.equals(pageProxy5));
+
+ log.info("Tests Successful");
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPHashCode.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPHashCode.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPHashCode.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPHashCode.java Wed Nov 6 14:29:48 2013
@@ -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.extensions.dynamicproxy.lang;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.extensions.dynamicproxy.BaseSlingProxyTest;
+import org.apache.sling.extensions.dynamicproxy.SlingProxyService;
+import org.apache.sling.extensions.dynamicproxy.impl.DefaultSlingProxyServiceImpl;
+import org.apache.sling.extensions.dynamicproxy.samples.DuplicateSlingPropertyProxy;
+import org.apache.sling.extensions.dynamicproxy.samples.SlingPropertyProxy;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for the Sling Proxy hashCode implementation.
+ */
+public class TestJDPHashCode extends BaseSlingProxyTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(TestJDPHashCode.class);
+
+ /**
+ * All of the tests for the hashCode implementation.
+ */
+ @Test
+ public void runTests() {
+
+ log.info("runTests");
+
+ Resource pageResource = resolver.getResource("/content/test");
+ SlingPropertyProxy pageProxy = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+
+ log.info("Testing Equals functionality");
+ int hashCode = pageProxy.hashCode();
+ assertNotNull(hashCode);
+ log.info("HashCode: " + hashCode);
+
+ log.info("Ensuring the same proxy interface from the same resource get the same hash code");
+ SlingPropertyProxy pageProxy2 = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+ log.info("HashCode1 {}, HashCode 2 {}", hashCode, pageProxy2.hashCode());
+ assertEquals(pageProxy2.hashCode(), hashCode);
+
+ log.info("Ensuring different proxy interfaces from the same resource get different hash codes");
+ DuplicateSlingPropertyProxy pageProxy3 = pageResource
+ .adaptTo(DuplicateSlingPropertyProxy.class);
+ log.info("HashCode1 {}, HashCode 2 {}", hashCode, pageProxy3.hashCode());
+ assertFalse(pageProxy3.hashCode() == hashCode);
+
+ log.info("Ensuring retrieving the same proxy from different proxy services results in the same hashCode");
+ SlingProxyService slingProxyService2 = new DefaultSlingProxyServiceImpl();
+ SlingPropertyProxy pageProxy4 = slingProxyService2.getProxy(
+ pageResource, SlingPropertyProxy.class);
+ log.info("HashCode1 {}, HashCode 2 {}", hashCode, pageProxy4.hashCode());
+ assertEquals(hashCode, pageProxy4.hashCode());
+
+ log.info("Tests Successful");
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPToString.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPToString.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPToString.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/lang/TestJDPToString.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.extensions.dynamicproxy.lang;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.extensions.dynamicproxy.BaseSlingProxyTest;
+import org.apache.sling.extensions.dynamicproxy.samples.SlingPropertyProxy;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for the SlingProxy toString method.
+ */
+public class TestJDPToString extends BaseSlingProxyTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(TestJDPToString.class);
+
+ /**
+ * Test the SlingProxy toString method.
+ */
+ @Test
+ public void runTests() {
+
+ log.info("runTests");
+
+ Resource pageResource = resolver.getResource("/content/test");
+ SlingPropertyProxy pageProxy = pageResource
+ .adaptTo(SlingPropertyProxy.class);
+
+ log.info("Testing toString functionality");
+ String stringed = pageProxy.toString();
+ assertNotNull(stringed);
+ log.info(stringed);
+
+ log.info("Tests Successful");
+ }
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/DuplicateSlingPropertyProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/DuplicateSlingPropertyProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/DuplicateSlingPropertyProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/DuplicateSlingPropertyProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.extensions.dynamicproxy.samples;
+
+import org.apache.sling.extensions.dynamicproxy.SlingProxy;
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingProperty;
+
+/**
+ * Duplicate of the SlingPropertyProxy class. This is used to see if really
+ * similar proxies are treated as different.
+ */
+public interface DuplicateSlingPropertyProxy extends SlingProxy {
+
+ @SlingProperty(path = "jcr:content")
+ public String getNonExistentProperty();
+
+ @SlingProperty(name = "sling:resourceType")
+ public String getSlingResourceType();
+
+ @SlingProperty(name = "jcr:title", path = "jcr:content")
+ public String getTitle();
+
+ @SlingProperty(path = "jcr:content", name = "active")
+ public Boolean isActive();
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/NoAnnotationSlingProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/NoAnnotationSlingProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/NoAnnotationSlingProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/NoAnnotationSlingProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.extensions.dynamicproxy.samples;
+
+import org.apache.sling.extensions.dynamicproxy.SlingProxy;
+
+/**
+ * A simple proxy interface for testing the SlingProxy API. This proxy interface
+ * only utilizes the default property retrieval mechanism.
+ */
+public interface NoAnnotationSlingProxy extends SlingProxy {
+
+ /**
+ * Gets the jcr:title attribute
+ *
+ * @return
+ */
+ public String getJcrTitle();
+
+ /**
+ * Gets the sling:resourceType attribute.
+ *
+ * @return
+ */
+ public String getSlingResourceType();
+
+ /**
+ * Another form of retrieving the jcr:title.
+ *
+ * @return
+ */
+ public String jcrTitle();
+
+ /**
+ * Gets the active attribute.
+ *
+ * @return
+ */
+ public Boolean isActive();
+
+ /**
+ * Gets the active attribute as a string.
+ *
+ * @return
+ */
+ public String active();
+
+ /**
+ * Attempts to retrieve a property which does not exist.
+ *
+ * @return
+ */
+ public String getNonExistentProperty();
+
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingDefaultsProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingDefaultsProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingDefaultsProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingDefaultsProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.extensions.dynamicproxy.samples;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingProperty;
+
+/**
+ * A proxy for testing the defaults functionality
+ */
+public interface SlingDefaultsProxy extends SlingPropertyProxy {
+
+ @SlingProperty(name = "boolean", useDefault=true, defaultBoolean=false)
+ public boolean getBoolean();
+
+ @SlingProperty(name="bytes", useDefault=true)
+ public byte[] getBytes();
+
+ @SlingProperty(name="input", useDefault=true)
+ public InputStream getInputStream();
+
+ @SlingProperty(name="date", useDefault=true, defaultDate=0)
+ public Date getDate();
+
+ @SlingProperty(name="calendar", useDefault=true, defaultDate=0)
+ public Calendar getCalendarDate();
+
+ @SlingProperty(name="double", useDefault=true, defaultDouble=1.0)
+ public double getDouble();
+
+ @SlingProperty(name = "int", useDefault=true, defaultInt=10)
+ public int getInt();
+
+ @SlingProperty(name = "long", useDefault=true, defaultLong=10)
+ public long getLong();
+
+ @SlingProperty(name = "string", useDefault=true, defaultString="bob")
+ public String getString();
+
+ @SlingProperty(name = "strings", useDefault=true, defaultStrings={"bob","jones"})
+ public String[] getStrings();
+
+
+ @SlingProperty(name = "jcr:title", path = "jcr:content", useDefault=true, defaultString="Default Title")
+ public String getBackupTitle();
+}
Added: sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingPropertyProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingPropertyProxy.java?rev=1539345&view=auto
==============================================================================
--- sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingPropertyProxy.java (added)
+++ sling/whiteboard/dklco/dynamic-proxy/src/test/java/org/apache/sling/extensions/dynamicproxy/samples/SlingPropertyProxy.java Wed Nov 6 14:29:48 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.extensions.dynamicproxy.samples;
+
+import org.apache.sling.extensions.dynamicproxy.SlingProxy;
+import org.apache.sling.extensions.dynamicproxy.annotations.SlingProperty;
+
+/**
+ * A simple proxy with only properties.
+ */
+public interface SlingPropertyProxy extends SlingProxy {
+
+ @SlingProperty(name = "jcr:title", path = "jcr:content")
+ public String getTitle();
+
+ @SlingProperty(name = "sling:resourceType")
+ public String getSlingResourceType();
+
+ @SlingProperty(path = "jcr:content", name = "active")
+ public Boolean isActive();
+
+ @SlingProperty(path = "jcr:content")
+ public String getNonExistentProperty();
+}