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: * File : ChangeUtils.java
044: * Version : 1.1
045: * Description : Utility methods and constants for Describe model-source
046: * roundtrip.
047: * Author : Darshan
048: */
049: package org.netbeans.modules.uml.integration.ide;
050:
051: import java.lang.reflect.Modifier;
052: import java.util.Arrays;
053:
054: import org.netbeans.modules.uml.integration.ide.events.MethodParameterInfo;
055: import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
056: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
057: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
058: import org.netbeans.modules.uml.core.metamodel.core.foundation.IRelationProxy;
059: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociation;
060: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociationEnd;
061: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAttribute;
062: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
063: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IGeneralization;
064: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IImplementation;
065: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IInterface;
066: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
067: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IParameter;
068: import org.netbeans.modules.uml.core.roundtripframework.IChangeRequest;
069: import org.netbeans.modules.uml.core.roundtripframework.IParameterChangeRequest;
070: import org.netbeans.modules.uml.core.support.umlsupport.Log;
071: import org.netbeans.modules.uml.core.support.umlutils.ETList;
072:
073: /**
074: * Utility methods and constants for Describe model-source roundtrip.
075: *
076: * Revision History
077: * No. Date Who What
078: * --- ---- --- ----
079: * 1 2002-04-23 Darshan Created
080: * 2 2002-04-25 Darshan Changed method parameter display to include
081: * parameter #0.
082: * 3 2002-05-03 Sumitabh Tweaked to display request type, element type,
083: * method parameters and return type correctly.
084: * 4 2002-05-03 Darshan Made changes to match the new Wolverine
085: * event model.
086: * 5 2002-05-06 Darshan Added constants and string arrays to identify
087: * roundtrip change types. Updated the display
088: * for class and interface roundtrip events.
089: * 6 2002-05-22 Darshan Changed attribute type display from
090: * getType().getName() to getTypeName().
091: * 7 2002-05-29 Darshan Added constant for implementation relationships.
092: * 8 2002-05-30 Darshan Fixed bug in printing interfaces implemented
093: * by a class.
094: * 9 2002-06-05 Darshan Commented out code to display the request type,
095: * since the request types change frequently,
096: * causing ArrayIndexOutOfBoundsExceptions when
097: * indexing into reqDetailEnum[].
098: * 10 2002-06-18 Darshan Updated RequestDetailType enum.
099: *
100: * @author Darshan
101: * @version 1.1
102: */
103: public class ChangeUtils {
104: // Constants that indicate the nature of a model-source change.
105: public static final short CT_MODIFY = 0;
106: public static final short CT_DELETE = 1;
107: public static final short CT_CREATE = 2;
108:
109: static final String[] changeTypes = new String[] { "CT_MODIFY",
110: "CT_DELETE", "CT_CREATE", };
111:
112: public static final int RDT_NONE = 0;
113: public static final int RDT_DOCUMENTATION_MODIFIED = 1;
114: public static final int RDT_ELEMENT_DELETED = 2;
115: public static final int RDT_NAME_MODIFIED = 3;
116: public static final int RDT_VISIBILITY_MODIFIED = 4;
117: public static final int RDT_ELEMENT_ADDED_TO_NAMESPACE = 5;
118: public static final int RDT_RELATION_VALIDATE = 6;
119: public static final int RDT_RELATION_MODIFIED = 7;
120: public static final int RDT_RELATION_DELETED = 8;
121: public static final int RDT_ATTRIBUTE_DEFAULT_MODIFIED = 9;
122: public static final int RDT_ATTRIBUTE_DEFAULT_BODY_MODIFIED = 10;
123: public static final int RDT_ATTRIBUTE_DEFAULT_LANGUAGE_MODIFIED = 11;
124: public static final int RDT_CONCURRENCY_MODIFIED = 12;
125: public static final int RDT_SIGNAL_ADDED = 13;
126: public static final int RDT_SIGNAL_REMOVED = 14;
127: public static final int RDT_PARAMETER_ADDED = 15;
128: public static final int RDT_PARAMETER_REMOVED = 16;
129: public static final int RDT_ABSTRACT_MODIFIED = 17;
130: public static final int RDT_FEATURE_ADDED = 18;
131: public static final int RDT_FEATURE_REMOVED = 19;
132: public static final int RDT_STATIC_MODIFIED = 20;
133: public static final int RDT_CONDITION_ADDED = 21;
134: public static final int RDT_CONDITION_REMOVED = 22;
135: public static final int RDT_QUERY_MODIFIED = 23;
136: public static final int RDT_PARAMETER_DEFAULT_MODIFIED = 24;
137: public static final int RDT_PARAMETER_DEFAULT_BODY_MODIFIED = 25;
138: public static final int RDT_PARAMETER_DEFAULT_LANGUAGE_MODIFIED = 26;
139: public static final int RDT_PARAMETER_DIRECTION_MODIFIED = 27;
140: public static final int RDT_CHANGEABILITY_MODIFIED = 28;
141: public static final int RDT_MULTIPLICITY_MODIFIED = 29;
142: public static final int RDT_TYPE_MODIFIED = 30;
143: public static final int RDT_LOWER_MODIFIED = 31;
144: public static final int RDT_UPPER_MODIFIED = 32;
145: public static final int RDT_RANGE_ADDED = 33;
146: public static final int RDT_RANGE_REMOVED = 34;
147: public static final int RDT_ORDER_MODIFIED = 35;
148: public static final int RDT_PACKAGE_NAME_MODIFIED = 36;
149: public static final int RDT_TRANSIENT_MODIFIED = 37;
150: public static final int RDT_NATIVE_MODIFIED = 38;
151: public static final int RDT_VOLATILE_MODIFIED = 39;
152: public static final int RDT_LEAF_MODIFIED = 40;
153: public static final int RDT_RELATION_END_MODIFIED = 41;
154: public static final int RDT_RELATION_END_ADDED = 42;
155: public static final int RDT_RELATION_END_REMOVED = 43;
156: public static final int RDT_DEPENDENCY_ADDED = 44;
157: public static final int RDT_DEPENDENCY_REMOVED = 45;
158: public static final int RDT_ASSOCIATION_END_MODIFIED = 46;
159: public static final int RDT_ASSOCIATION_END_ADDED = 47;
160: public static final int RDT_ASSOCIATION_END_REMOVED = 48;
161: public static final int RDT_RELATION_CREATED = 49;
162: public static final int RDT_FEATURE_MOVED = 50;
163: public static final int RDT_FEATURE_DUPLICATED = 51;
164: public static final int RDT_NAMESPACE_MODIFIED = 52;
165: public static final int RDT_CHANGED_NAMESPACE = 53;
166: public static final int RDT_NAMESPACE_MOVED = 54;
167: public static final int RDT_FINAL_MODIFIED = 55;
168: public static final int RDT_STRICTFP_MODIFIED = 56;
169: public static final int RDT_MULTIPLE_PARAMETER_TYPE_MODIFIED = 57;
170: public static final int RDT_TRANSFORM = 58;
171: public static final int RDT_EXCEPTION_ADDED = 59;
172: public static final int RDT_EXCEPTION_REMOVED = 60;
173: public static final int RDT_SIGNATURE_CHANGED = 61;
174: public static final int RDT_SOURCE_DIR_CHANGED = 62;
175:
176: static final String[] reqDetailEnum = new String[] { "RDT_NONE",
177: "RDT_DOCUMENTATION_MODIFIED", "RDT_ELEMENT_DELETED",
178: "RDT_NAME_MODIFIED", "RDT_VISIBILITY_MODIFIED",
179: "RDT_ELEMENT_ADDED_TO_NAMESPACE", "RDT_RELATION_VALIDATE",
180: "RDT_RELATION_MODIFIED", "RDT_RELATION_DELETED",
181: "RDT_ATTRIBUTE_DEFAULT_MODIFIED",
182: "RDT_ATTRIBUTE_DEFAULT_BODY_MODIFIED",
183: "RDT_ATTRIBUTE_DEFAULT_LANGUAGE_MODIFIED",
184: "RDT_CONCURRENCY_MODIFIED", "RDT_SIGNAL_ADDED",
185: "RDT_SIGNAL_REMOVED", "RDT_PARAMETER_ADDED",
186: "RDT_PARAMETER_REMOVED", "RDT_ABSTRACT_MODIFIED",
187: "RDT_FEATURE_ADDED", "RDT_FEATURE_REMOVED",
188: "RDT_STATIC_MODIFIED", "RDT_CONDITION_ADDED",
189: "RDT_CONDITION_REMOVED", "RDT_QUERY_MODIFIED",
190: "RDT_PARAMETER_DEFAULT_MODIFIED",
191: "RDT_PARAMETER_DEFAULT_BODY_MODIFIED",
192: "RDT_PARAMETER_DEFAULT_LANGUAGE_MODIFIED",
193: "RDT_PARAMETER_DIRECTION_MODIFIED",
194: "RDT_CHANGEABILITY_MODIFIED", "RDT_MULTIPLICITY_MODIFIED",
195: "RDT_TYPE_MODIFIED", "RDT_LOWER_MODIFIED",
196: "RDT_UPPER_MODIFIED", "RDT_RANGE_ADDED",
197: "RDT_RANGE_REMOVED", "RDT_ORDER_MODIFIED",
198: "RDT_PACKAGE_NAME_MODIFIED", "RDT_TRANSIENT_MODIFIED",
199: "RDT_NATIVE_MODIFIED", "RDT_VOLATILE_MODIFIED",
200: "RDT_LEAF_MODIFIED", "RDT_RELATION_END_MODIFIED",
201: "RDT_RELATION_END_ADDED", "RDT_RELATION_END_REMOVED",
202: "RDT_DEPENDENCY_ADDED", "RDT_DEPENDENCY_REMOVED",
203: "RDT_ASSOCIATION_END_MODIFIED",
204: "RDT_ASSOCIATION_END_ADDED", "RDT_ASSOCIATION_END_REMOVED",
205: "RDT_RELATION_CREATED", "RDT_FEATURE_MOVED",
206: "RDT_FEATURE_DUPLICATED", "RDT_NAMESPACE_MODIFIED",
207: "RDT_CHANGED_NAMESPACE", "RDT_NAMESPACE_MOVED",
208: "RDT_FINAL_MODIFIED", "RDT_STRICTFP_MODIFIED",
209: "RDT_MULTIPLE_PARAMETER_TYPE_MODIFIED", "RDT_TRANSFORM",
210: "RDT_EXCEPTION_ADDED", "RDT_EXCEPTION_REMOVED",
211: "RDT_SIGNATURE_CHANGED", "RDT_SOURCE_DIR_CHANGED", };
212:
213: public static final String REL_GENER = "Generalization";
214: public static final String REL_REALZ = "Realization";
215: public static final String REL_IMPL = "Implementation";
216: public static final String REL_ASSOS = "Association";
217:
218: private static void say(String s) {
219: Log.out(s);
220: }
221:
222: private static void say(String left, String right) {
223: final int margin = 29;
224: StringBuffer truth = new StringBuffer(left);
225: if (left.length() < margin) {
226: char[] buf = new char[margin - left.length()];
227: Arrays.fill(buf, ' ');
228: truth.append(buf);
229: }
230: truth.append(": ").append(right);
231: Log.out(truth.toString());
232: }
233:
234: private static String getVis(int mod) {
235: return Modifier.toString(JavaClassUtils.getJavaModifier(mod));
236: }
237:
238: public static void say(IChangeRequest req) {
239: if (true)
240: return;
241: say("Change type", Integer.toString(req.getState()) + " ("
242: + changeTypes[req.getState()] + ")");
243: int reqType = req.getRequestDetailType();
244: say("Request detail type", Integer.toString(reqType)/* + " ("
245: + reqDetailEnum[reqType] + ")"*/);
246: if (reqType == RDT_RELATION_DELETED
247: || reqType == RDT_RELATION_MODIFIED
248: || reqType == RDT_RELATION_VALIDATE) {
249: IRelationProxy rel = req.getRelation();
250: say("Relation type", rel.getConnectionElementType());
251: say("From:");
252: sayElement(rel.getFrom());
253: say("To:");
254: sayElement(rel.getTo());
255: }
256:
257: say("Element type", req.getAfter().getElementType());
258: IElement before = req.getBefore(), after = req.getAfter();
259: say("Before");
260: sayElement(before);
261: say("After");
262: sayElement(after);
263:
264: if (after instanceof IParameter) {
265: IParameterChangeRequest preq = (IParameterChangeRequest) req;
266:
267: say("Before Operation");
268: sayElement(preq.getBeforeOperation());
269: say("After Operation");
270: sayElement(preq.getAfterOperation());
271: }
272: }
273:
274: public static void sayElement(IElement el) {
275: if (el instanceof IClass) {
276: IClass cprox = (IClass) el;
277: sayClass(cprox);
278: } else if (el instanceof IInterface) {
279: IInterface ip = (IInterface) el;
280: sayInterface(ip);
281: } else if (el instanceof IAttribute) {
282: IAttribute aprox = (IAttribute) el;
283: sayAttribute(aprox);
284: } else if (el instanceof IOperation) {
285: IOperation oprox = (IOperation) el;
286: sayOperation(oprox);
287: } else if (el instanceof IParameter) {
288: IParameter pp = (IParameter) el;
289: sayParameter(pp);
290: } else if (el instanceof IAssociation) {
291: IAssociation ap = (IAssociation) el;
292: sayAssociation(ap);
293: } else if (el instanceof IAssociationEnd) {
294: IAssociationEnd end = (IAssociationEnd) el;
295: sayAssociation(end.getAssociation());
296: }
297: }
298:
299: public static void sayAssociation(IAssociation a) {
300: if (a == null)
301: return;
302: say(" Association type", a.getElementType());
303: say(" Association end participants");
304: ETList<IAssociationEnd> ends = a.getAssociationEnds();
305: if (ends != null) {
306: for (int i = 0; i < ends.getCount(); ++i) {
307: IAssociationEnd end = ends.item(i);
308: IClassifier el = end.getParticipant();
309: say(" " + (end.getIsNavigable() ? "-> " : " ")
310: + el.getName());
311: }
312: } else {
313: say(" << None >>");
314: }
315: }
316:
317: public static void sayClass(IClass cp) {
318: say(" Class name", JavaClassUtils.getFullyQualifiedName(cp));
319: say(" Modifiers", getVis(cp.getVisibility()));
320: say(" Superclass", getSuperclasses(cp));
321: say(" Subclasses", getSubclasses(cp));
322: say(" Interfaces", getSuperInterfaces(cp));
323: }
324:
325: public static void sayInterface(IInterface ip) {
326: say(" Interface name", JavaClassUtils.getFullyQualifiedName(ip));
327: say(" Modifiers", getVis(ip.getVisibility()));
328: say(" Superclasses?", getSuperclasses(ip));
329: say(" Super interfaces", getSuperInterfaces(ip));
330: say(" Sub types", getSubTypes(ip));
331: }
332:
333: public static void sayParameter(IParameter p) {
334: say(" Parameter name", p.getName());
335: say(" Type", p.getTypeName());
336: say(" Owning operation:");
337:
338: IOperation owner = (IOperation) p.getOwner();
339: sayOperation(owner);
340: }
341:
342: public static void sayOperation(IOperation op) {
343: StringBuffer parStr = new StringBuffer();
344: ETList<IParameter> pars = op.getFormalParameters();
345: for (int j = 0; pars != null && j < pars.getCount(); ++j) {
346: IParameter par = pars.item(j);
347: if (j > 0)
348: parStr.append(", ");
349: parStr.append(MethodParameterInfo.getType(par) + " "
350: + par.getName());
351: }
352: IParameter retType = op.getReturnType();
353: say(" Operation", getVis(op.getVisibility()) + " "
354: + op.getName() + "(" + parStr.toString() + ") : "
355: + (retType != null ? retType.getTypeName() : ""));
356: IElement owner = op.getOwner();
357: if (owner instanceof INamedElement) {
358: INamedElement nel = (INamedElement) owner;
359: say(" Owner", nel.getName());
360: }
361: }
362:
363: public static void sayAttribute(IAttribute ap) {
364: say(" Attribute", ap.getName());
365: say(" Type", ap.getTypeName());
366: say(" Modifiers", getVis(ap.getVisibility()));
367:
368: IElement owner = ap.getOwner();
369: if (owner instanceof INamedElement) {
370: INamedElement nel = (INamedElement) owner;
371: say(" Owner", nel.getName());
372: }
373: }
374:
375: public static String getSuperclasses(IClassifier cp) {
376: ETList<IGeneralization> gens = cp.getGeneralizations();
377: if (gens != null && gens.getCount() > 0) {
378: StringBuffer sups = new StringBuffer();
379: for (int i = 0; i < gens.getCount(); ++i) {
380: if (i > 0)
381: sups.append(", ");
382: sups.append(gens.item(i).getGeneral().getName());
383: }
384: return sups.toString();
385: }
386: return "<none>";
387: }
388:
389: public static String getSubclasses(IClass cp) {
390: ETList<IGeneralization> gens = cp.getSpecializations();
391: if (gens != null && gens.getCount() > 0) {
392: StringBuffer specs = new StringBuffer();
393: for (int i = 0; i < gens.getCount(); ++i) {
394: if (i > 0)
395: specs.append(", ");
396: specs.append(gens.item(i).getSpecific().getName());
397: }
398: return specs.toString();
399: }
400: return "<none>";
401: }
402:
403: public static String getSuperInterfaces(IClassifier cp) {
404: ETList<IImplementation> impls = cp.getImplementations();
405:
406: if (impls != null && impls.getCount() > 0) {
407: StringBuffer ints = new StringBuffer("{" + impls.getCount()
408: + "} ");
409: for (int i = 0; i < impls.getCount(); ++i) {
410: if (i > 0)
411: ints.append(", ");
412: INamedElement el = impls.item(i).getSupplier();
413: ints.append(el.getName());
414: }
415: return ints.toString();
416: }
417: return "<none>";
418: }
419:
420: public static String getSuperInterfaces(IInterface ip) {
421: return getSuperInterfaces((IClassifier) ip);
422: }
423:
424: public static String getSubTypes(IInterface ip) {
425: return "<not impl>";
426: }
427: }
|