KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Field JavaDoc;
21 import java.util.ArrayList JavaDoc;
22
23 /**
24  * The ClientInitializer represents a generated class that contains the code
25  * necessary to initialize a client that uses controls declaratively (via Control and
26  * EventHandler annotations).
27  */

28 public class ClientInitializer
29 {
30     /**
31      * Constructs a new ClientInitializer class
32      * @param controlClient the control client this initializer will target
33      */

34     protected ClientInitializer(AptControlClient controlClient)
35     {
36         super();
37
38         assert controlClient != null;
39
40         _controlClient = controlClient;
41         _packageName = _controlClient.getPackage();
42         _shortName = _controlClient.getShortName() + "ClientInitializer";
43         _className = isRootPackage() ? _shortName : _packageName + "." + _shortName;
44
45         //
46
// Compute the list of impl fields that will require reflected Fields. This is
47
// done unconditionally for all @Control fields (to support PropertyMap initialization)
48
//
49

50         _reflectFields = new ArrayList JavaDoc<AptField>();
51         for (AptField genField : _controlClient.getControls())
52             _reflectFields.add(genField);
53     }
54
55     /**
56      * Returns the package name of the ClientInitializer
57      */

58     public String JavaDoc getPackage() { return _packageName; }
59
60     /**
61      * Is the ClientInitializer in the root package?
62      */

63     public boolean isRootPackage() { return getPackage().equals(""); }
64
65     /**
66      * Returns the unqualified classname of the ClientInitializer
67      */

68     public String JavaDoc getShortName() { return _shortName; }
69
70     /**
71      * Returns the fully qualfied classname of the ClientInitializer
72      */

73     public String JavaDoc getClassName() { return _className; }
74
75     /**
76      * Returns the ControlBean implementation instance
77      */

78     public AptControlClient getControlClient() { return _controlClient; }
79
80     public ClientInitializer getSuperClass() { return null; }
81
82     /**
83      * Returns true if the initializer will use Reflection to initialize the field, false
84      * otherwise.
85      */

86     static public boolean needsReflection(AptField genField)
87     {
88         //
89
// Since initializers are generated into the same package as the initialized class,
90
// only private access fields require reflection
91
//
92
String JavaDoc accessModifier = genField.getAccessModifier();
93         if (accessModifier.equals("private"))
94             return true;
95
96         return false;
97     }
98
99     /**
100      * Returns the list of impl class fields that must be initialized using Reflection
101      */

102     public ArrayList JavaDoc<AptField> getReflectFields()
103     {
104         return _reflectFields;
105     }
106
107     String JavaDoc _packageName;
108     String JavaDoc _shortName;
109     String JavaDoc _className;
110     AptControlClient _controlClient;
111     ArrayList JavaDoc<AptField> _reflectFields;
112 }
113
Popular Tags