You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/11 12:39:13 UTC

svn commit: r1091015 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Reflect.java test/org/apache/commons/runtime/TestReflect.java

Author: mturk
Date: Mon Apr 11 10:39:13 2011
New Revision: 1091015

URL: http://svn.apache.org/viewvc?rev=1091015&view=rev
Log:
Add Reflect java API skeleton

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java   (with props)
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java   (with props)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java?rev=1091015&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java Mon Apr 11 10:39:13 2011
@@ -0,0 +1,72 @@
+/* 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.commons.runtime;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * JVM reflection support.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Reflect
+{
+
+    private Reflect()
+    {
+        // No instance.
+    }
+
+    private static native Class  get0(String name)
+        throws NoClassDefFoundError, OutOfMemoryError;
+    private static native Class  get1(String name, boolean weakReference)
+        throws NoClassDefFoundError, OutOfMemoryError;
+    private static native long   get2(Class clazz, String name, String signature, boolean isStatic)
+        throws NoSuchMethodError, OutOfMemoryError;
+    private static native long   get3(Class clazz, String name, String signature, boolean isStatic)
+        throws NoSuchFieldError, OutOfMemoryError;
+    private static native Method get4(long methodID)
+        throws OutOfMemoryError;
+    private static native Field  get5(long fieldID)
+        throws OutOfMemoryError;
+    private static native Object new0(Class clazz)
+        throws InstantiationException, OutOfMemoryError;
+    private static native void   clr0(Object inst);
+    private static native void   clr1(Object inst);
+
+    /**
+     * Allocates a new java.lang.Object without invoking any
+     * of the constructors for the object.
+     */
+    public static Object allocObject(Class clazz)
+        throws IllegalArgumentException, InstantiationException, OutOfMemoryError
+    {
+        if (clazz == null)
+            throw new IllegalArgumentException();
+        return new0(clazz); 
+    }
+
+    public static Class findClass(String name)
+        throws IllegalArgumentException, NoClassDefFoundError, OutOfMemoryError
+    {
+        if (name == null)
+            throw new IllegalArgumentException();
+        return get0(name); 
+    }
+    
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Reflect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java?rev=1091015&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java Mon Apr 11 10:39:13 2011
@@ -0,0 +1,35 @@
+/* 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.commons.runtime;
+
+import java.lang.reflect.*;
+import org.testng.annotations.*;
+import org.testng.Assert;
+
+public class TestReflect
+{
+
+    @Test(groups = { "utils" })
+    public void testFindClass()
+    {
+        Class c1 = Reflect.findClass("java/lang/System");
+        Assert.assertEquals("java.lang.System", c1.getCanonicalName());
+        Class c2 = Reflect.findClass("java.lang.System");
+        Assert.assertEquals("java.lang.System", c1.getCanonicalName());
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestReflect.java
------------------------------------------------------------------------------
    svn:eol-style = native