001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * ClassElem.java
044: *
045: * Created on January 23, 2007, 2:50 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.test.umllib.project.elem.impl;
052:
053: import java.util.LinkedList;
054: import java.util.List;
055: import org.netbeans.test.umllib.project.elem.ElemType;
056: import org.netbeans.test.umllib.project.elem.IAttributeElem;
057: import org.netbeans.test.umllib.project.elem.IClassElem;
058: import org.netbeans.test.umllib.project.elem.IInterfaceElem;
059: import org.netbeans.test.umllib.project.elem.IJavaElem;
060: import org.netbeans.test.umllib.project.elem.IOperationElem;
061: import org.netbeans.test.umllib.project.elem.IPackageElem;
062:
063: /**
064: *
065: * @author andromeda
066: */
067:
068: public abstract class JavaElem implements IJavaElem {
069:
070: String name;
071: IPackageElem pack;
072:
073: IJavaElem parentElem;
074:
075: List<IInterfaceElem> super InterfaceList = new LinkedList<IInterfaceElem>();
076: List<IJavaElem> templateParameterList = new LinkedList<IJavaElem>();
077:
078: List<IAttributeElem> attributeList = new LinkedList<IAttributeElem>();
079: List<IOperationElem> operationList = new LinkedList<IOperationElem>();
080:
081: List<IJavaElem> nestedElemList = new NestedElemList();
082:
083: /** Creates a new instance of ClassElem */
084: public JavaElem(String name) {
085: this (name, PackageElem.ROOT_PACKAGE_ELEM);
086: }
087:
088: public JavaElem(String name, IPackageElem pack) {
089: this .name = name;
090: this .pack = pack;
091: }
092:
093: public String getName() {
094: return name;
095: }
096:
097: public List<IInterfaceElem> getSuperInterfaceList() {
098: return super InterfaceList;
099: }
100:
101: public IPackageElem getPackage() {
102: return pack;
103: }
104:
105: public String getFullName() {
106:
107: if (parentElem == null) {
108: return PackageElem.getFullName(getPackage(), getName());
109:
110: } else {
111: return parentElem.getFullName() + "$" + getName();
112: }
113:
114: }
115:
116: public List<IJavaElem> getTemplateParameterList() {
117: return templateParameterList;
118: }
119:
120: public List<IAttributeElem> getAttributeList() {
121: return attributeList;
122: }
123:
124: public List<IOperationElem> getOperationList() {
125: return operationList;
126: }
127:
128: public List<IJavaElem> getNestedElemList() {
129: return nestedElemList;
130: }
131:
132: public IJavaElem getParentElem() {
133: return parentElem;
134: }
135:
136: public void setParentElem(IJavaElem parentElem) {
137: this .parentElem = parentElem;
138: }
139:
140: class NestedElemList extends LinkedList<IJavaElem> {
141: public boolean add(IJavaElem elem) {
142: elem.setParentElem(JavaElem.this );
143: return NestedElemList.super .add(elem);
144: }
145:
146: }
147:
148: public static String getGenericSignatureName(IJavaElem javaElem) {
149:
150: String str = "";
151: str += javaElem.getName();
152:
153: List<IJavaElem> templateParamList = javaElem
154: .getTemplateParameterList();
155:
156: if (templateParamList.size() != 0) {
157: str += "<";
158:
159: str += templateParamList.get(0).getName();
160:
161: for (int i = 1; i < templateParamList.size(); i++) {
162: str += ", " + templateParamList.get(i).getName();
163: }
164: str += ">";
165:
166: }
167:
168: return str;
169: }
170:
171: public String getSignature() {
172: String signature = "";
173:
174: switch (getType()) {
175:
176: case CLASS:
177: signature += "class";
178: break;
179: case INTERFACE:
180: signature += "interface";
181: break;
182: case ENUMERATION:
183: signature += "enum";
184: break;
185:
186: default:
187: }
188:
189: signature += " " + getGenericSignatureName(this);
190:
191: return signature;
192:
193: }
194: }
|