commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java
Date Wed, 01 Feb 2012 07:40:13 GMT
Author: simonetripodi
Date: Wed Feb  1 07:40:13 2012
New Revision: 1238968

URL: http://svn.apache.org/viewvc?rev=1238968&view=rev
Log:
added BeanUtils method to load classes for name

Added:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
  (with props)
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
  (with props)
Modified:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java?rev=1238968&r1=1238967&r2=1238968&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
Wed Feb  1 07:40:13 2012
@@ -42,6 +42,12 @@ public final class BeanUtils
         return new DefaultClassAccessor<B>( beanType );
     }
 
+    public static ClassLoaderBuilder onClassName( String beanTypeName )
+    {
+        beanTypeName = checkNotNull( beanTypeName, "No bean class name specified" );
+        return new DefaultClassLoaderBuilder( beanTypeName );
+    }
+
     /**
      * Hidden constructor, this class cannot be instantiated directly
      */

Added: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java?rev=1238968&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
Wed Feb  1 07:40:13 2012
@@ -0,0 +1,34 @@
+package org.apache.commons.beanutils2;
+
+/*
+ * 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.
+ */
+
+public interface ClassLoaderBuilder
+{
+
+    ClassAccessor<?> loadWithThreadContextClassLoader()
+        throws ClassNotFoundException;
+
+    ClassAccessor<?> loadWithBeanUtilsClassLoader()
+        throws ClassNotFoundException;
+
+    ClassAccessor<?> loadWithClassLoader( ClassLoader classLoader )
+        throws ClassNotFoundException;
+
+}

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

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/ClassLoaderBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java?rev=1238968&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
Wed Feb  1 07:40:13 2012
@@ -0,0 +1,70 @@
+package org.apache.commons.beanutils2;
+
+/*
+ * 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.
+ */
+
+import static java.lang.Thread.currentThread;
+
+import static org.apache.commons.beanutils2.Assertions.checkNotNull;
+
+final class DefaultClassLoaderBuilder
+    implements ClassLoaderBuilder
+{
+
+    private final String beanTypeName;
+
+    public DefaultClassLoaderBuilder( String beanTypeName )
+    {
+        this.beanTypeName = beanTypeName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ClassAccessor<?> loadWithThreadContextClassLoader()
+        throws ClassNotFoundException
+    {
+        return loadWithClassLoader( currentThread().getContextClassLoader() );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ClassAccessor<?> loadWithBeanUtilsClassLoader()
+        throws ClassNotFoundException
+    {
+        return loadWithClassLoader( getClass().getClassLoader() );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ClassAccessor<?> loadWithClassLoader( ClassLoader classLoader )
+        throws ClassNotFoundException
+    {
+        classLoader = checkNotNull( classLoader, "No ClassLoader specified" );
+
+        Class<?> beanType = classLoader.loadClass( beanTypeName );
+
+        @SuppressWarnings( { "rawtypes", "unchecked" } ) // ClassAccessor raw type is unknown
+        DefaultClassAccessor<?> accessor = new DefaultClassAccessor( beanType );
+        return accessor;
+    }
+
+}

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

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message