Package org.nuiton.jaxx.compiler.binding
Class DataSource
- java.lang.Object
-
- org.nuiton.jaxx.compiler.binding.DataSource
-
public class DataSource extends Object
Represents a Java expression which fires aPropertyChangeEventwhen 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 StringconstantIdConstant idprotected static org.apache.logging.log4j.LoggerlogLoggerprotected List<JavaMethod>methods
-
Constructor Summary
Constructors Constructor Description DataSource(String id, String constantId, String source, JAXXCompiler compiler, List<JavaMethod> methods)Creates a new data source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancompile()Compiles the data source expression and listener.StringgetAddMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, 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.StringgetObjectCode()Set<String>getOverrideIds()StringgetRemoveMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler)DataListener[]getTrackers()booleanhasMethod(String methodName)booleanshowLog()StringtoString()
-
-
-
Field Detail
-
log
protected static final org.apache.logging.log4j.Logger log
Logger
-
constantId
protected final String constantId
Constant id
-
methods
protected final List<JavaMethod> methods
-
-
Constructor Detail
-
DataSource
public DataSource(String id, String constantId, String source, JAXXCompiler compiler, 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 Detail
-
getObjectCode
public String getObjectCode()
-
getTrackers
public DataListener[] getTrackers()
-
showLog
public boolean showLog()
-
compile
protected boolean compile() throws CompilerException, IllegalStateExceptionCompiles 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 occursIllegalStateException- if data source was already compiled
-
hasMethod
public boolean hasMethod(String methodName)
-
getAddMemberListenerCode
public String getAddMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, 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 String getRemoveMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, 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
-
-