private <T, V extends PrismValue> List<V> convertList(
      Class<T> type, NodeList valueNodes, String contextDescription)
      throws ExpressionEvaluationException {
    List<V> values = new ArrayList<V>();
    if (valueNodes == null) {
      return values;
    }

    try {
      List<T> list = XmlTypeConverter.convertValueElementAsList(valueNodes, type);
      for (T item : list) {
        if (item instanceof ObjectReferenceType) {
          values.add((V) ((ObjectReferenceType) item).asReferenceValue());
        }
        if (isNothing(item)) {
          continue;
        }
        values.add((V) new PrismPropertyValue<T>(item));
      }
      return values;
    } catch (SchemaException e) {
      throw new ExpressionEvaluationException(
          "Error converting return value of " + contextDescription + ": " + e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      throw new ExpressionEvaluationException(
          "Error converting return value of " + contextDescription + ": " + e.getMessage(), e);
    }
  }
Example #2
0
 private String extractLastMessageFromOperationalInformation(
     EnvironmentalPerformanceInformationType environmentalPerformanceInformationType) {
   if (environmentalPerformanceInformationType.getLastMessageTimestamp() == null) {
     return null;
   }
   Date timestamp =
       XmlTypeConverter.toDate(environmentalPerformanceInformationType.getLastMessageTimestamp());
   return timestamp + ": " + environmentalPerformanceInformationType.getLastMessage();
 }
  /*
  	 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);
    }
  }
 protected void assertShadowOperationalData(
     PrismObject<ShadowType> shadow,
     SynchronizationSituationType expectedSituation,
     Long timeBeforeSync) {
   ShadowType shadowType = shadow.asObjectable();
   SynchronizationSituationType actualSituation = shadowType.getSynchronizationSituation();
   assertEquals("Wrong situation in shadow " + shadow, expectedSituation, actualSituation);
   XMLGregorianCalendar actualTimestampCal = shadowType.getSynchronizationTimestamp();
   assert actualTimestampCal != null : "No synchronization timestamp in shadow " + shadow;
   if (timeBeforeSync != null) {
     long actualTimestamp = XmlTypeConverter.toMillis(actualTimestampCal);
     assert actualTimestamp >= timeBeforeSync
         : "Synchronization timestamp was not updated in shadow " + shadow;
   }
   // TODO: assert sync description
 }
Example #5
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));
 }