Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv13563
Modified Files:
Casting.java
Log Message:
support for casting to Class
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util
Index: Casting.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/Casting.java,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -b -r1.118 -r1.119
--- Casting.java 21 Oct 2008 16:17:07 -0000 1.118
+++ Casting.java 22 Oct 2008 12:27:20 -0000 1.119
@@ -16,7 +16,7 @@
*
* @author Michiel Meeuwissen
* @since MMBase-1.6
- * @version $Id: Casting.java,v 1.118 2008/10/21 16:17:07 michiel Exp $
+ * @version $Id: Casting.java,v 1.119 2008/10/22 12:27:20 michiel Exp $
*/
import java.util.*;
@@ -208,7 +208,19 @@
} else if (type.equals(Collection.class)) {
return (C) toCollection(value);
} else if (type.equals(java.util.regex.Pattern.class)) {
+ if (java.util.regex.Pattern.class.isInstance(value)) {
+ return (C) value;
+ }
return (C) java.util.regex.Pattern.compile(toString(value));
+ } else if (type.equals(Class.class)) {
+ if (Class.class.isInstance(value)) {
+ return (C) value;
+ }
+ try {
+ return (C) Class.forName(toString(value));
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
} else {
log.error("Don't know how to convert to " + type);
if (value == null || "".equals(value)) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs