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 com.sun.mirror.type.InterfaceType;
022:
023: /**
024: * The ControlBean class is an class representing a generated JavaBean class that can host
025: * control implementation types associated with a particular control public or extension
026: * interface.
027: */
028: public class ControlBean {
029: /**
030: * Constructs a new ControlBean class supporting a particular bean interface
031: * @param controlIntf the public interface associated with the bean
032: */
033: protected ControlBean(AptControlInterface controlIntf) {
034: super ();
035: _controlIntf = controlIntf;
036: if (_controlIntf != null) {
037: _packageName = _controlIntf.getPackage();
038: _shortName = _controlIntf.getShortName() + "Bean";
039: _className = isRootPackage() ? _shortName : _packageName
040: + "." + _shortName;
041:
042: _super Class = new ControlBean(_controlIntf.getSuperClass());
043: } else {
044: Class c = org.apache.beehive.controls.runtime.bean.ControlBean.class;
045: _packageName = c.getPackage().getName();
046: _className = c.getName();
047: _shortName = _className
048: .substring(_packageName.length() + 1);
049: }
050: }
051:
052: /**
053: * Return whether the ControlBean is contained in a package.
054: */
055: public boolean isRootPackage() {
056: return _packageName == null || _packageName.trim().equals("");
057: }
058:
059: /**
060: * Returns the fully qualified package name of the ControlBean
061: */
062: public String getPackage() {
063: return _packageName;
064: }
065:
066: /**
067: * Returns the unqualified classname of the ControlBean
068: */
069: public String getShortName() {
070: return _shortName;
071: }
072:
073: /**
074: * Returns the fully qualified classname of the ControlBean
075: */
076: public String getClassName() {
077: return _className;
078: }
079:
080: /**
081: * Returns the class declaration for the ControlBean
082: */
083: public String getClassDeclaration() {
084: StringBuffer sb = new StringBuffer(_shortName);
085: sb.append(_controlIntf.getFormalTypeParameters());
086: return sb.toString();
087: }
088:
089: /**
090: * Returns the fully qualified classname of the ControlBean BeanInfo class. The
091: * standard JavaBean naming convention is used to enable automatic location by
092: * the JavaBean introspector.
093: */
094: public String getBeanInfoName() {
095: return _className + "BeanInfo";
096: }
097:
098: /**
099: * Returns the class as a Jar Manifest Name attribute
100: */
101: public String getManifestName() {
102: return _className.replace('.', '/') + ".class";
103: }
104:
105: /**
106: * Returns the public or extension interface associated with the ControlBean
107: */
108: public AptControlInterface getControlInterface() {
109: return _controlIntf;
110: }
111:
112: /**
113: * Returns the super class for this ControlBean
114: */
115: public ControlBean getSuperClass() {
116: return _super Class;
117: }
118:
119: /**
120: * Returns any formal type parameters that should be bound for the bean's superclass,
121: * based upon any type bindings that occur on the original interface.
122: */
123: public String getSuperTypeBinding() {
124: InterfaceType super Type = _controlIntf.getSuperType();
125: if (super Type != null) {
126: String typeStr = super Type.toString();
127: int paramIndex = typeStr.indexOf('<');
128: if (paramIndex > 0)
129: return typeStr.substring(paramIndex);
130: }
131: return "";
132: }
133:
134: String _packageName;
135: String _shortName;
136: String _className;
137: AptControlInterface _controlIntf;
138: ControlBean _superClass;
139: }
|