- if (String.class.isAssignableFrom(clss)) {
- return (T) get(node, property);
- } else if (Long.class.isAssignableFrom(clss)) {
- return (T) get(node, property);
- } else {
- throw new IllegalArgumentException("Unsupported format " + clss);
+ try {
+ Property p = node.getProperty(property);
+ try {
+ if (p.isMultiple()) {
+ throw new UnsupportedOperationException("Multiple values properties are not supported");
+ }
+ Value value = p.getValue();
+ return (T) get(value);
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException(
+ "Cannot cast property of type " + PropertyType.nameFromValue(p.getType()), e);
+ }
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot retrieve property " + property + " from " + node, e);
+ }
+// if (String.class.isAssignableFrom(clss)) {
+// return (T) get(node, property);
+// } else if (Long.class.isAssignableFrom(clss)) {
+// return (T) get(node, property);
+// } else if (Boolean.class.isAssignableFrom(clss)) {
+// return (T) get(node, property);
+// } else {
+// throw new IllegalArgumentException("Unsupported format " + clss);
+// }
+ }
+
+ /**
+ * Retrieve a {@link PropertyType#DATE} property as an {@link Instant}.
+ *
+ * @return the property value, or <code>null</code> if not found.
+ */
+ public static Instant getAsInstant(Node node, String property) {
+ try {
+ if (!node.hasProperty(property))
+ return null;
+ Calendar calendar = node.getProperty(property).getDate();
+ return calendar.getTime().toInstant();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot get property " + property + " of " + node + " as an instant.", e);