Package jaxx.compiler.binding
Class DataSource
java.lang.Object
jaxx.compiler.binding.DataSource
public class DataSource
extends java.lang.Object
Represents a Java expression which fires a
PropertyChangeEvent when it can be
determined that its value may have changed. Events are fired on a "best effort" basis, and events
may either be fired too often (the value has not actually changed) or not often enough (the value
changed but no event was fired).-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringconstantIdConstant idprotected static org.apache.commons.logging.LoglogLoggerprotected java.util.List<JavaMethod>methods -
Constructor Summary
Constructors Constructor Description DataSource(java.lang.String id, java.lang.String constantId, java.lang.String source, JAXXCompiler compiler, java.util.List<JavaMethod> methods)Creates a new data source. -
Method Summary
Modifier and Type Method Description protected booleancompile()Compiles the data source expression and listener.java.lang.StringgetAddMemberListenerCode(DefaultObjectHandler handler, java.lang.String objectCode, java.lang.String memberName, java.lang.String propertyChangeListenerCode, JAXXCompiler compiler)Returns a snippet of Java code which will cause aPropertyChangeListenerto be notified when the member's value changes.protected ClassDescriptorgetMethodReturnType(ClassDescriptor contextClass, MethodDescriptor method)Given a method from a given context class, try to obtain his method return type.java.lang.StringgetObjectCode()java.util.Set<java.lang.String>getOverrideIds()java.lang.StringgetRemoveMemberListenerCode(DefaultObjectHandler handler, java.lang.String objectCode, java.lang.String memberName, java.lang.String propertyChangeListenerCode, JAXXCompiler compiler)DataListener[]getTrackers()booleanhasMethod(java.lang.String methodName)booleanshowLog()java.lang.StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
log
protected static final org.apache.commons.logging.Log logLogger -
constantId
protected final java.lang.String constantIdConstant id -
methods
-
-
Constructor Details
-
DataSource
public DataSource(java.lang.String id, java.lang.String constantId, java.lang.String source, JAXXCompiler compiler, java.util.List<JavaMethod> methods)Creates a new data source. After creating aDataSource, usecompile()to cause it to function at runtime.- Parameters:
id- the DataSource's idconstantId- the DataSource constant idsource- the Java source code for the data source expressioncompiler- the currentJAXXCompilermethods- where to store extra method to add to binding
-
-
Method Details
-
getObjectCode
public java.lang.String getObjectCode() -
getTrackers
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
showLog
public boolean showLog() -
compile
Compiles the data source expression and listener. This method calls methods inJAXXCompilerto add the Java code that performs the data source setup. Adding listeners toDataSourceis slightly more complicated than with ordinary classes, becauseDataSourceonly exists at compile time. You must pass in a Java expression which evaluates to aPropertyChangeListener; this expression will be compiled and evaluated at runtime to yield theDataSource'slistener.- Returns:
trueif the expression has dependencies,falseotherwise- Throws:
CompilerException- if a compilation error occursjava.lang.IllegalStateException- if data source was already compiled
-
getOverrideIds
public java.util.Set<java.lang.String> getOverrideIds() -
hasMethod
public boolean hasMethod(java.lang.String methodName) -
getAddMemberListenerCode
public java.lang.String getAddMemberListenerCode(DefaultObjectHandler handler, java.lang.String objectCode, java.lang.String memberName, java.lang.String propertyChangeListenerCode, JAXXCompiler compiler)Returns a snippet of Java code which will cause aPropertyChangeListenerto be notified when the member's value changes. ThePropertyChangeListeneris provided in the form of a Java code snippet that evaluates to a listener object. For ordinary bound JavaBeans properties, the Java code returned is a simple call toaddPropertyChangeListener. Fields and methods which do not actually firePropertyChangeEventswhen they change necessitate more complex code.- Parameters:
handler- Object handler (containts known eventsobjectCode- Java code which evaluates to the object to which to add the listener *@param dataBinding the name of the data binding this listener is a part ofmemberName- the name of the field or method to listen topropertyChangeListenerCode- Java code which evaluates to aPropertyChangeListenercompiler- the currentJAXXCompiler- Returns:
- Java code snippet which causes the listener to be added to the object
-
getRemoveMemberListenerCode
public java.lang.String getRemoveMemberListenerCode(DefaultObjectHandler handler, java.lang.String objectCode, java.lang.String memberName, java.lang.String propertyChangeListenerCode, JAXXCompiler compiler) -
getMethodReturnType
protected ClassDescriptor getMethodReturnType(ClassDescriptor contextClass, MethodDescriptor method)Given a method from a given context class, try to obtain his method return type. Sometimes, the return type is unknown (generics can not be bind for example). As a fallback, we try if the context class is exactly the root context class of the compiler, replace it by the script method with same name on which we can have more chance to obtain a return type...- Parameters:
contextClass- the context class of the methodmethod- the method- Returns:
- the method return type
- Since:
- 2.4.2
-