KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > moduleloader > search > SelfContainedSearchPolicy


1 /*
2  * ModuleLoader - A generic, policy-driven class loader.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.moduleloader.search;
37
38 import java.net.URL JavaDoc;
39
40 import org.ungoverned.moduleloader.Module;
41 import org.ungoverned.moduleloader.ModuleManager;
42 import org.ungoverned.moduleloader.SearchPolicy;
43
44 /**
45  * <p>
46  * This class implements a <tt>ModuleLoader</tt> search policy that
47  * assumes that all modules are self-contained. In other words, when
48  * loading a class or resource for a particular module, only that
49  * particular module's resource sources are search. No classes or
50  * resources are shared among modules.
51  * </p>
52  * @see org.ungoverned.moduleloader.SearchPolicy
53  * @see org.ungoverned.moduleloader.Module
54  * @see org.ungoverned.moduleloader.ModuleClassLoader
55  * @see org.ungoverned.moduleloader.ModuleManager
56 **/

57 public class SelfContainedSearchPolicy implements SearchPolicy
58 {
59     private ModuleManager m_mgr = null;
60
61     /**
62      * This method is part of the <tt>SearchPolicy</tt> interface.
63      * This method is called by the <tt>ModuleManager</tt> once to
64      * give the search policy instance a reference to its associated
65      * module manager. This method should be implemented such that
66      * it cannot be called twice; calling this method a second time
67      * should produce an illegal state exception.
68      * @param mgr the module manager associated with this search policy.
69      * @throws java.lang.IllegalStateException if the method is called
70      * more than once.
71     **/

72     public void setModuleManager(ModuleManager mgr)
73         throws IllegalStateException JavaDoc
74     {
75         if (m_mgr == null)
76         {
77             m_mgr = mgr;
78         }
79         else
80         {
81             throw new IllegalStateException JavaDoc("Module manager is already initialized");
82         }
83     }
84
85     /**
86      * Simply returns <tt>null</tt> which forces the module class
87      * loader to only search the target module's resource sources
88      * for the specified class.
89      * @param module the target module that is loading the class.
90      * @param name the name of the class being loaded.
91      * @return <tt>null</tt>.
92     **/

93     public Class JavaDoc findClass(Module module, String JavaDoc name)
94     {
95         return null;
96     }
97
98     /**
99      * Simply returns <tt>null</tt> which forces the module class
100      * loader to only search the target module's resource sources
101      * for the specified resource.
102      * @param module the target module that is loading the class.
103      * @param name the name of the resource being loaded.
104      * @return <tt>null</tt>.
105     **/

106     public URL JavaDoc findResource(Module module, String JavaDoc name)
107     {
108         return null;
109     }
110 }
Popular Tags