001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.controls.runtime.generator;
020:
021: import java.util.ArrayList;
022:
023: /**
024: * The ImplInitializer class is a generated class that contains the code necessary to initialize
025: * a ControlBean implementation instance.
026: */
027: public class ImplInitializer {
028: /**
029: * Constructs a new ImplInitializer class supporting a particular control bean implementation
030: * @param controlImpl the control implementation to be initialized
031: */
032: protected ImplInitializer(AptControlImplementation controlImpl) {
033: super ();
034: _controlImpl = controlImpl;
035: _controlIntf = _controlImpl.getControlInterface();
036: if (_controlImpl != null) {
037: _packageName = _controlImpl.getPackage();
038: _shortName = _controlImpl.getShortName() + "Initializer";
039: _className = _packageName + "." + _shortName;
040: if (_controlImpl.getSuperClass() != null)
041: _super Class = new ImplInitializer(_controlImpl
042: .getSuperClass());
043: } else {
044: Class c = org.apache.beehive.controls.runtime.bean.ImplInitializer.class;
045: _packageName = c.getPackage().getName();
046: _className = c.getName();
047: _shortName = _className
048: .substring(_packageName.length() + 1);
049: }
050:
051: //
052: // Compute the list of impl fields that will require reflected Fields.
053: //
054: _reflectFields = new ArrayList<AptField>();
055: for (AptField genField : _controlImpl.getContexts())
056: if (needsReflection(genField))
057: _reflectFields.add(genField);
058: for (AptField genField : _controlImpl.getClients())
059: if (needsReflection(genField))
060: _reflectFields.add(genField);
061: }
062:
063: /*
064: * Return whether the ControlBean is contained in a package.
065: */
066: public boolean isRootPackage() {
067: return _packageName == null || _packageName.trim().equals("");
068: }
069:
070: /**
071: * Returns the package name of the ImplInitializer
072: */
073: public String getPackage() {
074: return _packageName;
075: }
076:
077: /**
078: * Returns the unqualified classname of the ImplInitializer
079: */
080: public String getShortName() {
081: return _shortName;
082: }
083:
084: /**
085: * Returns the fully qualfied classname of the ImplInitializer
086: */
087: public String getClassName() {
088: return _className;
089: }
090:
091: /**
092: * Returns the fully qualified classname of any associated ClientInitializer
093: */
094: public String getClientInitializerName() {
095: return _controlImpl.getClassName() + "ClientInitializer";
096: }
097:
098: /**
099: * Returns the ControlBean implementation instance
100: */
101: public AptControlImplementation getControlImplementation() {
102: return _controlImpl;
103: }
104:
105: /**
106: * Returns the public or extension interface associated with the ControlBean implementation
107: */
108: public AptControlInterface getControlInterface() {
109: return _controlIntf;
110: }
111:
112: /**
113: * Returns the ImplInitializer super class for this ImplInitializer
114: */
115: public ImplInitializer getSuperClass() {
116: return _super Class;
117: }
118:
119: /**
120: * Returns true if the ImplInitializer has a super class
121: */
122: public boolean hasSuperClass() {
123: return _super Class != null;
124: }
125:
126: /**
127: * Returns true if the initializer will use Reflection to initialize the field, false
128: * otherwise.
129: */
130: static public boolean needsReflection(AptField genField) {
131: //
132: // Since initializers are generated into the same package as the initialized class,
133: // only private access fields require reflection
134: //
135: String accessModifier = genField.getAccessModifier();
136: if (accessModifier.equals("private"))
137: return true;
138:
139: return false;
140: }
141:
142: /**
143: * Returns the list of impl class fields that must be initialized using Reflection
144: */
145: public ArrayList<AptField> getReflectFields() {
146: return _reflectFields;
147: }
148:
149: String _packageName;
150: String _shortName;
151: String _className;
152: AptControlImplementation _controlImpl;
153: AptControlInterface _controlIntf;
154: ImplInitializer _super Class;
155: ArrayList<AptField> _reflectFields;
156: }
|