jaxx.compiler.binding
Class DataSource

java.lang.Object
  extended by jaxx.compiler.binding.DataSource

public class DataSource
extends 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
protected  String constantId
          Constant id
protected static org.apache.commons.logging.Log log
          Logger
protected  List<JavaMethod> methods
           
 
Constructor Summary
DataSource(String id, String constantId, String source, JAXXCompiler compiler, List<JavaMethod> methods)
          Creates a new data source.
 
Method Summary
protected  boolean compile()
          Compiles the data source expression and listener.
 String getAddMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler)
          Returns a snippet of Java code which will cause a PropertyChangeListener to be notified when the member's value changes.
protected  ClassDescriptor getMethodReturnType(ClassDescriptor contextClass, MethodDescriptor method)
          Given a method from a given context class, try to obtain his method return type.
 String getObjectCode()
           
 Set<String> getOverrideIds()
           
 String getRemoveMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler)
           
 DataListener[] getTrackers()
           
 boolean hasMethod(String methodName)
           
 boolean showLog()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log 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 a DataSource, use compile() to cause it to function at runtime.

Parameters:
id - the DataSource's id
constantId - the DataSource constant id
source - the Java source code for the data source expression
compiler - the current JAXXCompiler
methods - where to store extra method to add to binding
Method Detail

getObjectCode

public String getObjectCode()

getTrackers

public DataListener[] getTrackers()

toString

public String toString()
Overrides:
toString in class Object

showLog

public boolean showLog()

compile

protected boolean compile()
                   throws CompilerException,
                          IllegalStateException
Compiles the data source expression and listener. This method calls methods in JAXXCompiler to add the Java code that performs the data source setup. Adding listeners to DataSource is slightly more complicated than with ordinary classes, because DataSource only exists at compile time. You must pass in a Java expression which evaluates to a PropertyChangeListener; this expression will be compiled and evaluated at runtime to yield the DataSource's listener.

Returns:
true if the expression has dependencies, false otherwise
Throws:
CompilerException - if a compilation error occurs
IllegalStateException - if data source was already compiled

getOverrideIds

public Set<String> getOverrideIds()

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 a PropertyChangeListener to be notified when the member's value changes. The PropertyChangeListener is 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 to addPropertyChangeListener. Fields and methods which do not actually fire PropertyChangeEvents when they change necessitate more complex code.

Parameters:
handler - Object handler (containts known events
objectCode - 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 of
memberName - the name of the field or method to listen to
propertyChangeListenerCode - Java code which evaluates to a PropertyChangeListener
compiler - the current JAXXCompiler
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 method
method - the method
Returns:
the method return type
Since:
2.4.2


Copyright © 2008-2011 CodeLutin. All Rights Reserved.