Package org.nuiton.jaxx.compiler
Class CompiledObject
- java.lang.Object
-
- org.nuiton.jaxx.compiler.CompiledObject
-
- Direct Known Subclasses:
BeanValidatorHandler.CompiledBeanValidator,JScrollPaneHandler.JScrollPaneCompiledObject,JSpinnerHandler.CompiledSpinner,JTabbedPaneHandler.CompiledTabbedPane,ScriptInitializer,TabHandler.CompiledTabbedTab
public class CompiledObject extends Object
Represents an object in the.javafile being generated during compilation. There is aCompiledObjectfor each class tag encountered, and certain tags may generate additional objects for various reasons.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCompiledObject.ChildRef
-
Constructor Summary
Constructors Constructor Description CompiledObject(String id, String javaCode, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force)Creates a newCompiledObject.CompiledObject(String id, ClassDescriptor objectClass, JAXXCompiler compiler)Creates a newCompiledObject.CompiledObject(String id, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force)Creates a newCompiledObject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(CompiledObject child, String constraints, JAXXCompiler compiler)Adds a child component to this container.voidaddChild(CompiledObject child, String constraints, JAXXCompiler compiler, DefaultComponentHandler tagHandler)Adds a child component to this container.voidaddClientProperty(String property, String value)voidaddEventHandler(String eventId, MethodDescriptor addMethod, MethodDescriptor listenerMethod, String code, JAXXCompiler compiler)Adds an event listener to this object.voidaddProperty(String property, String value)Stores a property for this object.voidappendAdditionCode(String code)Appends code to the addition code block.voidappendInitializationCode(String code)Appends code to the initialization code block.voidfinalizeCompiler(JAXXCompiler compiler)StringgetAdditionCode()Returns Java code to complete final setup on this object.StringgetAdditionMethodName()Returns the name of the method that should be generated in the compiled.javafile in order to add children to this object.Optional<BeanScope>getBeanScope()List<CompiledObject.ChildRef>getChilds()Map<String,String>getClientProperties()StringgetClientProperty(String key)StringgetConstructorParams()Returns a list of comma-separated Java code snippets that represent the parameters to pass to this object's constructor.StringgetCreationMethodName()Returns the name of the method that should be generated in the compiled.javafile in order to create this object.CompiledObjectDecoratorgetDecorator()StringgetGenericTypes()intgetGenericTypesLength()StringgetGetterName()StringgetI18nProperty()StringgetId()Returns this object's id.protected StringgetInitializationCode(EventHandler handler, JAXXCompiler compiler)StringgetInitializationCode(JAXXCompiler compiler)Returns the code that performs basic initialization of this object, after it has already been constructed.StringgetInitializer()StringgetJavaBeanInitCode()StringgetJavaCode()Returns Java code used to refer to this object in the compiled Java file.StringgetJavaCodeForProperty(String property)ClassDescriptorgetObjectClass()Returns the type of this object.ClassDescriptorgetOverrideType()CompiledObjectgetParent()Returns this object's parent container.Map<?,?>getProperties()Returns all properties which have been set for this object.StringgetSetterName()StringgetSimpleType()StringgetStyleClass()Returns this object's CSS style class.Set<String>getStyleClasses()booleanhasClientProperties()booleanisAddToContainer()booleanisForceOverride()booleanisJavaBean()booleanisOverride()True if this object overrides an object in the superclass of the class being compiled.booleanisOverrideType()truewhen overrides an object in the superclass of the class being compiled AND type is also override.booleanisUseComputeI18n()static booleanisValidID(String id)booleanmatchStyleClass(String styleClass)protected CompiledObject.ChildRefnewChildRef(CompiledObject child, String constraints, String delegateCode)voidsetAddToContainer(boolean addToContainer)voidsetBeanScope(BeanScope beanScope)voidsetConstructorParams(String constructorParams)Sets the parameters to pass to this object's constructor.voidsetDecorator(CompiledObjectDecorator decorator)voidsetForceOverride(boolean forceOverride)voidsetGenericTypes(String... genericTypes)voidsetI18nProperty(String i18nProperty)voidsetInitializer(String initializer)voidsetJavaBean(boolean javaBean)voidsetJavaBeanInitCode(String javaBeanInitCode)voidsetOverride(boolean override)Sets whether this class overrides an identically-named object in the parent class.voidsetOverrideType(ClassDescriptor overrideType)voidsetParent(CompiledObject parent)Sets this object's parent container.voidsetSimpleType(String simpleType)Sets the simple type of the object.voidsetStyleClass(String styleClass)Sets this object's CSS style class.StringtoString()
-
-
-
Constructor Detail
-
CompiledObject
public CompiledObject(String id, ClassDescriptor objectClass, JAXXCompiler compiler)
Creates a newCompiledObject.To be useful, the object should be registered with a
JAXXCompilerusingJAXXCompiler.registerCompiledObject(CompiledObject).- Parameters:
id- the object's idobjectClass- the object's classcompiler- the currentJAXXCompiler- Throws:
NullPointerException- if id or class is null
-
CompiledObject
public CompiledObject(String id, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force)
Creates a newCompiledObject. To be useful, the object should be registered with aJAXXCompilerusingJAXXCompiler.registerCompiledObject(CompiledObject).- Parameters:
id- the object's idobjectClass- the object's classcompiler- the currentJAXXCompilerforce-trueto force acceptance of invalid ids- Throws:
NullPointerException- if id or class is null
-
CompiledObject
public CompiledObject(String id, String javaCode, ClassDescriptor objectClass, JAXXCompiler compiler, boolean force) throws CompilerException
Creates a newCompiledObject. To be useful, the object should be registered with aJAXXCompilerusingJAXXCompiler.registerCompiledObject(CompiledObject).- Parameters:
id- the object's idjavaCode- Java code referring to the objectobjectClass- the object's classforce-trueto force acceptance of invalid idscompiler- the currentJAXXCompiler- Throws:
CompilerException- if the id is not a valid Java identifierNullPointerException- if id or class is null
-
-
Method Detail
-
getSimpleType
public String getSimpleType()
-
setBeanScope
public void setBeanScope(BeanScope beanScope)
-
setAddToContainer
public void setAddToContainer(boolean addToContainer)
-
isAddToContainer
public boolean isAddToContainer()
-
isValidID
public static boolean isValidID(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 anotherJAXXObjectwhich has an identically-named object.- Returns:
trueif this object is an override- See Also:
setOverride(boolean)
-
isForceOverride
public boolean isForceOverride()
-
setForceOverride
public void setForceOverride(boolean forceOverride)
-
isOverrideType
public boolean isOverrideType()
truewhen overrides an object in the superclass of the class being compiled AND type is also override.- Returns:
trueif 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-trueif this object is an override- See Also:
isOverride()
-
setSimpleType
public void setSimpleType(String simpleType)
Sets the simple type of the object.Used when cast in 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 String getStyleClass()
Returns this object's CSS style class.- Returns:
- the value of the
styleClassattribute
-
matchStyleClass
public boolean matchStyleClass(String styleClass)
-
setStyleClass
public void setStyleClass(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) returnnull.- Returns:
- the object's parent container
-
setParent
public void setParent(CompiledObject parent) throws IllegalArgumentException
Sets this object's parent container.- Parameters:
parent- the parent container- Throws:
IllegalArgumentException- if parent is not aContainer
-
getCreationMethodName
public String getCreationMethodName()
Returns the name of the method that should be generated in the compiled.javafile 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 String getAdditionMethodName()
Returns the name of the method that should be generated in the compiled.javafile 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
CompiledObjectrepresents
-
getId
public String getId()
Returns this object's id. Generally, a field with this name will be created in the compiled.javafile in order to represent this object.- Returns:
- the id used to refer to this object
-
getJavaCode
public 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
-
getConstructorParams
public 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(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 String getInitializer()
-
setInitializer
public void setInitializer(String initializer)
-
getInitializationCode
public 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 otherCompiledObjectsas they may not have been created yet.- Parameters:
compiler- compiler to use- Returns:
- the code which initializes this object
-
getInitializationCode
protected String getInitializationCode(EventHandler handler, JAXXCompiler compiler)
-
getAdditionCode
public String getAdditionCode()
Returns Java code to complete final setup on this object. This code may reference otherCompiledObjects, 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(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(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(String property, String value)
Stores a property for this object. The only effect of calling this method is that the property will be returned bygetProperties().- Parameters:
property- the name of the propertyvalue- the property's value- See Also:
getProperties()
-
hasClientProperties
public boolean hasClientProperties()
-
getProperties
public Map<?,?> getProperties()
Returns all properties which have been set for this object.- Returns:
- a
Mapcontaining all properties defined for this object - See Also:
addProperty(String, String)
-
addEventHandler
public void addEventHandler(String eventId, MethodDescriptor addMethod, MethodDescriptor listenerMethod, 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 handleraddMethod- the method which adds the event listenerlistenerMethod- the method (in the listener class) which is called when the event is firedcode- the Java code for the listenerMethod's bodycompiler- the currentJAXXCompiler- See Also:
getInitializationCode(EventHandler, JAXXCompiler)
-
addChild
public void addChild(CompiledObject child, 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 addconstraints- Java code for the layout constraints objectcompiler- the currentJAXXCompiler- Throws:
CompilerException- if this object is not a container
-
addChild
public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler, DefaultComponentHandler tagHandler) 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 addconstraints- Java code for the layout constraints objectcompiler- the currentJAXXCompilertagHandler- parent tag handler- Throws:
CompilerException- if this object is not a container
-
newChildRef
protected CompiledObject.ChildRef newChildRef(CompiledObject child, String constraints, String delegateCode)
-
getGenericTypes
public String getGenericTypes()
-
setGenericTypes
public void setGenericTypes(String... genericTypes)
-
isJavaBean
public boolean isJavaBean()
-
setJavaBean
public void setJavaBean(boolean javaBean)
-
getOverrideType
public ClassDescriptor getOverrideType()
-
setOverrideType
public void setOverrideType(ClassDescriptor overrideType)
-
getJavaBeanInitCode
public String getJavaBeanInitCode()
-
setJavaBeanInitCode
public void setJavaBeanInitCode(String javaBeanInitCode)
-
getChilds
public 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 String getGetterName()
-
getSetterName
public String getSetterName()
-
isUseComputeI18n
public boolean isUseComputeI18n()
-
getI18nProperty
public String getI18nProperty()
-
setI18nProperty
public void setI18nProperty(String i18nProperty)
-
-