use of com.tinkerpop.frames.Property in project org.openntf.domino by OpenNTF.
the class AbstractPropertyHandler method processElementProperty.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object processElementProperty(final Object frame, final Method method, final Object[] arguments, final Annotation annotation, final FramedGraph framedGraph, final Element element) {
boolean isDerived = false;
// $NON-NLS-1$
String value = "";
@SuppressWarnings("unused") Class<?> converter = null;
String defaultValue = null;
String computation = null;
if (annotation instanceof Property) {
value = ((Property) annotation).value();
} else if (annotation instanceof TypedProperty) {
value = ((TypedProperty) annotation).value();
isDerived = ((TypedProperty) annotation).derived();
// converter = ((TypedProperty) annotation).converter();
defaultValue = ((TypedProperty) annotation).defaultValue();
// if (defaultValue != null) {
// System.out.println("TEMP DEBUG defaultValue found of " + defaultValue + " on method " + method.getName());
// }
} else if (annotation instanceof ComputedProperty) {
// System.out.println("TEMP DEBUG handling a computed property");
value = ((ComputedProperty) annotation).value();
computation = ((ComputedProperty) annotation).computation();
// isDerived = true;
}
if (ClassUtilities.isSetMethod(method) && isDerived) {
// $NON-NLS-1$
throw new DerivedPropertySetException(MessageFormat.format("Setting on a derived property {0} is not permitted.", value));
}
Class<?> type = method.getReturnType();
if (ClassUtilities.isSetMethod(method)) {
Class<?>[] paramTypes = method.getParameterTypes();
int i = 0;
for (Class paramType : paramTypes) {
if (lotus.domino.Base.class.isAssignableFrom(paramType)) {
arguments[i] = org.openntf.domino.utils.TypeUtils.convertToTarget(arguments[i], paramType, org.openntf.domino.utils.Factory.getSession(SessionType.NATIVE));
} else {
arguments[i] = org.openntf.domino.utils.TypeUtils.convertToTarget(arguments[i], paramType, null);
}
i++;
}
}
Object raw = orig_processElement(value, method, arguments, framedGraph, element, null);
if (null == raw || (raw instanceof String && ((String) raw).length() == 0)) {
if (defaultValue != null && defaultValue.length() > 0) {
Formula formula = new Formula(defaultValue);
raw = processFormula(formula, element);
// System.out.println("TEMP DEBUG defaultValue of " + String.valueOf(raw) + " calculated for " + value);
} else if (computation != null && computation.length() > 0) {
// System.out.println("TEMP DEBUG Running a computed property: " + value);
Formula formula = new Formula(computation);
raw = processFormula(formula, element);
}
}
Object result = null;
if (raw == null) {
result = null;
} else if (type.isAssignableFrom(raw.getClass())) {
result = type.cast(raw);
} else if (lotus.domino.Base.class.isAssignableFrom(type)) {
result = org.openntf.domino.utils.TypeUtils.convertToTarget(raw, type, org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT));
} else {
result = org.openntf.domino.utils.TypeUtils.convertToTarget(raw, type, null);
}
if (computation != null && computation.length() > 0) {
element.setProperty(value, result);
}
return result;
}
use of com.tinkerpop.frames.Property in project org.openntf.domino by OpenNTF.
the class JsonFrameAdapter method putJsonProperty.
@Override
public void putJsonProperty(final String paramKey, Object value) {
Object frame = getFrame();
if (frame != null) {
CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
Method crystal = getSetters().get(key);
if (crystal != null) {
try {
Class<?>[] types = crystal.getParameterTypes();
Class<?> type = types[0];
if (value == null) {
String propName = null;
TypedProperty tprop = crystal.getAnnotation(TypedProperty.class);
if (tprop != null) {
propName = tprop.value();
} else {
Property prop = crystal.getAnnotation(Property.class);
if (prop != null) {
propName = prop.value();
}
}
if (propName != null) {
if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(propName, null);
} else if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(propName, null);
}
} else {
System.err.println("ALERT the next operation will probably throw an exception");
Object[] nullarg = { type.cast(null) };
crystal.invoke(frame, nullarg);
}
} else if (!type.isAssignableFrom(value.getClass())) {
value = TypeUtils.convertToTarget(value, type, org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT));
crystal.invoke(frame, value);
} else if (JsonJavaObject.class.equals(type)) {
// FIXME NTF this is a complete hack :(
TypedProperty prop = crystal.getAnnotation(TypedProperty.class);
String itemname = prop.value();
if (frame instanceof DVertexFrame) {
Document doc = ((DVertexFrame) frame).asDocument();
TypeUtils.writeToItem(doc, itemname, value, false);
}
} else {
crystal.invoke(frame, value);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
Method man = getGetters().get(key);
if (man == null) {
// undefined property
if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(paramKey, value);
} else if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(paramKey, value);
}
} else {
// NTF if there is a getter but no setter, this is a
// read-only property. Disregard the JSON
}
}
}
}
use of com.tinkerpop.frames.Property in project org.openntf.domino by OpenNTF.
the class JsonSearchAdapter method putJsonProperty.
@Override
public void putJsonProperty(final String paramKey, Object value) {
Object frame = getFrame();
if (frame != null) {
CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
Method crystal = getSetters().get(key);
if (crystal != null) {
try {
Class<?>[] types = crystal.getParameterTypes();
Class<?> type = types[0];
if (value == null) {
String propName = null;
TypedProperty tprop = crystal.getAnnotation(TypedProperty.class);
if (tprop != null) {
propName = tprop.value();
} else {
Property prop = crystal.getAnnotation(Property.class);
if (prop != null) {
propName = prop.value();
}
}
if (propName != null) {
if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(propName, null);
} else if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(propName, null);
}
} else {
System.err.println("ALERT the next operation will probably throw an exception");
Object[] nullarg = { type.cast(null) };
crystal.invoke(frame, nullarg);
}
} else if (!type.isAssignableFrom(value.getClass())) {
value = TypeUtils.convertToTarget(value, type, org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT));
crystal.invoke(frame, value);
} else if (JsonJavaObject.class.equals(type)) {
// FIXME NTF this is a complete hack :(
TypedProperty prop = crystal.getAnnotation(TypedProperty.class);
String itemname = prop.value();
if (frame instanceof DVertexFrame) {
Document doc = ((DVertexFrame) frame).asDocument();
TypeUtils.writeToItem(doc, itemname, value, false);
}
} else {
crystal.invoke(frame, value);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
Method man = getGetters().get(key);
if (man == null) {
// undefined property
if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(paramKey, value);
} else if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(paramKey, value);
}
} else {
// NTF if there is a getter but no setter, this is a
// read-only property. Disregard the JSON
}
}
}
}
Aggregations