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.String constantId
    Constant id
    protected static org.apache.commons.logging.Log log
    Logger
    protected 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 boolean compile()
    Compiles the data source expression and listener.
    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 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.
    java.lang.String getObjectCode()  
    java.util.Set<java.lang.String> getOverrideIds()  
    java.lang.String getRemoveMemberListenerCode​(DefaultObjectHandler handler, java.lang.String objectCode, java.lang.String memberName, java.lang.String propertyChangeListenerCode, JAXXCompiler compiler)  
    DataListener[] getTrackers()  
    boolean hasMethod​(java.lang.String methodName)  
    boolean showLog()  
    java.lang.String toString()  

    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 log
      Logger
    • constantId

      protected final java.lang.String constantId
      Constant id
    • methods

      protected final java.util.List<JavaMethod> 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 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 Details

    • getObjectCode

      public java.lang.String getObjectCode()
    • getTrackers

      public DataListener[] getTrackers()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • showLog

      public boolean showLog()
    • compile

      protected boolean compile() throws CompilerException, java.lang.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
      java.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 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 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 method
      method - the method
      Returns:
      the method return type
      Since:
      2.4.2