Package jaxx.compiler

Class CompiledObject

java.lang.Object
jaxx.compiler.CompiledObject
Direct Known Subclasses:
BeanValidatorHandler.CompiledBeanValidator, JScrollPaneHandler.JScrollPaneCompiledObject, JSpinnerHandler.CompiledSpinner, JTabbedPaneHandler.CompiledTabbedPane, ScriptInitializer

public class CompiledObject
extends java.lang.Object
Represents an object in the .java file being generated during compilation. There is a CompiledObject for each class tag encountered, and certain tags may generate additional objects for various reasons.
  • Constructor Details

    • CompiledObject

      public CompiledObject​(java.lang.String id, ClassDescriptor objectClass, JAXXCompiler compiler)
      Creates a new CompiledObject. To be useful, the object should be registered with a JAXXCompiler using JAXXCompiler.registerCompiledObject(CompiledObject) .
      Parameters:
      id - the object's id
      objectClass - the object's class
      compiler - the current JAXXCompiler
      Throws:
      java.lang.NullPointerException - if id or class is null
    • CompiledObject

      public CompiledObject​(java.lang.String id, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force)
      Creates a new CompiledObject. To be useful, the object should be registered with a JAXXCompiler using JAXXCompiler.registerCompiledObject(CompiledObject) .
      Parameters:
      id - the object's id
      objectClass - the object's class
      compiler - the current JAXXCompiler
      force - true to force acceptance of invalid ids
      Throws:
      java.lang.NullPointerException - if id or class is null
    • CompiledObject

      public CompiledObject​(java.lang.String id, java.lang.String javaCode, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force) throws CompilerException
      Creates a new CompiledObject. To be useful, the object should be registered with a JAXXCompiler using JAXXCompiler.registerCompiledObject(CompiledObject) .
      Parameters:
      id - the object's id
      javaCode - Java code referring to the object
      objectClass - the object's class
      force - true to force acceptance of invalid ids
      compiler - the current JAXXCompiler
      Throws:
      CompilerException - if the id is not a valid Java identifier
      java.lang.NullPointerException - if id or class is null
  • Method Details

    • getSimpleType

      public java.lang.String getSimpleType()
    • isValidID

      public static boolean isValidID​(java.lang.String id)
    • isOverride

      public boolean isOverride()
      True if this object overrides an object in the superclass of the class being compiled. For this to be true, the class currently being compiled must be a subclass of another JAXXObject which has an identically-named object.
      Returns:
      true if this object is an override
      See Also:
      setOverride(boolean)
    • isOverrideType

      public boolean isOverrideType()
      true when overrides an object in the superclass of the class being compiled AND type is also override.
      Returns:
      true if this object is an override AND override type
    • setOverride

      public void setOverride​(boolean override)
      Sets whether this class overrides an identically-named object in the parent class.
      Parameters:
      override - true if this object is an override
      See Also:
      isOverride()
    • setSimpleType

      public void setSimpleType​(java.lang.String simpleType)
      Sets the simple type of the object. Used when castin an overridden object.
      Parameters:
      simpleType - the simple type to use (or the fqn if there is a conflict with already imported types of the compiler).
      Since:
      2.4
    • getStyleClass

      public java.lang.String getStyleClass()
      Returns this object's CSS style class.
      Returns:
      the value of the styleClass attribute
    • setStyleClass

      public void setStyleClass​(java.lang.String styleClass)
      Sets this object's CSS style class.
      Parameters:
      styleClass - the new style class
    • getParent

      public CompiledObject getParent()
      Returns this object's parent container. Non-visual components (and the root container) return null.
      Returns:
      the object's parent container
    • setParent

      public void setParent​(CompiledObject parent) throws java.lang.IllegalArgumentException
      Sets this object's parent container.
      Parameters:
      parent - the parent container
      Throws:
      java.lang.IllegalArgumentException - if parent is not a Container
    • getCreationMethodName

      public java.lang.String getCreationMethodName()
      Returns the name of the method that should be generated in the compiled .java file in order to create this object. This is just a suggestion and may be ignored.
      Returns:
      the suggested name of the method which initializes this object
    • getAdditionMethodName

      public java.lang.String getAdditionMethodName()
      Returns the name of the method that should be generated in the compiled .java file in order to add children to this object. This is just a suggestion and may be ignored.
      Returns:
      the suggested name of the method which completes this object's setup
    • getObjectClass

      public ClassDescriptor getObjectClass()
      Returns the type of this object.
      Returns:
      the class this CompiledObject represents
    • getId

      public java.lang.String getId()
      Returns this object's id. Generally, a field with this name will be created in the compiled .java file in order to represent this object.
      Returns:
      the id used to refer to this object
    • getJavaCode

      public java.lang.String getJavaCode()
      Returns Java code used to refer to this object in the compiled Java file. This is usually the same as its id.
      Returns:
      the Java code for this object
    • getJavaCodeForProperty

      public java.lang.String getJavaCodeForProperty​(java.lang.String property)
    • getConstructorParams

      public java.lang.String getConstructorParams()
      Returns a list of comma-separated Java code snippets that represent the parameters to pass to this object's constructor.
      Returns:
      the raw constructor params
      See Also:
      setConstructorParams(String)
    • setConstructorParams

      public void setConstructorParams​(java.lang.String constructorParams)
      Sets the parameters to pass to this object's constructor.
      Parameters:
      constructorParams - comma-separated Java code snippets representing constructor params
      See Also:
      getConstructorParams()
    • getInitializer

      public java.lang.String getInitializer()
    • setInitializer

      public void setInitializer​(java.lang.String initializer)
    • getInitializationCode

      public java.lang.String getInitializationCode​(JAXXCompiler compiler)
      Returns the code that performs basic initialization of this object, after it has already been constructed. This basic code should not reference any other CompiledObjects as they may not have been created yet.
      Parameters:
      compiler - compiler to use
      Returns:
      the code which initializes this object
    • getInitializationCode

      protected java.lang.String getInitializationCode​(EventHandler handler, JAXXCompiler compiler)
    • getAdditionCode

      public java.lang.String getAdditionCode()
      Returns Java code to complete final setup on this object. This code may reference other CompiledObjects, as they are guaranteed to have all been created by this point.
      Returns:
      code which adds children and performs final setup
    • appendInitializationCode

      public void appendInitializationCode​(java.lang.String code)
      Appends code to the initialization code block. A line separator is automatically appended to the end.
      Parameters:
      code - the code to add to the initialization block
      See Also:
      getInitializationCode(JAXXCompiler)
    • appendAdditionCode

      public void appendAdditionCode​(java.lang.String code)
      Appends code to the addition code block. A line separator is automatically appended to the end.
      Parameters:
      code - the code to add to the addition block
      See Also:
      getAdditionCode()
    • addProperty

      public void addProperty​(java.lang.String property, java.lang.String value)
      Stores a property for this object. The only effect of calling this method is that the property will be returned by getProperties().
      Parameters:
      property - the name of the property
      value - the property's value
      See Also:
      getProperties()
    • hasClientProperties

      public boolean hasClientProperties()
    • addClientProperty

      public void addClientProperty​(java.lang.String property, java.lang.String value)
    • getClientProperty

      public java.lang.String getClientProperty​(java.lang.String key)
    • getClientProperties

      public java.util.Map<java.lang.String,​java.lang.String> getClientProperties()
    • getProperties

      public java.util.Map<?,​?> getProperties()
      Returns all properties which have been set for this object.
      Returns:
      a Map containing all properties defined for this object
      See Also:
      addProperty(String, String)
    • addEventHandler

      public void addEventHandler​(java.lang.String eventId, MethodDescriptor addMethod, MethodDescriptor listenerMethod, java.lang.String code, JAXXCompiler compiler)
      Adds an event listener to this object. The generated code will appear in the initialization block.
      Parameters:
      eventId - unique (per CompiledObject) identifier for the event handler
      addMethod - the method which adds the event listener
      listenerMethod - the method (in the listener class) which is called when the event is fired
      code - the Java code for the listenerMethod's body
      compiler - the current JAXXCompiler
      See Also:
      getInitializationCode(EventHandler, JAXXCompiler)
    • addChild

      public void addChild​(CompiledObject child, JAXXCompiler compiler) throws CompilerException
      Adds a child component to this container. The child is added without layout constraints.
      Parameters:
      child - the component to add
      compiler - the current JAXXCompiler
      Throws:
      CompilerException - if this object is not a container
      See Also:
      addChild(CompiledObject, String, JAXXCompiler)
    • addChild

      public void addChild​(CompiledObject child, java.lang.String constraints, JAXXCompiler compiler) throws CompilerException
      Adds a child component to this container. This variant allows the Java code for a layout constraints object to be specified.
      Parameters:
      child - the component to add
      constraints - Java code for the layout constraints object
      compiler - the current JAXXCompiler
      Throws:
      CompilerException - if this object is not a container
      See Also:
      addChild(CompiledObject, JAXXCompiler)
    • newChildRef

      protected CompiledObject.ChildRef newChildRef​(CompiledObject child, java.lang.String constraints, java.lang.String delegateCode)
    • toString

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

      public java.lang.String getGenericTypes()
    • setGenericTypes

      public void setGenericTypes​(java.lang.String... genericTypes)
    • isJavaBean

      public boolean isJavaBean()
    • setJavaBean

      public void setJavaBean​(boolean javaBean)
    • getOverrideType

      public ClassDescriptor getOverrideType()
    • setOverrideType

      public void setOverrideType​(ClassDescriptor overrideType)
    • getJavaBeanInitCode

      public java.lang.String getJavaBeanInitCode()
    • setJavaBeanInitCode

      public void setJavaBeanInitCode​(java.lang.String javaBeanInitCode)
    • getChilds

      public java.util.List<CompiledObject.ChildRef> getChilds()
    • getDecorator

      public CompiledObjectDecorator getDecorator()
    • setDecorator

      public void setDecorator​(CompiledObjectDecorator decorator)
    • finalizeCompiler

      public void finalizeCompiler​(JAXXCompiler compiler)
    • getGenericTypesLength

      public int getGenericTypesLength()
    • getGetterName

      public java.lang.String getGetterName()