<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<document>

 <properties>
  <title>Commons ClassScan - User guide</title>
  <author email="dev@commons.apache.org">Commons Documentation Team</author>
 </properties>

 <body>


  <section name="Description">
   <p>This library provides methods to search for classes without using reflection, in fact, without even loading the classes.  This is particularly important when the class has
   static initializers that cause behavior that cannot be undone.  Additionally, framework libraries don't always have apriori knowledge of all classes which must be managed.</p>
  </section>

   <section name="Find All Implementors of an Interface">
<p>You can use the following code snippet to find all implementors of an interface.</p>
   <source><![CDATA[
        MetaClassLoader classLoader = MetaRegistry.SINGLETON.getClassLoader(getClass().getClassLoader());
        Collection<? extends MetaClass> implementations = classLoader.findAllImplementors(FullInterface.class.getCanonicalName());
]]></source>
   </section>

   <section name="Find All Classes in a jar with a Annotation">
<p>You can use the following code snippets to find all classes with a particular annotation in a jar with a marker META-INF file.</p>
   <source><![CDATA[    
    public void findAnnotatedClassesFromJar(MetaClassLoader classLoader) {
        for(MetaClassLocation location : classLoader.getClassLocationsWithMetaFile("persistence.xml")) {
            findAnnotatedClassesFromLocation(location);
        }
    }

    private void findAnnotatedClassesFromLocation(MetaClassLocation location) {
        for(MetaClass mc : location.getMetaClasses()) {
            MetaAnnotation ma = mc.getAnnotation("javax.persistence.Entity");
            if(ma!=null) {
                workOnClass(mc);
            }
        }
    }
]]></source>
   </section>
   
   
</body>
</document>
