You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/02/01 08:40:13 UTC

svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java

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



Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java

Posted by Simone Tripodi <si...@apache.org>.
don't worry, that is why ASF projects are communities project, and no
"one man band" instead ;)
4 eyes are better than 2, immagine what if someone else joins us! :)

alles gute!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Wed, Feb 1, 2012 at 9:51 AM,  <be...@systemoutprintln.de> wrote:
> You got me again. Sorry about that. I thought, this time I could make a good suggestion. Damn it ;-) I'm still having trouble reading the svn commit mails. Next time, I'll better check the commit from my IDE.
>
> ----- Original Message -----
> From: simonetripodi@apache.org
> To: dev@commons.apache.org
> Date: 01.02.2012 09:26:58
> Subject: Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java
>
>
>> Guten morgen,
>>
>>> I don't think that "onClassName" is a good name for that method, because fluent invocations will look like:
>>> onClassName("java.lang.Object").invokeStaticMethod(...)...
>>> We do not invoke a method on a class name, but on a class. I think
>>> onClass(String className) is self-explanatory enough and it would be similar to invokeStaticMethod(String methodName).
>>>
>>> What do you think?
>>
>> I think you didn't checkout the code and/or didn't have a look at how
>> methods are chained in the patch :)
>>
>> onClassName( "com.acme.Something" ).loadWithClassLoader( myClassLoader
>> ).invokeStaticMethod(...)
>>
>>
>> ˆˆˆˆˆˆˆˆˆˆhave a look at alternatives
>>
>> best,
>> -Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java

Posted by be...@systemoutprintln.de.
You got me again. Sorry about that. I thought, this time I could make a good suggestion. Damn it ;-) I'm still having trouble reading the svn commit mails. Next time, I'll better check the commit from my IDE.

----- Original Message -----
From: simonetripodi@apache.org
To: dev@commons.apache.org
Date: 01.02.2012 09:26:58
Subject: Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java


> Guten morgen,
> 
>> I don't think that "onClassName" is a good name for that method, because fluent invocations will look like:
>> onClassName("java.lang.Object").invokeStaticMethod(...)...
>> We do not invoke a method on a class name, but on a class. I think
>> onClass(String className) is self-explanatory enough and it would be similar to invokeStaticMethod(String methodName).
>> 
>> What do you think?
> 
> I think you didn't checkout the code and/or didn't have a look at how
> methods are chained in the patch :)
> 
> onClassName( "com.acme.Something" ).loadWithClassLoader( myClassLoader
> ).invokeStaticMethod(...)
> 
> 
> ˆˆˆˆˆˆˆˆˆˆhave a look at alternatives
> 
> best,
> -Simo
> 
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java

Posted by Simone Tripodi <si...@apache.org>.
Guten morgen,

> I don't think that "onClassName" is a good name for that method, because fluent invocations will look like:
> onClassName("java.lang.Object").invokeStaticMethod(...)...
> We do not invoke a method on a class name, but on a class. I think
> onClass(String className) is self-explanatory enough and it would be similar to invokeStaticMethod(String methodName).
>
> What do you think?

I think you didn't checkout the code and/or didn't have a look at how
methods are chained in the patch :)

onClassName( "com.acme.Something" ).loadWithClassLoader( myClassLoader
).invokeStaticMethod(...)


ˆˆˆˆˆˆˆˆˆˆhave a look at alternatives

best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java

Posted by be...@systemoutprintln.de.
----- Original Message -----
From: simonetripodi@apache.org
To: commits@commons.apache.org
Date: 01.02.2012 08:40:13
Subject: svn commit: r1238968 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: BeanUtils.java ClassLoaderBuilder.java DefaultClassLoaderBuilder.java


> 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 )

I don't think that "onClassName" is a good name for that method, because fluent invocations will look like: 
onClassName("java.lang.Object").invokeStaticMethod(...)...
We do not invoke a method on a class name, but on a class. I think 
onClass(String className) is self-explanatory enough and it would be similar to invokeStaticMethod(String methodName).

What do you think?
Regards,
Benedikt  

> +    {
> +        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
> 






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org