static <T> T set(Class<T> interf, Object value) { Properties p = new Properties(); Method ms[] = interf.getMethods(); for (Method m : ms) { p.put(m.getName(), value); } return Configurable.createConfigurable(interf, (Map<Object, Object>) p); }
/* if (type.equals(String.class)) { return XPathConstants.STRING; } if (type.equals(Double.class) || type.equals(double.class)) { return XPathConstants.NUMBER; } if (type.equals(Integer.class) || type.equals(int.class)) { return XPathConstants.NUMBER; } if (type.equals(Long.class) || type.equals(long.class)) { return XPathConstants.NUMBER; } if (type.equals(Boolean.class) || type.equals(boolean.class)) { return XPathConstants.BOOLEAN; } if (type.equals(NodeList.class)) { if (expressionType.getReturnType() == ScriptExpressionReturnTypeType.SCALAR) { // FIXME: is this OK? return XPathConstants.STRING; } else { return XPathConstants.NODESET; } } if (type.equals(Node.class)) { return XPathConstants.NODE; } if (type.equals(PolyString.class) || type.equals(PolyStringType.class)) { return XPathConstants.STRING; } throw new ExpressionEvaluationException("Unsupported return type " + type); } */ private <T, V extends PrismValue> V convertScalar( Class<T> type, QName returnType, Object value, String contextDescription) throws ExpressionEvaluationException { if (value instanceof ObjectReferenceType) { return (V) ((ObjectReferenceType) value).asReferenceValue(); } if (type.isAssignableFrom(value.getClass())) { return (V) new PrismPropertyValue<T>((T) value); } try { T resultValue = null; if (value instanceof String) { resultValue = XmlTypeConverter.toJavaValue((String) value, type); } else if (value instanceof Boolean) { resultValue = (T) value; } else if (value instanceof Element) { resultValue = XmlTypeConverter.convertValueElementAsScalar((Element) value, type); } else { throw new ExpressionEvaluationException( "Unexpected scalar return type " + value.getClass().getName()); } if (returnType.equals(PrismConstants.POLYSTRING_TYPE_QNAME) && resultValue instanceof String) { resultValue = (T) new PolyString((String) resultValue); } PrismUtil.recomputeRealValue(resultValue, prismContext); return (V) new PrismPropertyValue<T>(resultValue); } catch (SchemaException e) { throw new ExpressionEvaluationException( "Error converting result of " + contextDescription + ": " + e.getMessage(), e); } catch (IllegalArgumentException e) { throw new ExpressionEvaluationException( "Error converting result of " + contextDescription + ": " + e.getMessage(), e); } }