Package jaxx.compiler

Class JAXXCompiler

java.lang.Object
jaxx.compiler.JAXXCompiler

public class JAXXCompiler
extends java.lang.Object
Compiles a given jaxxFile into a javaFile.
Since:
1.0.0
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

    • log

      protected static final org.apache.commons.logging.Log log
      Logger
    • STRICT_CHECKS

      public static boolean STRICT_CHECKS
      True to throw exceptions when we encounter unresolvable classes, false to ignore. This is currently set to false until JAXX has full support for inner classes (including enumerations), because currently they don't always resolve (but will generally run without error anyway).
    • JAXX_NAMESPACE

      public static final java.lang.String JAXX_NAMESPACE
      See Also:
      Constant Field Values
    • JAXX_INTERNAL_NAMESPACE

      public static final java.lang.String JAXX_INTERNAL_NAMESPACE
      See Also:
      Constant Field Values
    • INLINE_THRESHOLD

      public static final int INLINE_THRESHOLD
      Maximum length of an inlinable creation method.
      See Also:
      Constant Field Values
    • lineSeparator

      protected static java.lang.String lineSeparator
      Line separator cached value
    • BORDER_LAYOUT_PREFIX

      public static final java.lang.String BORDER_LAYOUT_PREFIX
    • firstPassClassTagHandler

      protected final DefaultObjectHandler firstPassClassTagHandler
      The unique object handler used in first pass
    • failed

      protected boolean failed
      flag to detect if an error occurs while compiling jaxx file
    • root

      protected CompiledObject root
      Object corresponding to the root tag in the document.
    • importedPackages

      protected java.util.Set<java.lang.String> importedPackages
      Contains strings of the form "javax.swing."
    • importedClasses

      protected java.util.Set<java.lang.String> importedClasses
      Contains strings of the form "javax.swing.Timer"
    • openComponents

      protected java.util.Stack<CompiledObject> openComponents
      Keeps track of open components (components still having children added).
    • idHelper

      protected final IDHelper idHelper
      to generate ids
    • bindingHelper

      protected final DataBindingHelper bindingHelper
      Binding Util
    • symbolTable

      protected SymbolTable symbolTable
      table of symbols for this compiler
    • baseDir

      protected java.io.File baseDir
      Base directory used for path resolution (normally the directory in which the .jaxx file resides).
    • src

      protected java.io.File src
      jaxx file being compiled.
    • document

      protected org.w3c.dom.Document document
      Parsed XML of src file.
    • outputClassName

      protected java.lang.String outputClassName
      Name of class being compiled.
    • scriptManager

      protected ScriptManager scriptManager
      script manager
    • stylesheet

      protected Stylesheet stylesheet
      Combination of all stylesheets registered using registerStylesheet(Stylesheet).
    • inlineStyles

      protected java.util.List<Rule> inlineStyles
      Contains all attributes defined inline on class tags.
    • eventHandlers

      protected java.util.Map<java.lang.String,​java.util.Map<ClassDescriptor,​java.util.List<EventHandler>>> eventHandlers
      Maps objects (expressed in Java code) to event listener classes (e.g. MouseListener) to Lists of EventHandlers. The final list contains all event handlers of a particular type attached to a particular object (again, as represented by a Java expression).
    • eventHandlerMethodNames

      protected java.util.Map<EventHandler,​java.lang.String> eventHandlerMethodNames
      Map of event handler method names used in compiler
    • classLoader

      protected java.lang.ClassLoader classLoader
      ClassLoader which searches the user-specified class path in addition to the normal class path
    • initializers

      protected java.util.List<java.lang.Runnable> initializers
      A list of Runnables which will be run after the first compilation pass. This is primarily used to trigger the creation of CompiledObjects, which cannot be created during the first pass and must be created in document order.
    • initializer

      protected java.lang.StringBuilder initializer
      Extra code to be added to the instance initializer.
    • lateInitializer

      protected java.lang.StringBuilder lateInitializer
      Extra code to be added at the end of the instance initializer.
    • bodyCode

      protected java.lang.StringBuilder bodyCode
      Extra code to be added to the class body.
    • mainDeclared

      protected boolean mainDeclared
      true if a main() method has been declared in a script
    • javaFile

      protected JavaFile javaFile
      the file to be generated
    • tagsBeingCompiled

      protected java.util.Stack<org.w3c.dom.Element> tagsBeingCompiled
      Used for error reporting purposes, so we can report the right line number.
    • sourceFiles

      protected java.util.Stack<java.io.File> sourceFiles
      Used for error reporting purposes, so we can report the right source file.
    • objects

      protected java.util.Map<java.lang.String,​CompiledObject> objects
      Maps object ID strings to the objects themselves. These are created during the second compilation pass.
    • ids

      protected java.util.Map<CompiledObject,​java.lang.String> ids
      Maps objects to their ID strings. These are created during the second compilation pass.
    • defaultDecorator

      protected CompiledObjectDecorator defaultDecorator
      default decodator to use if none specified
    • engine

      protected final JAXXEngine engine
      engine which references this compiler (can be null if compiler is standalone)
    • defaultConfiguration

      protected final CompilerConfiguration defaultConfiguration
    • jaxxFile

      protected final JAXXCompilerFile jaxxFile
    • identCssFound

      protected boolean identCssFound
      Flag to know if jaxx file ident css was found, otherwise add it at the end of the second compile pass.
      Since:
      2.0.2
    • needSwingUtil

      @Deprecated protected boolean needSwingUtil
      Deprecated.
      since 2.4.1, will be removed in version 3.0, it is not a good idea to do special treatment for a particular class, to use SwingUtil, do like for other class : import it!
      A flag to know if SwingUtil msut be imported.
      Since:
      2.4
    • EMPTY_STRING_ARRAY

      public static final java.lang.String[] EMPTY_STRING_ARRAY
    • uiHandler

      protected java.lang.String uiHandler
  • Constructor Details

    • JAXXCompiler

      public JAXXCompiler()
    • JAXXCompiler

      public JAXXCompiler​(JAXXEngine engine, JAXXCompilerFile jaxxFile, java.util.List<java.lang.String> defaultImports)
      Creates a new JAXXCompiler.
      Parameters:
      engine - engine which use the compiler (could be null if not attach to any engine)
      jaxxFile - the file to compile
      defaultImports - list of default imports to add to java files
  • Method Details

    • runInitializers

      public void runInitializers()
    • registerInitializer

      public void registerInitializer​(java.lang.Runnable r)
      Registers a Runnable which will be executed after the first compilation pass is complete.
      Parameters:
      r - runnable to register
    • compileFirstPass

      public void compileFirstPass​(org.w3c.dom.Element tag) throws java.io.IOException
      Throws:
      java.io.IOException
    • compileSecondPass

      public void compileSecondPass​(org.w3c.dom.Element tag) throws java.io.IOException
      Throws:
      java.io.IOException
    • compileFirstPass

      public void compileFirstPass() throws java.io.IOException
      Throws:
      java.io.IOException
    • compileSecondPass

      public void compileSecondPass() throws java.io.IOException
      Throws:
      java.io.IOException
    • openComponent

      public void openComponent​(CompiledObject component) throws CompilerException
      Throws:
      CompilerException
    • openComponent

      public void openComponent​(CompiledObject component, java.lang.String constraints) throws CompilerException
      Throws:
      CompilerException
    • openInvisibleComponent

      public void openInvisibleComponent​(CompiledObject component)
    • getOpenComponent

      public CompiledObject getOpenComponent()
    • closeComponent

      public void closeComponent​(CompiledObject component)
    • registerCompiledObject

      public void registerCompiledObject​(CompiledObject object)
    • getCompiledObject

      public CompiledObject getCompiledObject​(java.lang.String id)
    • inlineCreation

      public boolean inlineCreation​(CompiledObject object)
    • checkOverride

      public void checkOverride​(CompiledObject object) throws CompilerException
      Throws:
      CompilerException
    • getBindingHelper

      public DataBindingHelper getBindingHelper()
    • registerEventHandler

      public void registerEventHandler​(EventHandler handler)
    • getEventHandlerMethodName

      public java.lang.String getEventHandlerMethodName​(EventHandler handler)
    • addScriptField

      public void addScriptField​(FieldDescriptor field)
    • addScriptMethod

      public void addScriptMethod​(MethodDescriptor method)
    • registerScript

      public void registerScript​(java.lang.String script) throws CompilerException
      Throws:
      CompilerException
    • registerScript

      public void registerScript​(java.lang.String script, java.io.File sourceFile) throws CompilerException
      Throws:
      CompilerException
    • preprocessScript

      public java.lang.String preprocessScript​(java.lang.String script) throws CompilerException
      Throws:
      CompilerException
    • isIdentCssFound

      public boolean isIdentCssFound()
    • registerStyleSheetFile

      public void registerStyleSheetFile​(java.io.File styleFile, boolean warnAutoCssImport) throws java.io.IOException
      Throws:
      java.io.IOException
    • applyStylesheets

      public void applyStylesheets()
    • registerStylesheet

      public void registerStylesheet​(Stylesheet stylesheet)
    • addInlineStyle

      public void addInlineStyle​(CompiledObject object, java.lang.String propertyName, boolean dataBinding)
    • reportWarning

      public void reportWarning​(java.lang.String warning)
    • reportWarning

      public void reportWarning​(org.w3c.dom.Element tag, java.lang.String warning, int lineOffset)
    • reportError

      public void reportError​(java.lang.String error)
    • reportError

      public void reportError​(CompilerException ex)
    • reportError

      public void reportError​(java.lang.String extraMessage, CompilerException ex)
    • reportError

      public void reportError​(org.w3c.dom.Element tag, java.lang.String error)
    • reportError

      public void reportError​(org.w3c.dom.Element tag, java.lang.String error, int lineOffset)
    • reportError

      public void reportError​(int lineNumber, java.lang.String error)
    • getObjects

      public java.util.Map<java.lang.String,​CompiledObject> getObjects()
    • getEventHandlers

      public java.util.Map<java.lang.String,​java.util.Map<ClassDescriptor,​java.util.List<EventHandler>>> getEventHandlers()
    • getConfiguration

      public CompilerConfiguration getConfiguration()
    • getOutputClassName

      public java.lang.String getOutputClassName()
    • getBaseDir

      public java.io.File getBaseDir()
    • getImportedClasses

      public java.util.Set<java.lang.String> getImportedClasses()
    • getImportedPackages

      public java.util.Set<java.lang.String> getImportedPackages()
    • getObjectCreationOrder

      public java.util.Iterator<CompiledObject> getObjectCreationOrder()
    • getRootObject

      public CompiledObject getRootObject()
    • getSourceFiles

      public java.util.Stack<java.io.File> getSourceFiles()
    • getScriptManager

      public ScriptManager getScriptManager()
    • getSymbolTable

      public SymbolTable getSymbolTable()
    • getStylesheet

      public Stylesheet getStylesheet()
    • getScriptFields

      public FieldDescriptor[] getScriptFields()
    • getScriptField

      public FieldDescriptor getScriptField​(java.lang.String fieldName)
    • getScriptMethods

      public MethodDescriptor[] getScriptMethods()
    • getScriptMethod

      public MethodDescriptor getScriptMethod​(java.lang.String methodName)
    • isFailed

      public boolean isFailed()
    • getIdHelper

      public IDHelper getIdHelper()
    • getClassLoader

      public java.lang.ClassLoader getClassLoader()
      Returns a ClassLoader which searches the user-specified class path in addition to the normal system class path.
      Returns:
      ClassLoader to use while resolving class references
    • isSuperClassAware

      public boolean isSuperClassAware​(java.lang.Class<?> type) throws java.lang.ClassNotFoundException
      Checks if the super class of the mirrored javaFile is aware of the iven type. Note: If no super-class exist, then returns false.
      Parameters:
      type - the type to check against super class
      Returns:
      true if super class exists and is assignable against the given type, false otherwise
      Throws:
      java.lang.ClassNotFoundException - if could not find class descriptor for super-class
    • getJAXXObjectDescriptor

      public JAXXObjectDescriptor getJAXXObjectDescriptor()
    • getInitializer

      public java.lang.StringBuilder getInitializer()
    • getLateInitializer

      public java.lang.StringBuilder getLateInitializer()
    • getBodyCode

      public java.lang.StringBuilder getBodyCode()
    • isMainDeclared

      public boolean isMainDeclared()
    • setMainDeclared

      public void setMainDeclared​(boolean mainDeclared)
    • appendInitializerCode

      public void appendInitializerCode​(java.lang.String code)
    • appendBodyCode

      public void appendBodyCode​(java.lang.String code)
    • appendLateInitializer

      public void appendLateInitializer​(java.lang.String code)
    • hasMethod

      public boolean hasMethod​(java.lang.String methodName)
    • addImport

      public void addImport​(java.lang.Class<?> clazz)
    • addImport

      public void addImport​(java.lang.String text)
    • addDefaultImport

      protected void addDefaultImport​(java.lang.String text)
    • addDependencyClass

      public void addDependencyClass​(java.lang.String className)
    • loadFile

      public java.lang.String loadFile​(java.io.File file)
      Loads the given file and returns its content. Note: If any errors encounters, then report an error in the compiler and returns an empty string.
      Parameters:
      file - the file to load
      Returns:
      the content of the file or empty string if something was wrong
    • checkJavaCode

      public java.lang.String checkJavaCode​(java.lang.String javaCode)
      Verifies that a snippet of Java code parses correctly. A warning is generated if the string has enclosing curly braces.
      Parameters:
      javaCode - the Java code snippet to test
      Returns:
      a "cooked" version of the string which has enclosing curly braces removed.
      Throws:
      CompilerException - if the code cannot be parsed
    • checkReference

      public boolean checkReference​(org.w3c.dom.Element tag, java.lang.String reference, boolean strict, java.lang.String attribute)
      Check that a reference exists in symbol table on second compil pass
      Parameters:
      tag - the current tag
      reference - the required reference
      strict - flag to report an error if reference was not found
      attribute - (if not null reference the attribute where is defined the reference)
      Returns:
      true if reference was found, false otherwise and add an error in compiler
    • getAutoId

      public java.lang.String getAutoId​(java.lang.String name)
    • getUniqueId

      public java.lang.String getUniqueId​(java.lang.Object object)
    • setExtraInterfaces

      public void setExtraInterfaces​(java.lang.String[] extraInterfaces)
    • getExtraInterfaces

      public java.lang.String[] getExtraInterfaces()
    • isAbstractClass

      public boolean isAbstractClass()
    • setAbstractClass

      public void setAbstractClass​(boolean abstractClass)
    • getGenericType

      public java.lang.String getGenericType()
    • setGenericType

      public void setGenericType​(java.lang.String genericType)
    • getSuperGenericType

      public java.lang.String getSuperGenericType()
    • setSuperGenericType

      public void setSuperGenericType​(java.lang.String superGenericType)
    • addSimpleField

      public void addSimpleField​(JavaField javaField)
    • getJavaFile

      public JavaFile getJavaFile()
    • preFinalizeCompiler

      public void preFinalizeCompiler() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • finalizeCompiler

      public void finalizeCompiler() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • generate

      public void generate​(JavaFileGenerator generator) throws java.io.IOException
      Throws:
      java.io.IOException
    • getLineSeparator

      public static java.lang.String getLineSeparator()
      Returns the system line separator string.
      Returns:
      the string used to separate lines
    • getCanonicalName

      public static java.lang.String getCanonicalName​(java.lang.Class<?> clazz)
    • getCanonicalName

      public static java.lang.String getCanonicalName​(ClassDescriptor clazz)
    • getCanonicalName

      public static java.lang.String getCanonicalName​(CompiledObject compiled)
    • escapeJavaString

      public static java.lang.String escapeJavaString​(java.lang.String raw)
      Escapes a string using standard Java escape sequences, generally in preparation to including it in a string literal in a compiled Java file.
      Parameters:
      raw - the raw string to be escape
      Returns:
      a string in which all 'dangerous' characters have been replaced by equivalent Java escape sequences
    • URLtoFile

      public static java.io.File URLtoFile​(java.net.URL url)
    • URLtoFile

      public static java.io.File URLtoFile​(java.lang.String urlString)
    • getSAXParser

      public static javax.xml.parsers.SAXParser getSAXParser()
    • parseDocument

      public static org.w3c.dom.Document parseDocument​(java.io.InputStream in) throws java.io.IOException, org.xml.sax.SAXException
      Throws:
      java.io.IOException
      org.xml.sax.SAXException
    • getEngine

      public JAXXEngine getEngine()
    • clear

      public void clear()
    • setClassLoader

      public void setClassLoader​(java.lang.ClassLoader classLoader)
    • getImportedType

      public java.lang.String getImportedType​(java.lang.Class<?> type)
      Try to import the given type into the underlying java file of this compiler. If import can not be done, will then returns the fully qualified name of the type.
      Parameters:
      type - the type to simplify
      Returns:
      the simplify type or the fqn if type could not be imported for the underlying java file.
      Since:
      2.4.1
    • getImportedType

      public java.lang.String getImportedType​(java.lang.String type)
      Try to import the given type into the underlying java file of this compiler. If import can not be done, will then returns the fully qualified name of the type.
      Parameters:
      type - the fqn of the type to simplify
      Returns:
      the simplify type or the fqn if type could not be imported for the underlying java file.
      Since:
      2.4.1
    • getImportedTypeForSimpleName

      public java.lang.String getImportedTypeForSimpleName​(java.lang.String type)
    • getImportManager

      @Deprecated public org.nuiton.eugene.java.extension.ImportsManager getImportManager()
      Deprecated.
      since 2.4.1, will be removed in version 3.0 : do not want to expose eugene export manager in rest of api, this is purpose of JavaFile only
      Returns:
      the javafile import manager
      Since:
      2.4
    • isNeedSwingUtil

      @Deprecated public boolean isNeedSwingUtil()
      Deprecated.
      since 2.4.1, will be removed in version 3.0, has no effect do not use it...
      Since:
      2.4
    • setNeedSwingUtil

      @Deprecated public void setNeedSwingUtil​(boolean needSwingUtil)
      Deprecated.
      since 2.4.1, will be removed in version 3.0, has no effect do not use it...
      Since:
      2.4
    • containsScriptField

      public boolean containsScriptField​(java.lang.String fieldName)
    • getUiHandler

      public java.lang.String getUiHandler()
    • setUiHandler

      public void setUiHandler​(java.lang.String uiHandler)
    • isUseHandler

      public boolean isUseHandler()