예제 #1
0
 private String dumpEntry(int indent, Serializable value) {
   if (value instanceof Element) {
     Element element = (Element) value;
     if (SchemaConstants.C_VALUE.equals(DOMUtil.getQName(element))) {
       try {
         String cvalue = null;
         if (value == null) {
           cvalue = "null";
         } else if (value instanceof Element) {
           cvalue = SchemaDebugUtil.prettyPrint(XmlTypeConverter.toJavaValue((Element) value));
         } else {
           cvalue = SchemaDebugUtil.prettyPrint(value);
         }
         return DebugUtil.fixIndentInMultiline(indent, INDENT_STRING, cvalue);
       } catch (Exception e) {
         return DebugUtil.fixIndentInMultiline(
             indent, INDENT_STRING, "value: " + element.getTextContent());
       }
     }
   }
   return DebugUtil.fixIndentInMultiline(
       indent, INDENT_STRING, SchemaDebugUtil.prettyPrint(value));
 }
예제 #2
0
  /*
  	 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);
    }
  }