KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > ImplInitializer


1 package org.apache.beehive.controls.runtime.generator;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.util.ArrayList JavaDoc;
21
22 /**
23  * The ImplInitializer class is a generated class that contains the code necessary to initialize
24  * a ControlBean implementation instance.
25  */

26 public class ImplInitializer
27 {
28     /**
29      * Constructs a new ImplInitializer class supporting a particular control bean implementation
30      * @param controlImpl the control implementation to be initialized
31      */

32     protected ImplInitializer(AptControlImplementation controlImpl)
33     {
34         super();
35         _controlImpl = controlImpl;
36         _controlIntf = _controlImpl.getControlInterface();
37         if (_controlImpl != null)
38         {
39             _packageName = _controlImpl.getPackage();
40             _shortName = _controlImpl.getShortName() + "Initializer";
41             _className = _packageName + "." + _shortName;
42             if (_controlImpl.getSuperClass() != null)
43                 _superClass = new ImplInitializer(_controlImpl.getSuperClass());
44         }
45         else
46         {
47             Class JavaDoc c = org.apache.beehive.controls.runtime.bean.ImplInitializer.class;
48             _packageName = c.getPackage().getName();
49             _className = c.getName();
50             _shortName = _className.substring(_packageName.length() + 1);
51         }
52
53         //
54
// Compute the list of impl fields that will require reflected Fields.
55
//
56
_reflectFields = new ArrayList JavaDoc<AptField>();
57         for (AptField genField : _controlImpl.getContexts())
58             if (needsReflection(genField))
59                 _reflectFields.add(genField);
60         for (AptField genField : _controlImpl.getClients())
61             if (needsReflection(genField))
62                 _reflectFields.add(genField);
63     }
64
65     /**
66      * Returns the package name of the ImplInitializer
67      */

68     public String JavaDoc getPackage() { return _packageName; }
69
70     /**
71      * Returns the unqualified classname of the ImplInitializer
72      */

73     public String JavaDoc getShortName() { return _shortName; }
74
75     /**
76      * Returns the fully qualfied classname of the ImplInitializer
77      */

78     public String JavaDoc getClassName() { return _className; }
79
80     /**
81      * Returns the fully qualified classname of any associated ClientInitializer
82      */

83     public String JavaDoc getClientInitializerName()
84     {
85         return _controlImpl.getClassName() + "ClientInitializer";
86     }
87
88     /**
89      * Returns the ControlBean implementation instance
90      */

91     public AptControlImplementation getControlImplementation() { return _controlImpl; }
92
93     /**
94      * Returns the public or extension interface associated with the ControlBean implementation
95      */

96     public AptControlInterface getControlInterface() { return _controlIntf; }
97
98     /**
99      * Returns the ImplInitializer super class for this ImplInitializer
100      */

101     public ImplInitializer getSuperClass() { return _superClass; }
102
103     /**
104      * Returns true if the ImplInitializer has a super class
105      */

106     public boolean hasSuperClass() { return _superClass != null; }
107
108     /**
109      * Returns true if the initializer will use Reflection to initialize the field, false
110      * otherwise.
111      */

112     static public boolean needsReflection(AptField genField)
113     {
114         //
115
// Since initializers are generated into the same package as the initialized class,
116
// only private access fields require reflection
117
//
118
String JavaDoc accessModifier = genField.getAccessModifier();
119         if (accessModifier.equals("private"))
120             return true;
121
122         return false;
123     }
124
125     /**
126      * Returns the list of impl class fields that must be initialized using Reflection
127      */

128     public ArrayList JavaDoc<AptField> getReflectFields()
129     {
130         return _reflectFields;
131     }
132
133     String JavaDoc _packageName;
134     String JavaDoc _shortName;
135     String JavaDoc _className;
136     AptControlImplementation _controlImpl;
137     AptControlInterface _controlIntf;
138     ImplInitializer _superClass;
139     ArrayList JavaDoc<AptField> _reflectFields;
140 }
141
Popular Tags