Package org.nuiton.jaxx.compiler.tags
Class TagManager
- java.lang.Object
-
- org.nuiton.jaxx.compiler.tags.TagManager
-
public class TagManager extends Object
Manages TagHandlers, including automatically compiling .jaxx files corresponding to class tags.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.logging.log4j.LoggerlogLogger
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DefaultObjectHandlergetTagHandler(Class<?> klass)static TagHandlergetTagHandler(String namespace, String tag, boolean namespacePrefix, JAXXCompiler compiler)Returns theTagHandlerthat should be used to process the specified tag.static TagHandlergetTagHandler(String namespace, String tag, JAXXCompiler compiler)Returns theTagHandlerthat should be used to process the specified tag.static DefaultObjectHandlergetTagHandler(ClassDescriptor beanClass)static <T extends TagHandler>
voidregisterBean(ClassDescriptor beanClass, Class<T> handler)Maps a class tag to a specificTagHandler.static voidregisterDefaultNamespace(String tag, String namespace)Sets the default namespace for a tag.static <T extends TagHandler>
voidregisterTag(String namespace, String tag, T handler)Registers aTagHandlerfor a tag.static voidreset()static ClassDescriptorresolveClass(String className, JAXXCompiler compiler)static StringresolveClassName(String name, JAXXCompiler compiler)Resolves a simple class name (likeObjectorString) to its fully-qualified name.
-
-
-
Method Detail
-
reset
public static void reset()
-
registerBean
public static <T extends TagHandler> void registerBean(ClassDescriptor beanClass, Class<T> handler)
Maps a class tag to a specificTagHandler. When a tag representing the bean class is encountered (either the class' simple name, if it is unambiguous, or its fully-qualified name), the specifiedTagHandlerwill be invoked to run it.- Type Parameters:
T- type of handler- Parameters:
beanClass- the class to associate with aTagHandlerhandler- theTagHandlerclass, which must descend fromDefaultObjectHandler- Throws:
IllegalArgumentException- if the handler class does not descend fromDefaultObjectHandler
-
registerDefaultNamespace
public static void registerDefaultNamespace(String tag, 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 anullvalue 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 namenamespace- namespace
-
registerTag
public static <T extends TagHandler> void registerTag(String namespace, String tag, T handler)
Registers aTagHandlerfor a tag. When a tag with the given name and namespace is encountered, theTagHandler's compileFirstPassandcompileSecondPassmethods 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 namespacetag- the simple name of the taghandler- theTagHandlerwhich should process the tag
-
getTagHandler
public static TagHandler getTagHandler(String namespace, String tag, JAXXCompiler compiler) throws CompilerException
Returns theTagHandlerthat should be used to process the specified tag. If the tag represents the class name of an uncompiled.jaxxfile, the.jaxxis first compiled.- Parameters:
namespace- the tag's namespace (may benull)tag- the tag's simple namecompiler- the currentJAXXCompiler- Returns:
- the
TagHandlerfor the tag - Throws:
CompilerException- ?
-
getTagHandler
public static DefaultObjectHandler getTagHandler(Class<?> klass) throws CompilerException
- Parameters:
klass- the java class- Returns:
- the
TagHandlerthat should be used to process the specified class. OnlyTagHandlerspreviously registered withregisterBeanare considered. - Throws:
CompilerException- ?
-
getTagHandler
public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass) throws CompilerException
- Parameters:
beanClass- the tag class- Returns:
- the
TagHandlerthat should be used to process the specified class. OnlyTagHandlerspreviously registered withregisterBeanare considered. - Throws:
CompilerException- ?
-
getTagHandler
public static TagHandler getTagHandler(String namespace, String tag, boolean namespacePrefix, JAXXCompiler compiler) throws CompilerException
Returns theTagHandlerthat should be used to process the specified tag. ThenamespacePrefixparameter 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 benull)tag- the tag's simple name (which can include fully-qualified Java class names)namespacePrefix-trueif the namespace was specified by means of a namespace prefix (as opposed to a default namespace)compiler- the currentJAXXCompiler- Returns:
- the
TagHandlerfor the tag - Throws:
CompilerException- ?
-
resolveClassName
public static String resolveClassName(String name, JAXXCompiler compiler)
Resolves a simple class name (likeObjectorString) 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 asjava.lang.Objectare 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). Returnsnullif no matching class could be found.- Parameters:
name- name to resolvecompiler- run to use- Returns:
- the resolved fqn class name
-
resolveClass
public static ClassDescriptor resolveClass(String className, JAXXCompiler compiler)
-
-