Author: apetrelli
Date: Sun Jul 27 07:48:43 2008
New Revision: 680116
URL: http://svn.apache.org/viewvc?rev=680116&view=rev
Log:
TILES-286
Added @since tags.
Re-added the old ClassUtil deprecated class.
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
(with props)
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java?rev=680116&r1=680115&r2=680116&view=diff
==============================================================================
---
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
(original)
+++
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
Sun Jul 27 07:48:43 2008
@@ -28,6 +28,7 @@
* Utilities to work with dynamic class loading and instantiation.
*
* @version $Rev: 637434 $ $Date: 2008-03-15 16:48:38 +0100 (sab, 15 mar 2008)
$
+ * @since 2.0.7
*/
public final class ClassUtil {
@@ -45,6 +46,7 @@
* @return The new instance of the class name.
* @throws CannotInstantiateObjectException If something goes wrong during
* instantiation.
+ * @since 2.0.7
*/
public static Object instantiate(String className) {
return instantiate(className, false);
@@ -60,6 +62,7 @@
* <code>TilesException</code>.
* @return The new instance of the class name.
* @throws CannotInstantiateObjectException If something goes wrong during
instantiation.
+ * @since 2.0.7
*/
public static Object instantiate(String className, boolean returnNull) {
ClassLoader original = Thread.currentThread().getContextClassLoader();
@@ -96,6 +99,7 @@
* @param methodName The name of the method.
* @param parameterTypes The parameter types that the method must match.
* @return The method, if it is found.
+ * @since 2.0.7
*/
public static Method getForcedAccessibleMethod(Class<?> clazz,
String methodName, Class<?>... parameterTypes) {
@@ -124,6 +128,7 @@
* @param method The method to call.
* @param args The arguments of the method.
* @return The object returned, if the method is not "void".
+ * @since 2.0.7
*/
public static Object invokeMethod(Object obj, Method method, Object...
args) {
try {
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java?rev=680116&view=auto
==============================================================================
---
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
(added)
+++
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
Sun Jul 27 07:48:43 2008
@@ -0,0 +1,91 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.util;
+
+import org.apache.tiles.reflect.CannotInstantiateObjectException;
+
+
+/**
+ * Utilities to work with dynamic class loading and instantiation.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated Use [EMAIL PROTECTED] org.apache.tiles.reflect.ClassUtil}.
+ */
+public final class ClassUtil {
+
+ /**
+ * Constructor, private to avoid instantiation.
+ */
+ private ClassUtil() {
+ }
+
+ /**
+ * Returns an instance of the given class name, by calling the default
+ * constructor.
+ *
+ * @param className The class name to load and to instantiate.
+ * @return The new instance of the class name.
+ * @throws CannotInstantiateObjectException If something goes wrong during
+ * instantiation.
+ */
+ public static Object instantiate(String className) {
+ return instantiate(className, false);
+ }
+
+ /**
+ * Returns an instance of the given class name, by calling the default
+ * constructor.
+ *
+ * @param className The class name to load and to instantiate.
+ * @param returnNull If <code>true</code>, if the class is not found it
+ * returns <code>true</code>, otherwise it throws a
+ * <code>TilesException</code>.
+ * @return The new instance of the class name.
+ * @throws CannotInstantiateObjectException If something goes wrong during
instantiation.
+ */
+ public static Object instantiate(String className, boolean returnNull) {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ if (original == null) {
+
Thread.currentThread().setContextClassLoader(ClassUtil.class.getClassLoader());
+ }
+ try {
+ Class<?> namedClass = Class.forName(className);
+ return namedClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ if (returnNull) {
+ return null;
+ }
+ throw new CannotInstantiateObjectException(
+ "Unable to resolve factory class: '" + className + "'", e);
+ } catch (IllegalAccessException e) {
+ throw new CannotInstantiateObjectException(
+ "Unable to access factory class: '" + className + "'", e);
+ } catch (InstantiationException e) {
+ throw new CannotInstantiateObjectException(
+ "Unable to instantiate factory class: '"
+ + className
+ + "'. Make sure that this class has a default
constructor",
+ e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+}
Propchange:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/ClassUtil.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL