[jboss-cvs] JBossAS SVN: r93216 - projects/annotations/trunk/doc/userguide/en/modules.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 4 14:05:38 EDT 2009


Author: jesper.pedersen
Date: 2009-09-04 14:05:37 -0400 (Fri, 04 Sep 2009)
New Revision: 93216

Modified:
   projects/annotations/trunk/doc/userguide/en/modules/usage.xml
Log:
[JBANN-30] Add an advanced usage scenario

Modified: projects/annotations/trunk/doc/userguide/en/modules/usage.xml
===================================================================
--- projects/annotations/trunk/doc/userguide/en/modules/usage.xml	2009-09-04 17:18:23 UTC (rev 93215)
+++ projects/annotations/trunk/doc/userguide/en/modules/usage.xml	2009-09-04 18:05:37 UTC (rev 93216)
@@ -50,5 +50,53 @@
 
    </section>
 
+   <section id="advanvedusage">
+      <title>Advanced usage</title>
 
+      <para>The code below shows a more advanced usage of the Papaki project.</para>
+
+     <programlisting>
+import org.jboss.papaki.Annotation;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.papaki.AnnotationScannerFactory;
+import org.jboss.papaki.AnnotationType;
+import org.jboss.papaki.Visibility;
+
+
+// Create an annotation scanner instance using the Javassist InputStream strategy
+AnnotationScanner as = 
+   AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVASSIST_INPUT_STREAM);
+
+// Configure it to scan for 
+// 1) No parameter level annotations
+// 2) Only public classes
+
+as.configure().parameterLevel(false).classVisibility(Visibility.PUBLIC); 
+
+// URLs which points to .jar files
+URL[] urls = ...;
+
+// Scan the urls
+AnnotationRepository ar = as.scan(urls);
+
+// Query the repository for an annotation and receive a list of instances
+Collection&lt;Annotation&gt; l = ar.getAnnotation(MyAnnotation.class);
+
+// Use each annotation
+if (l != null)
+{
+  for (Annotation annotation : l)
+  {
+    MyAnnotation myAnnotation = (MyAnnotation)annotation.getAnnotation();
+    AnnotationType annotationType = annotation.getType();
+    String locatedOn = annotation.getClassName();
+    ...
+  }
+}
+     </programlisting>
+
+   </section>
+
+
 </chapter>




More information about the jboss-cvs-commits mailing list