/** * Parse a string, assuming that it is of the type expected by a given NamedParameter. * * <p>This method does not deal with sets; if the NamedParameter is set valued, then the provided * string should correspond to a single member of the set. It is up to the caller to call parse * once for each value that should be parsed as a member of the set. * * @return a non-null reference to the parsed value. */ @Override @SuppressWarnings("unchecked") public <T> T parse(final NamedParameterNode<T> np, final String value) throws ParseException { final ClassNode<T> iface; try { iface = (ClassNode<T>) getNode(np.getFullArgName()); } catch (final NameResolutionException e) { throw new IllegalStateException( "Could not parse validated named parameter argument type. NamedParameter is " + np.getFullName() + " argument type is " + np.getFullArgName()); } Class<?> clazz; String fullName; try { clazz = classForName(iface.getFullName()); fullName = null; } catch (final ClassNotFoundException e) { clazz = null; fullName = iface.getFullName(); } try { if (clazz != null) { return (T) parameterParser.parse(clazz, value); } else { return parameterParser.parse(fullName, value); } } catch (final UnsupportedOperationException e) { try { final Node impl = getNode(value); if (impl instanceof ClassNode && isImplementation(iface, (ClassNode<?>) impl)) { return (T) impl; } throw new ParseException( "Name<" + iface.getFullName() + "> " + np.getFullName() + " cannot take non-subclass " + impl.getFullName(), e); } catch (final NameResolutionException e2) { throw new ParseException( "Name<" + iface.getFullName() + "> " + np.getFullName() + " cannot take non-class " + value, e); } } }