net.sf.jsfcomp.facelets.deploy
Class FaceletAnnotationParser

java.lang.Object
  extended by net.sf.jsfcomp.facelets.deploy.FaceletAnnotationParser

public class FaceletAnnotationParser
extends java.lang.Object

The parser that scans the classpath for annotated classes, creating tag libraries and registers them with the facelets compiler.

Author:
Andrew Robinson (andrew)
See Also:
parse(), Compiler, AnnotationTagLibrary

Field Summary
static java.lang.String MANIFEST_SECTION_NAME
           
 
Constructor Summary
FaceletAnnotationParser()
          Default constructor (required for ParserFactory)
 
Method Summary
static void addToFacelets(java.util.Set<AnnotationTagLibrary> libraries)
          Convenience method that gets the compiler from the facelet factory and registers the tag libraries with it.
static void addToFacelets(java.util.Set<AnnotationTagLibrary> libraries, com.sun.facelets.compiler.Compiler c)
          Convenience method that adds the given libraries to the compiler given
protected  java.lang.String getClassName(java.lang.String name)
          Translate a file system path or a jar file path into a class name.
protected  RegisterPriority getEffectivePriority(RegisterPriority value, RegisterPriority defaultValue)
          Get the effective priority
protected  java.util.Iterator<java.net.URL> getManifestsToScan()
           
protected  java.lang.String getManifestValue(java.util.jar.Manifest mf, java.lang.String namedSection, java.lang.String attrName, java.lang.String defaultValueIfNotSet)
          Get a value from a named section in a manifest
protected  AnnotationTagLibrary getTagLibrary(java.lang.String ns)
          Get a tag library.
protected  AnnotationTagLibraryFactory getTagLibraryFactory()
          Get an instance of the tag library factory.
protected  boolean iteratorContains(java.util.Iterator<?> iter, java.lang.Object value)
          Utility function to see if a value is contained in an iterator
protected  java.lang.Iterable<ScanLocationInformation> obtainLocationsToScan()
          Obtain the URLs to scan for class files.
 java.util.Set<AnnotationTagLibrary> parse()
          The work-horse of the class.
protected  boolean parseClassesInPath(java.net.URL manifestPath, java.util.jar.Manifest mf)
          Checks a manifest to see if the path should be parsed.
protected  void parseComponent(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Parse a class that has the FaceletComponent annotation
protected  void parseConverter(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Parse a class that has the FaceletConverter annotation
protected  void parseFunctions(java.lang.Class<?> cls)
          Parse a class for functions
protected  void parseRenderer(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Parse a class that has the FacesRenderer annotation
protected  void parseTagHandler(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Parse a class that has the FaceletTagHandler annotation
protected  void parseValidator(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Parse a class that has the FaceletValidator annotation
protected  void postScan(javax.faces.context.FacesContext context, java.lang.Class<?> cls, RegisterPriority defaultPriority)
          Allows sub-classes to do any further work on the given class.
protected  void scanClass(javax.faces.context.FacesContext context, java.lang.String name, RegisterPriority defaultPriority)
          Loads the Class for the given name and then checks it for facelet deployment annotations
protected  void scanClassesInDirectory(javax.faces.context.FacesContext context, java.io.File dir, RegisterPriority defaultPriority)
          Scan the given directory
protected  void scanClassesInDirectory(javax.faces.context.FacesContext context, java.io.File dir, java.lang.StringBuilder path, RegisterPriority defaultPriority)
          Called from scanClassesInDirectory and recursively calls itself looking for files with a .class extension in sub-directories
protected  void scanClassesInJar(javax.faces.context.FacesContext context, java.io.File jarFile, RegisterPriority defaultPriority)
          Scan the classes in a jar file on the classpath
protected  void scanClasspath(javax.faces.context.FacesContext context)
          Scan the class path for annotated classes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANIFEST_SECTION_NAME

public static final java.lang.String MANIFEST_SECTION_NAME
See Also:
Constant Field Values
Constructor Detail

FaceletAnnotationParser

public FaceletAnnotationParser()
Default constructor (required for ParserFactory)

Method Detail

parse

public java.util.Set<AnnotationTagLibrary> parse()
                                          throws ParserException
The work-horse of the class. Parses the classpath to find classes that contain facelets deployment annotations

Returns:
Set of configured tag libraries
Throws:
ParserException - thrown if there was an issue during parsing

addToFacelets

public static void addToFacelets(java.util.Set<AnnotationTagLibrary> libraries)
                          throws java.lang.IllegalStateException
Convenience method that gets the compiler from the facelet factory and registers the tag libraries with it. Requires that FaceletFactory.getInstance() returns an instance of DefaultFaceletFactory.

Once the compiler is obtained, it calls addToFacelets(Set, Compiler).

Throws:
java.lang.IllegalStateException - thrown if the facelet factory instance is not of type DefaultFaceletFactory
See Also:
DefaultFaceletFactory.getCompiler(), DefaultFaceletFactory, FaceletFactory.getInstance()

addToFacelets

public static void addToFacelets(java.util.Set<AnnotationTagLibrary> libraries,
                                 com.sun.facelets.compiler.Compiler c)
Convenience method that adds the given libraries to the compiler given

Parameters:
libraries - the tag libraries to add
c - the compiler to add them to

scanClassesInJar

protected void scanClassesInJar(javax.faces.context.FacesContext context,
                                java.io.File jarFile,
                                RegisterPriority defaultPriority)
                         throws java.io.IOException,
                                FactoryException
Scan the classes in a jar file on the classpath

Parameters:
context - the faces context to use when registering JSF items
jarFile - the jar file to scan
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
java.io.IOException - opening and scanning the jar file errors
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

scanClassesInDirectory

protected void scanClassesInDirectory(javax.faces.context.FacesContext context,
                                      java.io.File dir,
                                      RegisterPriority defaultPriority)
                               throws FactoryException
Scan the given directory

Parameters:
context - the faces context to use when registering JSF items
dir - the directory
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException

scanClassesInDirectory

protected void scanClassesInDirectory(javax.faces.context.FacesContext context,
                                      java.io.File dir,
                                      java.lang.StringBuilder path,
                                      RegisterPriority defaultPriority)
                               throws FactoryException
Called from scanClassesInDirectory and recursively calls itself looking for files with a .class extension in sub-directories

Parameters:
context - the faces context to use when registering JSF items
dir - the current directory
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
path - the path to this directory starting after the directory in the classpath (so the folders in this path should mirror the package of the class file)
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

getClassName

protected java.lang.String getClassName(java.lang.String name)
Translate a file system path or a jar file path into a class name. If the name does not appear to be a class or a class that supports deployment (for example, an inner class), this method should return null.

Parameters:
name - the file name and relative path from the directory or the entry name from the jar file
Returns:
The java-compatible class name or null if not supported

scanClass

protected void scanClass(javax.faces.context.FacesContext context,
                         java.lang.String name,
                         RegisterPriority defaultPriority)
                  throws FactoryException
Loads the Class for the given name and then checks it for facelet deployment annotations

Parameters:
context - the faces context to use when registering JSF items
name - the class name
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

postScan

protected void postScan(javax.faces.context.FacesContext context,
                        java.lang.Class<?> cls,
                        RegisterPriority defaultPriority)
                 throws FactoryException
Allows sub-classes to do any further work on the given class. Called from #scanClass(FacesContext, String), scanClass.

Parameters:
context - the faces context to use when registering JSF items
cls - the class to scan
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

parseConverter

protected void parseConverter(javax.faces.context.FacesContext context,
                              java.lang.Class<?> cls,
                              RegisterPriority defaultPriority)
                       throws FactoryException
Parse a class that has the FaceletConverter annotation

Parameters:
context - the faces context to use when registering JSF items
cls - the class
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

parseValidator

protected void parseValidator(javax.faces.context.FacesContext context,
                              java.lang.Class<?> cls,
                              RegisterPriority defaultPriority)
                       throws FactoryException
Parse a class that has the FaceletValidator annotation

Parameters:
context - the faces context to use when registering JSF items
cls - the class
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

parseTagHandler

protected void parseTagHandler(javax.faces.context.FacesContext context,
                               java.lang.Class<?> cls,
                               RegisterPriority defaultPriority)
                        throws FactoryException
Parse a class that has the FaceletTagHandler annotation

Parameters:
context - the faces context to use when registering JSF items
cls - the class
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

parseComponent

protected void parseComponent(javax.faces.context.FacesContext context,
                              java.lang.Class<?> cls,
                              RegisterPriority defaultPriority)
                       throws FactoryException
Parse a class that has the FaceletComponent annotation

Parameters:
context - the faces context to use when registering JSF items
cls - the class
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory

parseFunctions

protected void parseFunctions(java.lang.Class<?> cls)
                       throws FactoryException
Parse a class for functions

Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory
See Also:
FaceletFunctionHolder, FaceletElFunction

scanClasspath

protected void scanClasspath(javax.faces.context.FacesContext context)
                      throws java.io.IOException,
                             FactoryException
Scan the class path for annotated classes

Parameters:
context - the faces context to use when registering JSF items
Throws:
java.io.IOException - if an IO exception occurs from the file system
FactoryException - if there was an error getting the AnnotationTagLibraryFactory
See Also:
obtainLocationsToScan()

getManifestsToScan

protected java.util.Iterator<java.net.URL> getManifestsToScan()
                                                       throws java.io.IOException
Throws:
java.io.IOException

obtainLocationsToScan

protected java.lang.Iterable<ScanLocationInformation> obtainLocationsToScan()
                                                                     throws java.io.IOException
Obtain the URLs to scan for class files. This is protected to allow sub-classes to override the current behavior of scanning the entire class path for manifest files and then checking the contents of the manifest to check and see if the path should be parsed.

Returns:
the locations to scan
Throws:
java.io.IOException - opening and scanning the jar file errors
See Also:
parseClassesInPath(URL, Manifest)

parseClassesInPath

protected boolean parseClassesInPath(java.net.URL manifestPath,
                                     java.util.jar.Manifest mf)
Checks a manifest to see if the path should be parsed.

If this is not overridden, it checks for an attribute Scan that is equal to true in the named manifest section net/sf/jsf-comp/facelets.

Parameters:
manifestPath - The URL to the manifest file
mf - The manifest file data
Returns:
true if the file should be parsed.

parseRenderer

protected void parseRenderer(javax.faces.context.FacesContext context,
                             java.lang.Class<?> cls,
                             RegisterPriority defaultPriority)
Parse a class that has the FacesRenderer annotation

Parameters:
context - the faces context to use when registering JSF items
cls - the class
defaultPriority - The default priority to use when the annotation is set to RegisterPriority.DEFAULT

getTagLibrary

protected final AnnotationTagLibrary getTagLibrary(java.lang.String ns)
                                            throws FactoryException
Get a tag library. If one doesn't already exist for the given namespace, this method creates one.

Parameters:
ns - the namespace
Returns:
the tag library for the namespace
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory
See Also:
getTagLibraryFactory()

iteratorContains

protected final boolean iteratorContains(java.util.Iterator<?> iter,
                                         java.lang.Object value)
Utility function to see if a value is contained in an iterator


getTagLibraryFactory

protected AnnotationTagLibraryFactory getTagLibraryFactory()
                                                    throws FactoryException
Get an instance of the tag library factory. If not overridden, this method uses DeploymentFinderFactory.createFactory(FactoryType) to obtain the factory that should be used.

Returns:
the factory to use to create tag libraries
Throws:
FactoryException - if there was an error getting the AnnotationTagLibraryFactory
See Also:
DeploymentFinderFactory.createFactory(FactoryType), DeploymentFinderFactory.FactoryType.TAGLIBRARY

getManifestValue

protected final java.lang.String getManifestValue(java.util.jar.Manifest mf,
                                                  java.lang.String namedSection,
                                                  java.lang.String attrName,
                                                  java.lang.String defaultValueIfNotSet)
Get a value from a named section in a manifest

Parameters:
mf - the manifest
namedSection - the section name
attrName - the attribute name
defaultValueIfNotSet - the value to return if the section or attribute were not found
Returns:
the value or the default value

getEffectivePriority

protected final RegisterPriority getEffectivePriority(RegisterPriority value,
                                                      RegisterPriority defaultValue)
Get the effective priority

Parameters:
value - the value from the annotation
defaultValue - the default value from the manifest
Returns:
the priority to use


Copyright © 2007-2008. All Rights Reserved.