NoSuchReferenceException,
ComponentSearchException {
// Perform property substitution
arg = substitute(resolver, arg);
Parser parser;
Object result = null;
try {
if (arg == null || arg.equals(NULL)) {
result = null;
}
else if (cls.equals(Boolean.class)
|| cls.equals(boolean.class)) {
result = Boolean.valueOf(arg.trim());
}
else if (cls.equals(Short.class)
|| cls.equals(short.class)) {
result = Short.valueOf(arg.trim());
}
else if (cls.equals(Integer.class)
|| cls.equals(int.class)) {
result = Integer.valueOf(arg.trim());
}
else if (cls.equals(Long.class)
|| cls.equals(long.class)) {
result = Long.valueOf(arg.trim());
}
else if (cls.equals(Float.class)
|| cls.equals(float.class)) {
result = Float.valueOf(arg.trim());
}
else if (cls.equals(Double.class)
|| cls.equals(double.class)) {
result = Double.valueOf(arg.trim());
}
else if (cls.equals(ComponentReference.class)) {
ComponentReference ref =
resolver.getComponentReference(arg.trim());
if (ref == null)
throw new NoSuchReferenceException("The resolver "
+ resolver
+ " has no reference '"
+ arg + "'");
result = ref;
}
else if (Component.class.isAssignableFrom(cls)) {
ComponentReference ref =
resolver.getComponentReference(arg.trim());
if (ref == null)
throw new NoSuchReferenceException("The resolver "
+ resolver
+ " has no reference '"
+ arg + "'");
// Avoid requiring the user to wait for a component to become
// available, in most cases. In those cases where the
// component creation is particularly slow, an explicit wait
// can be added.
// Note that this is not necessarily a wait for the component
// to become visible, since menu items are not normally
// visible even if they're available.
result = waitForComponentAvailable(ref);
}
else if (cls.equals(String.class)) {
result = arg;
}
else if (cls.isArray() && arg.trim().startsWith("[")) {
arg = arg.trim();
String[] args =
parseArgumentList(arg.substring(1, arg.length()-1));
Class base = cls.getComponentType();
Object arr = Array.newInstance(base, args.length);
for (int i=0;i < args.length;i++) {
Object obj = eval(resolver, args[i], base);
Array.set(arr, i, obj);
}
result = arr;
}
else if ((parser = getParser(cls)) != null) {
result = parser.parse(arg.trim());
}
else {
String msg = Strings.get("parser.conversion_error",
new Object[] {
arg.trim(),