use of com.servoy.j2db.server.ngclient.component.RhinoMapOrArrayWrapper in project servoy-client by Servoy.
the class NGCustomJSONArrayType method toSabloComponentValue.
@Override
public Object toSabloComponentValue(final Object rhinoValue, Object previousComponentValue, PropertyDescription pd, final IWebObjectContext componentOrService) {
if (rhinoValue == null || RhinoConversion.isUndefinedOrNotFound(rhinoValue))
return null;
final ChangeAwareList<SabloT, SabloWT> previousSpecialArray = (ChangeAwareList<SabloT, SabloWT>) previousComponentValue;
if (rhinoValue instanceof RhinoMapOrArrayWrapper) {
return ((RhinoMapOrArrayWrapper) rhinoValue).getWrappedValue();
} else {
// if it's some kind of array
// we always make a new copy to simplify code; so previous Rhino reference in js code should no longer be used after this conversion
List<SabloT> rhinoArrayCopy = null;
PropertyDescription elementPD = getCustomJSONTypeDefinition();
if (rhinoValue instanceof NativeArray) {
rhinoArrayCopy = new ArrayList<SabloT>();
NativeArray nativeArray = (NativeArray) rhinoValue;
for (Object element : nativeArray) {
rhinoArrayCopy.add((SabloT) NGConversions.INSTANCE.convertRhinoToSabloComponentValue(element, null, elementPD, componentOrService));
}
} else if (rhinoValue instanceof NativeJavaArray) {
rhinoArrayCopy = new ArrayList<SabloT>();
NativeJavaArray nativeJavaArray = (NativeJavaArray) rhinoValue;
int length = ((Integer) nativeJavaArray.get("length", nativeJavaArray)).intValue();
for (int i = 0; i < length; i++) {
rhinoArrayCopy.add((SabloT) NGConversions.INSTANCE.convertRhinoToSabloComponentValue(nativeJavaArray.get(i, nativeJavaArray), null, elementPD, componentOrService));
}
} else
Debug.warn(// $NON-NLS-1$
"Cannot convert value assigned from solution scripting into array property type; class: " + rhinoValue.getClass() + ", new value = " + rhinoValue + // $NON-NLS-1$ //$NON-NLS-2$
"; property = " + pd.getName() + "; component name = " + // $NON-NLS-1$
componentOrService.getUnderlyingWebObject().getName());
if (rhinoArrayCopy != null) {
return wrap(rhinoArrayCopy, previousSpecialArray, pd, new WrappingContext(componentOrService.getUnderlyingWebObject(), pd.getName()));
}
}
// or should we return null or throw exception here? incompatible thing was assigned
return previousComponentValue;
}
use of com.servoy.j2db.server.ngclient.component.RhinoMapOrArrayWrapper in project servoy-client by Servoy.
the class NGCustomJSONObjectType method toRhinoValue.
@Override
public Object toRhinoValue(Map<String, SabloT> webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
if (webComponentValue != null) {
CustomObjectContext<SabloT, SabloWT> ext = ((ChangeAwareMap<SabloT, SabloWT>) webComponentValue).getOrCreateComponentOrServiceExtension();
RhinoMapOrArrayWrapper rhinoValue = new RhinoMapOrArrayWrapper(webComponentValue, ext, pd, startScriptable);
return rhinoValue;
}
return null;
}
Aggregations