Class TagManager


  • public class TagManager
    extends Object
    Manages TagHandlers, including automatically compiling .jaxx files corresponding to class tags.
    • Field Detail

      • log

        protected static final org.apache.logging.log4j.Logger log
        Logger
    • 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 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:
        IllegalArgumentException - if the handler class does not descend from DefaultObjectHandler
      • 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 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​(String namespace,
                                                              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​(String namespace,
                                               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​(Class<?> klass)
                                                  throws CompilerException
        Parameters:
        klass - the java 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​(String namespace,
                                               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 String resolveClassName​(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