polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [1/4] polygene-java git commit: Added method in Polygene API to check if an object is a Composite.
Date Wed, 07 Jun 2017 04:34:29 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop c201ff52a -> 4f1527980


Added method in Polygene API to check if an object is a Composite.

Signed-off-by: niclas <niclas@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/195da9f5
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/195da9f5
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/195da9f5

Branch: refs/heads/develop
Commit: 195da9f536b28323950b0d3166f4c499466a157a
Parents: c201ff5
Author: niclas <niclas@hedhman.org>
Authored: Wed Jun 7 08:58:22 2017 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Wed Jun 7 08:58:22 2017 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/polygene/api/PolygeneAPI.java |  8 ++++++--
 .../apache/polygene/runtime/PolygeneRuntimeImpl.java   | 13 +++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/195da9f5/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
index a9958a6..2823cb6 100644
--- a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
+++ b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
@@ -20,7 +20,6 @@
 package org.apache.polygene.api;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.util.function.Function;
 import org.apache.polygene.api.association.AbstractAssociation;
@@ -28,7 +27,6 @@ import org.apache.polygene.api.association.AssociationDescriptor;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.CompositeDescriptor;
 import org.apache.polygene.api.composite.CompositeInstance;
-import org.apache.polygene.api.composite.InvalidCompositeException;
 import org.apache.polygene.api.composite.ModelDescriptor;
 import org.apache.polygene.api.composite.TransientDescriptor;
 import org.apache.polygene.api.entity.EntityDescriptor;
@@ -139,6 +137,12 @@ public interface PolygeneAPI
      */
     AssociationDescriptor associationDescriptorFor( AbstractAssociation association );
 
+    /** Tests if the given object is a Composite
+     *
+     * @param object The Java object to be checked
+     * @return true if the given object is a Composite type.
+     */
+    boolean isComposite( Object object );
     /**
      * Function that returns the CompositeInstance of a Composite.
      */

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/195da9f5/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
index 405ade0..9e3bf2d 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
@@ -20,6 +20,7 @@
 package org.apache.polygene.runtime;
 
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.stream.Stream;
@@ -312,6 +313,18 @@ public final class PolygeneRuntimeImpl
         return (AssociationDescriptor) ( (AbstractAssociationInstance) association ).associationInfo();
     }
 
+    @Override
+    public boolean isComposite( Object object )
+    {
+        return isCompositeType( object );
+    }
+
+    public static boolean isCompositeType( Object object )
+    {
+        return Proxy.isProxyClass( object.getClass() )
+               && Proxy.getInvocationHandler( object ) instanceof CompositeInstance;
+    }
+
     // SPI
     @Override
     public EntityState entityStateOf( EntityComposite composite )


Mime
View raw message