jaxx.compiler.tags
Class TagManager

java.lang.Object
  extended by jaxx.compiler.tags.TagManager

public class TagManager
extends java.lang.Object

Manages TagHandlers, including automatically compiling .jaxx files corresponding to class tags.


Field Summary
protected static org.apache.commons.logging.Log log
          Logger
 
Method Summary
static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass)
           
static TagHandler getTagHandler(java.lang.String namespace, java.lang.String tag, boolean namespacePrefix, JAXXCompiler compiler)
          Returns the TagHandler that should be used to process the specified tag.
static TagHandler getTagHandler(java.lang.String namespace, java.lang.String tag, JAXXCompiler compiler)
          Returns the TagHandler that should be used to process the specified tag.
static
<T extends TagHandler>
void
registerBean(ClassDescriptor beanClass, java.lang.Class<T> handler)
          Maps a class tag to a specific TagHandler.
static void registerDefaultNamespace(java.lang.String tag, java.lang.String namespace)
          Sets the default namespace for a tag.
static
<T extends TagHandler>
void
registerTag(java.lang.String namespace, java.lang.String tag, T handler)
          Registers a TagHandler for a tag.
static void reset(boolean verbose)
           
static ClassDescriptor resolveClass(java.lang.String className, JAXXCompiler compiler)
           
static java.lang.String resolveClassName(java.lang.String name, JAXXCompiler compiler)
          Resolves a simple class name (like Object or String) to its fully-qualified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

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

Method Detail

reset

public static void reset(boolean verbose)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException,
                         java.lang.InstantiationException,
                         java.lang.IllegalAccessException
Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

registerBean

public static <T extends TagHandler> void registerBean(ClassDescriptor beanClass,
                                                       java.lang.Class<T> handler)
Maps a class tag to a specific TagHandler. When a tag representing the bean class is encountered (either the class' simple name, if it is unambiguous, or its fully-qualified name), the specified TagHandler will be invoked to run it.

Type Parameters:
T - type of handler
Parameters:
beanClass - the class to associate with a TagHandler
handler - the TagHandler class, which must descend from DefaultObjectHandler
Throws:
java.lang.IllegalArgumentException - if the handler class does not descend from DefaultObjectHandler

registerDefaultNamespace

public static void registerDefaultNamespace(java.lang.String tag,
                                            java.lang.String namespace)
Sets the default namespace for a tag. When the tag is encountered with no namespace specified, the specified namespace will be assumed. Mapping the same tag to two or more default namespaces removes the mapping and marks the entry as being ambiguous (by putting a null value into the map); this causes an error to be thrown if the tag is used without a namespace being specified.

Java package names on tags are automatically converted into namespaces (e.g. <javax.swing.JButton/> and <JButton xmlns="javax.swing.*"/> are equivalent), so tags with package names are considered to have namespaces specified.

Parameters:
tag - tag name
namespace - namespace

registerTag

public static <T extends TagHandler> void registerTag(java.lang.String namespace,
                                                      java.lang.String tag,
                                                      T handler)
Registers a TagHandler for a tag. When a tag with the given name and namespace is encountered, the TagHandler's compileFirstPass and compileSecondPass methods will be invoked to handle it.

It is not an error to register an already-registered tag and namespace combination. The new mapping will replace the old mapping.

Type Parameters:
T - type of handler
Parameters:
namespace - the tag's namespace
tag - the simple name of the tag
handler - the TagHandler which should process the tag

getTagHandler

public static TagHandler getTagHandler(java.lang.String namespace,
                                       java.lang.String tag,
                                       JAXXCompiler compiler)
                                throws CompilerException
Returns the TagHandler that should be used to process the specified tag. If the tag represents the class name of an uncompiled .jaxx file, the .jaxx is first compiled.

Parameters:
namespace - the tag's namespace (may be null)
tag - the tag's simple name
compiler - the current JAXXCompiler
Returns:
the TagHandler for the tag
Throws:
CompilerException - ?

getTagHandler

public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass)
                                          throws CompilerException
Parameters:
beanClass - the tag class
Returns:
the TagHandler that should be used to process the specified class. Only TagHandlers previously registered with registerBean are considered.
Throws:
CompilerException - ?

getTagHandler

public static TagHandler getTagHandler(java.lang.String namespace,
                                       java.lang.String tag,
                                       boolean namespacePrefix,
                                       JAXXCompiler compiler)
                                throws CompilerException
Returns the TagHandler that should be used to process the specified tag.

The namespacePrefix parameter is used only for error checking, as it is an error to specify conflicting package names using both a fully-qualified tag name and a namespace prefix, but it is not an error to specify conflicting package names using a fully-qualified tag name and a default namespace (i.e. <awt:javax.swing.JButton xmlns:awt='java.awt.*'/> is an error, whereas <javax.swing.JButton xmlns='java.awt.*'/> is not).

Parameters:
namespace - the tag's namespace (may be null)
tag - the tag's simple name (which can include fully-qualified Java class names)
namespacePrefix - true if the namespace was specified by means of a namespace prefix (as opposed to a default namespace)
compiler - the current JAXXCompiler
Returns:
the TagHandler for the tag
Throws:
CompilerException - ?

resolveClassName

public static java.lang.String resolveClassName(java.lang.String name,
                                                JAXXCompiler compiler)
Resolves a simple class name (like Object or String) to its fully-qualified name. Inner classes should be represented as they would appear in Java source code (e.g. JPopupMenu.Separator). Fully-qualified names, such as java.lang.Object are legal and will be returned unmodified (and in fact it is generally impossible to even know whether a given reference is fully qualified until it has been resolved). Returns null if no matching class could be found.

Parameters:
name - name to resolve
compiler - run to use
Returns:
the resolved fqn class name

resolveClass

public static ClassDescriptor resolveClass(java.lang.String className,
                                           JAXXCompiler compiler)


Copyright © 2008-2009 CodeLutin. All Rights Reserved.