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 ClientInitializer represents a generated class that contains the code
025: * necessary to initialize a client that uses controls declaratively (via Control and
026: * EventHandler annotations).
027: */
028: public class ClientInitializer {
029: /**
030: * Constructs a new ClientInitializer class
031: * @param controlClient the control client this initializer will target
032: */
033: protected ClientInitializer(AptControlClient controlClient) {
034: super ();
035:
036: assert controlClient != null;
037:
038: _controlClient = controlClient;
039: _packageName = _controlClient.getPackage();
040: _shortName = _controlClient.getShortName()
041: + "ClientInitializer";
042: _className = isRootPackage() ? _shortName : _packageName + "."
043: + _shortName;
044:
045: //
046: // Compute the list of impl fields that will require reflected Fields. This is
047: // done unconditionally for all @Control fields (to support PropertyMap initialization)
048: //
049:
050: _reflectFields = new ArrayList<AptField>();
051: for (AptField genField : _controlClient.getControls())
052: _reflectFields.add(genField);
053: }
054:
055: /**
056: * Returns the package name of the ClientInitializer
057: */
058: public String getPackage() {
059: return _packageName;
060: }
061:
062: /**
063: * Is the ClientInitializer in the root package?
064: */
065: public boolean isRootPackage() {
066: return getPackage() == null || getPackage().equals("");
067: }
068:
069: /**
070: * Returns the unqualified classname of the ClientInitializer
071: */
072: public String getShortName() {
073: return _shortName;
074: }
075:
076: /**
077: * Returns the fully qualfied classname of the ClientInitializer
078: */
079: public String getClassName() {
080: return _className;
081: }
082:
083: /**
084: * Returns the ControlBean implementation instance
085: */
086: public AptControlClient getControlClient() {
087: return _controlClient;
088: }
089:
090: public ClientInitializer getSuperClass() {
091: return null;
092: }
093:
094: /**
095: * Returns true if the initializer will use Reflection to initialize the field, false
096: * otherwise.
097: */
098: static public boolean needsReflection(AptField genField) {
099: //
100: // Since initializers are generated into the same package as the initialized class,
101: // only private access fields require reflection
102: //
103: String accessModifier = genField.getAccessModifier();
104: if (accessModifier.equals("private"))
105: return true;
106:
107: return false;
108: }
109:
110: /**
111: * Returns the list of impl class fields that must be initialized using Reflection
112: */
113: public ArrayList<AptField> getReflectFields() {
114: return _reflectFields;
115: }
116:
117: String _packageName;
118: String _shortName;
119: String _className;
120: AptControlClient _controlClient;
121: ArrayList<AptField> _reflectFields;
122: }
|