KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > code > lib > JavaCode


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: JavaCode.java,v 1.2 2005/07/06 15:36:00 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.core.code.lib;
30
31 import org.objectweb.util.explorer.ExplorerUtils;
32 import org.objectweb.util.explorer.core.code.api.Code;
33 import org.objectweb.util.explorer.core.code.api.CodeConfiguration;
34 import org.objectweb.util.explorer.core.common.lib.ClassResolver;
35 import org.objectweb.util.trace.TraceSystem;
36
37 /**
38  *
39  *
40  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
41  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
42  *
43  * @version 0.1
44  */

45 public class JavaCode
46   implements CodeConfiguration, Code
47 {
48
49     //==================================================================
50
//
51
// Internal States.
52
//
53
// ==================================================================
54

55     /** The class to instanciate. */
56     protected Class JavaDoc theClass_ = null;
57     
58     // ==================================================================
59
//
60
// Constructors.
61
//
62
// ==================================================================
63

64     // ==================================================================
65
//
66
// No internal method.
67
//
68
// ==================================================================
69

70     protected boolean equals(JavaCode code){
71         if(code!=null){
72             Class JavaDoc codeClass = code.theClass_;
73             if(theClass_!=null && codeClass!=null){
74                 return theClass_.getName().equals(codeClass.getName());
75             }
76         }
77         return false;
78     }
79     
80     // ==================================================================
81
//
82
// Public methods for CodeConfiguration interface.
83
//
84
// ==================================================================
85

86     public void setCode(String JavaDoc code) {
87         try {
88             theClass_ = ClassResolver.resolve(code);
89         } catch (ClassNotFoundException JavaDoc e) {
90             TraceSystem.get("explorer").info(code + ": Class not found!");
91         }
92     }
93
94     // ==================================================================
95
//
96
// Public methods for Code interface.
97
//
98
// ==================================================================
99

100     /* (non-Javadoc)
101      * @see org.objectweb.util.explorer.core.code.api.Code#isAssignableFrom(java.lang.Class)
102      */

103     public boolean isInstanceOf(Class JavaDoc c){
104         if(c!=null && theClass_!=null)
105             return c.isAssignableFrom(theClass_);
106         return false;
107     }
108     
109     /* (non-Javadoc)
110      * @see org.objectweb.util.explorer.core.code.api.Code#createInstance()
111      */

112     public Object JavaDoc createInstance() {
113         if(theClass_!=null){
114             try {
115                 return theClass_.newInstance();
116             } catch (InstantiationException JavaDoc e) {
117                 TraceSystem.get("explorer").info(e.getMessage());
118             } catch (IllegalAccessException JavaDoc e) {
119                 TraceSystem.get("explorer").info(e.getMessage());
120             }
121         }
122         return null;
123     }
124
125     // ==================================================================
126
//
127
// Public methods surcharging Object class.
128
//
129
// ==================================================================
130

131     /**
132      * Surcharging the Object.equals method.
133      * @see Object#equals(java.lang.Object)
134      */

135     public boolean equals(Object JavaDoc o){
136         if(o!=null && o instanceof JavaCode){
137             return equals((JavaCode)o);
138         }
139         return false;
140     }
141    
142     /**
143      * Return a String representation of a BasicImageIcon
144      * @see Object#toString()
145      */

146     public String JavaDoc toString(){
147         return "JavaCode[class=" +
148             ExplorerUtils.toString(theClass_) + "]";
149     }
150         
151 }
152
Popular Tags