use of com.servoy.j2db.scripting.annotations.JSReadonlyProperty in project servoy-client by Servoy.
the class InstanceJavaMembers method makeBeanProperties.
/**
* @see org.mozilla.javascript.JavaMembers#makeBeanProperties(Scriptable, boolean)
*/
@SuppressWarnings("nls")
@Override
protected void makeBeanProperties(boolean isStatic, boolean includePrivate) {
Map<String, Object> ht = isStatic ? staticMembers : members;
Map<String, Object> copy = new HashMap<String, Object>(ht);
for (Entry<String, Object> entry : ht.entrySet()) {
String name = entry.getKey();
String newName = null;
if (// $NON-NLS-1$
name.startsWith("js_")) {
newName = name.substring(3);
} else {
Object member = entry.getValue();
if (member instanceof NativeJavaMethod) {
if (((NativeJavaMethod) member).getMethods().length == 1) {
MemberBox mb = ((NativeJavaMethod) member).getMethods()[0];
if (mb.isMethod()) {
if (AnnotationManagerReflection.getInstance().isAnnotationPresent(mb.method(), cl, JSReadonlyProperty.class)) {
newName = AnnotationManagerReflection.getInstance().getAnnotation(mb.method(), cl, JSReadonlyProperty.class).property();
if (newName == null || newName.length() == 0 && (entry.getKey().startsWith("get") || entry.getKey().startsWith("is"))) {
newName = entry.getKey().substring(entry.getKey().startsWith("get") ? 3 : 2);
// Make the bean property name.
char ch0 = newName.charAt(0);
if (Character.isUpperCase(ch0)) {
if (newName.length() == 1) {
newName = newName.toLowerCase();
} else {
char ch1 = newName.charAt(1);
if (!Character.isUpperCase(ch1)) {
newName = Character.toLowerCase(ch0) + newName.substring(1);
}
}
}
}
} else if (AnnotationManagerReflection.getInstance().isAnnotationPresent(mb.method(), cl, JSGetter.class)) {
newName = AnnotationManagerReflection.getInstance().getAnnotation(mb.method(), cl, JSGetter.class).value();
} else if (AnnotationManagerReflection.getInstance().isAnnotationPresent(mb.method(), cl, JSSetter.class)) {
newName = AnnotationManagerReflection.getInstance().getAnnotation(mb.method(), cl, JSSetter.class).value();
}
}
}
for (MemberBox mb : ((NativeJavaMethod) member).getMethods()) {
if (mb.isMethod() && AnnotationManagerReflection.getInstance().isAnnotationPresent(mb.method(), cl, JSFunction.class)) {
String funcName = AnnotationManagerReflection.getInstance().getAnnotation(mb.method(), cl, JSFunction.class).value();
if (funcName == null || funcName.length() == 0) {
funcName = entry.getKey();
}
// $NON-NLS-1$
newName = "jsFunction_".concat(funcName);
break;
}
}
}
}
if (newName != null && newName.length() > 0 && !newName.equals(name) && !Ident.checkIfJavascriptKeyword(newName)) {
putNewValueMergeForDuplicates(copy, name, newName);
}
}
ht = copy;
if (isStatic) {
staticMembers = ht;
} else {
members = ht;
}
super.makeBeanProperties(isStatic, includePrivate);
copy = new HashMap<String, Object>(ht);
for (Entry<String, Object> entry : ht.entrySet()) {
String name = entry.getKey();
if (// $NON-NLS-1$
name.startsWith("jsFunction_")) {
String newName = name.substring(11);
if (!Ident.checkIfJavascriptKeyword(newName)) {
putNewValueMergeForDuplicates(copy, name, newName);
}
} else {
Object member = entry.getValue();
if (member instanceof NativeJavaMethod && ((NativeJavaMethod) member).getMethods().length == 1) {
MemberBox mb = ((NativeJavaMethod) member).getMethods()[0];
if (mb.isMethod()) {
// make bean property
JSReadonlyProperty jsReadonlyProperty = AnnotationManagerReflection.getInstance().getAnnotation(mb.method(), mb.getDeclaringClass(), JSReadonlyProperty.class);
if (jsReadonlyProperty != null) {
String propertyName = jsReadonlyProperty.property();
if (propertyName == null || propertyName.length() == 0) {
propertyName = name;
}
Object oldValue = copy.put(propertyName, new BeanProperty(mb, null, null));
if (oldValue instanceof NativeJavaMethod) {
// allow the method to be called directly as well
String functionName = ((NativeJavaMethod) oldValue).getFunctionName();
if (!functionName.equals(propertyName)) {
copy.put(functionName, oldValue);
// but do not show it
addMethodToDelete(functionName);
}
}
}
}
}
}
}
if (isStatic) {
staticMembers = copy;
} else {
members = copy;
}
}
use of com.servoy.j2db.scripting.annotations.JSReadonlyProperty in project servoy-client by Servoy.
the class DefaultJavaScope method getJsFunctions.
public static Map<String, NativeJavaMethod> getJsFunctions(Class<?> clazz) {
Map<String, NativeJavaMethod> jsFunctions = new HashMap<String, NativeJavaMethod>();
try {
for (Method method : clazz.getMethods()) {
String name = null;
if (// $NON-NLS-1$
method.getName().startsWith("js_")) {
name = method.getName().substring(3);
} else if (// $NON-NLS-1$
method.getName().startsWith("jsFunction_")) {
name = method.getName().substring(11);
} else {
AnnotationManagerReflection annotationManager = AnnotationManagerReflection.getInstance();
JSReadonlyProperty jsReadonlyProperty = annotationManager.getAnnotation(method, clazz, JSReadonlyProperty.class);
if (jsReadonlyProperty != null) {
name = jsReadonlyProperty.property();
if (name == null || name.length() == 0) {
name = method.getName();
}
} else if (annotationManager.isAnnotationPresent(method, clazz, JSFunction.class)) {
name = method.getName();
}
}
if (name != null) {
NativeJavaMethod nativeJavaMethod = jsFunctions.get(name);
if (nativeJavaMethod == null) {
nativeJavaMethod = new NativeJavaMethod(method, name);
} else {
nativeJavaMethod = new NativeJavaMethod(Utils.arrayAdd(nativeJavaMethod.getMethods(), new MemberBox(method), true), name);
}
jsFunctions.put(name, nativeJavaMethod);
}
}
} catch (Exception e) {
Debug.error(e);
}
return jsFunctions;
}
use of com.servoy.j2db.scripting.annotations.JSReadonlyProperty in project servoy-client by Servoy.
the class FoundSet method alldataproviders.
/**
* Get all dataproviders of the foundset.
*
* @sample
* var dataprovidersNames = %%prefix%%alldataproviders;
* application.output("This foundset has " + dataprovidersNames.length + " data providers.")
* for (var i=0; i<dataprovidersNames.length; i++)
* application.output(dataprovidersNames[i]);
*
* @special
*/
@JSReadonlyProperty
public String[] alldataproviders() {
List<String> al = new ArrayList<String>();
Table table = (Table) getTable();
if (table != null) {
try {
Iterator<Column> columnsIt = table.getColumnsSortedByName();
while (columnsIt.hasNext()) {
IColumn c = columnsIt.next();
al.add(c.getDataProviderID());
}
Iterator<AggregateVariable> aggIt = fsm.getApplication().getFlattenedSolution().getAggregateVariables(table, true);
while (aggIt.hasNext()) {
AggregateVariable av = aggIt.next();
al.add(av.getDataProviderID());
}
Iterator<ScriptCalculation> scriptIt = fsm.getApplication().getFlattenedSolution().getScriptCalculations(table, true);
while (scriptIt.hasNext()) {
ScriptCalculation sc = scriptIt.next();
if (al.contains(sc.getDataProviderID()))
al.remove(sc.getDataProviderID());
al.add(sc.getDataProviderID());
}
} catch (Exception ex) {
Debug.error(ex);
}
}
return al.toArray(new String[al.size()]);
}
use of com.servoy.j2db.scripting.annotations.JSReadonlyProperty in project servoy-client by Servoy.
the class QBSelect method having.
/**
* Get the having-part of the query, used to add conditions.
* The conditions added here are AND-ed.
* @sample
* var query = datasources.db.example_data.orders.createSelect();
* query.groupBy.addPk() // have to group by on pk when using having-conditions in (foundset) pk queries
* .root.having.add(query.joins.orders_to_order_details.columns.quantity.count.eq(0))
* foundset.loadRecords(query)
*/
@JSReadonlyProperty
public QBLogicalCondition having() throws RepositoryException {
if (having == null) {
ISQLCondition c = getQuery().getHaving();
if (!(c instanceof AndOrCondition)) {
getQuery().setHaving(c = AndCondition.and(c, new AndCondition()));
}
having = new QBLogicalCondition(this, this, (AndOrCondition) c);
}
return having;
}
Aggregations