This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit b21d28a7015692cda8ab58f02d13eec75fdcc434
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Fri May 18 21:00:12 2018 +0200

    ISIS-1948: Internal API: introduces _Proxies (stubs only)
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1948
---
 .../internal/proxy/ProxyFactory_Default.java       | 110 +++++++++++++++++++++
 .../isis/applib/internal/proxy/_Proxies.java       |  47 +++++++++
 .../isis/applib/internal/proxy/package-info.java   |  28 ++++++
 3 files changed, 185 insertions(+)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/ProxyFactory_Default.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/ProxyFactory_Default.java
new file mode 100644
index 0000000..37709c7
--- /dev/null
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/ProxyFactory_Default.java
@@ -0,0 +1,110 @@
+/*
+ *  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.isis.applib.internal.proxy;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+
+import org.apache.isis.applib.internal.exceptions._Exceptions;
+import org.apache.isis.applib.internal.proxy._Proxies.ProxyFactory;
+
+/**
+ * 
+ * package private mixin for utility class {@link _Proxies}
+ * 
+ * ProxyFactory default implementation.
+ *
+ */
+class ProxyFactory_Default<T> implements ProxyFactory<T> {
+
+       private final Class<?> extending;
+       private final Class<?>[] implementing;
+       
+       ProxyFactory_Default(Class<?> extending, Class<?>[] implementing) {
+               this.extending = extending;
+               this.implementing = implementing;
+               
+           // TODO ignore      return !m.getName().equals("finalize") || 
m.isBridge();
+               
+        // this is the default, I believe
+        // calling it here only because I know that it will throw an exception 
if the code were
+        // in the future changed such that caching is invalid
+        // (ie fail fast if future change could introduce a bug)
+        //TODO proxyFactory.setUseCache(true);
+               
+       }
+
+       @Override
+       public T createInstance(InvocationHandler handler) {
+               
+//      final Class<T> enhancedClass = proxyFactory.createClass();
+//      final Proxy proxy = (Proxy) Util.createInstance(enhancedClass);
+//
+//      proxy.setHandler(new MethodHandler() {
+//          @Override
+//          public Object invoke(Object self, Method thisMethod, Method 
proceed, Object[] args) throws Throwable {
+//              return handler.invoke(self, thisMethod, args);
+//          }
+//      });
+//
+//      return (T) proxy;
+               
+               //TODO 
+//     } catch (final InstantiationException |
+//            IllegalAccessException |
+//            InvocationTargetException e) {
+// throw new IsisException(e);
+//}
+               
+               // TODO Auto-generated method stub
+               _Exceptions.throwNotImplemented();
+               return null;
+       }
+
+       
+//      final Class<T> proxySubclass = proxyFactory.createClass();
+//     
+//     final T newInstance;
+//     if(mixedInIfAny == null) {
+//         newInstance = proxySubclass.newInstance();
+//     } else {
+//         Constructor<?> constructor = findConstructor(proxySubclass, 
mixedInIfAny);
+//         newInstance = (T) constructor.newInstance(mixedInIfAny);
+//     }
+//     final ProxyObject proxyObject = (ProxyObject) newInstance;
+//     proxyObject.setHandler(methodHandler);
+//
+//     return newInstance;
+       
+    private <T> Constructor<?> findConstructor(final Class<T> proxySubclass, 
final Object mixedInIfAny) {
+        final Constructor<?>[] constructors = proxySubclass.getConstructors();
+        for (Constructor<?> constructor : constructors) {
+            final Class<?>[] parameterTypes = constructor.getParameterTypes();
+            if(parameterTypes.length == 1 && 
parameterTypes[0].isAssignableFrom(mixedInIfAny.getClass())) {
+                return constructor;
+            }
+        }
+        throw new IllegalArgumentException( String.format(
+                "Could not locate 1-arg constructor for mixin type of '%s' 
accepting an instance of '%s'",
+                        proxySubclass, mixedInIfAny.getClass().getName()));
+    }
+       
+       
+}
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/_Proxies.java 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/_Proxies.java
new file mode 100644
index 0000000..d2dd1df
--- /dev/null
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/_Proxies.java
@@ -0,0 +1,47 @@
+/*
+ *  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.isis.applib.internal.proxy;
+
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * Provides framework internal proxy support.
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this 
package! <br/> 
+ * These may be changed or removed without notice!
+ * </p>
+ * 
+ * @since 2.0.0
+ */
+public class _Proxies {
+       
+       public static interface ProxyFactory<T> {
+               
+               public T createInstance(InvocationHandler handler);
+       }
+
+       public static <T> ProxyFactory<T> factory(Class<T> extending, Class<?> 
... implementing) {
+               return new ProxyFactory_Default<T>(extending, implementing);
+       }
+       
+}
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/package-info.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/package-info.java
new file mode 100644
index 0000000..cf818dc
--- /dev/null
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/proxy/package-info.java
@@ -0,0 +1,28 @@
+/*
+ *  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.
+ */
+/**
+ * <h1>Internal API</h1>
+ * Internal classes, contributing to the internal proprietary API. 
+ * These may be changed or removed without notice!
+ * <p>
+ * <b>WARNING</b>: 
+ * Do NOT use any of the classes provided by this package!
+ * </p>
+ */
+package org.apache.isis.applib.internal.proxy;
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to