org.wicketstuff.annotation.scan
Class AnnotatedMountScanner

java.lang.Object
  extended by org.wicketstuff.annotation.scan.AnnotatedMountScanner

public class AnnotatedMountScanner
extends Object

Looks for mount information by scanning for classes annotated with MountPath. You can specify a package to scan (e.g., "org.mycompany.wicket.pages"). Wildcards also work (e.g., "org.mycompany.*.pages" or "org.mycompany.**.pages").

You can also go more advanced, using any pattern supported by MatchingResources. For example, the first package example above is turned into "classpath*:/org/mycompany/wicket/pages/**/*.class".

For each class that is annotated, an appropriate IRequestTargetUrlCodingStrategy implementing class is created using the information in the MountPath annotation and any supplemental annotations. Each instance is added to the list to return. Each item in the returned list can then be mounted.

Typical usage is in your Application.init() method and utilizes the AnnotatedMountList.mount(org.apache.wicket.protocol.http.WebApplication) convenience method.

  protected void init()
  {
      new AnnotatedMountScanner().scanPackage("org.mycompany.wicket.pages").mount(this);
  }
 

You could scan the entire classpath if you wanted by passing in null, but that might require more time to run than limiting it to known packages which have annotated classes.

Page classes annotation usage is as follows:

  @MountPath(path = "hello")
  private class HelloPage extends Page
  {
  }

  @MountPath(path = "dogs", alt = {"canines", "k9s"})
  @MountMixedParam(parameterNames = {"dexter", "zorro"})
  private class DogsPage extends Page
  {
  }
 

The first example will mount HelloPage to /hello using the default encoding strategy (as returned by getDefaultStrategy(java.lang.String, java.lang.Class) which is BookmarkablePageRequestTargetUrlCodingStrategy.

The second example will mount DogsPage at "/dogs" (as the primary) and as "/canines" and "/k9s" as alternates using the MixedParamUrlCodingStrategy. Further, the second example specifies that {"dexter", "zorro"} String array is to be passed to the constructor. The value for the pageMapName argument is null.

Author:
Doug Donohoe

Constructor Summary
AnnotatedMountScanner()
           
 
Method Summary
 org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy getDefaultStrategy(String mountPath, Class<? extends org.apache.wicket.Page> pageClass)
          Returns the default coding strategy given a mount path and class.
 List<Class<?>> getPackageMatches(String pattern)
          Scan given a package name or part of a package name and return list of classes with MountPath annotation.
 String getPatternForPackage(String packageName)
          Get the Spring search pattern given a package name or part of a package name
 List<Class<?>> getPatternMatches(String pattern)
          Scan given a Spring search pattern and return list of classes with MountPath annotation.
 AnnotatedMountList scanClass(Class<? extends org.apache.wicket.Page> pageClass)
          Scan given a class that is a sublass of Page.
protected  AnnotatedMountList scanList(List<Class<?>> mounts)
          Scan a list of classes which are annotated with MountPath
 AnnotatedMountList scanPackage(String packageName)
          Scan given package name or part of a package name
 AnnotatedMountList scanPattern(String pattern)
          Scan given a Spring search pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotatedMountScanner

public AnnotatedMountScanner()
Method Detail

getPatternForPackage

public String getPatternForPackage(String packageName)
Get the Spring search pattern given a package name or part of a package name

Parameters:
packageName - a package name
Returns:
a Spring search pattern for the given package

getPackageMatches

public List<Class<?>> getPackageMatches(String pattern)
Scan given a package name or part of a package name and return list of classes with MountPath annotation.

Returns:
A List of classes annotated with @MountPath

getPatternMatches

public List<Class<?>> getPatternMatches(String pattern)
Scan given a Spring search pattern and return list of classes with MountPath annotation.

Returns:
A List of classes annotated with @MountPath

scanPackage

public AnnotatedMountList scanPackage(String packageName)
Scan given package name or part of a package name

Parameters:
packageName - a package to scan (e.g., "org.mycompany.pages)
Returns:
An AnnotatedMountList

scanPattern

public AnnotatedMountList scanPattern(String pattern)
Scan given a Spring search pattern.

Parameters:
pattern -
Returns:
An AnnotatedMountList

scanList

protected AnnotatedMountList scanList(List<Class<?>> mounts)
Scan a list of classes which are annotated with MountPath

Parameters:
mounts -
Returns:
An AnnotatedMountList

scanClass

public AnnotatedMountList scanClass(Class<? extends org.apache.wicket.Page> pageClass)
Scan given a class that is a sublass of Page.

Parameters:
pageClass - Page subclass to scan
Returns:
An AnnotatedMountList containing the primary and alternate strategies created for the class.

getDefaultStrategy

public org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy getDefaultStrategy(String mountPath,
                                                                                                  Class<? extends org.apache.wicket.Page> pageClass)
Returns the default coding strategy given a mount path and class.

Parameters:
mountPath -
pageClass -
Returns:
BookmarkablePageRequestTargetUrlCodingStrategy


Copyright © 2012. All Rights Reserved.