Source Code Cross Referenced for IDEProcessor.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » integration » ide » events » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » uml » org.netbeans.modules.uml.integration.ide.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.uml.integration.ide.events;
0043:
0044:        import org.netbeans.modules.uml.integration.ide.DiagramKind;
0045:        import org.netbeans.modules.uml.integration.ide.JavaClassUtils;
0046:        import org.netbeans.modules.uml.integration.ide.UMLSupport;
0047:        import org.netbeans.modules.uml.integration.ide.dialogs.ExceptionDialog;
0048:        import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
0049:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IDependency;
0050:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0051:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
0052:        import org.netbeans.modules.uml.core.metamodel.diagrams.ICoreRelationshipDiscovery;
0053:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0054:        import org.netbeans.modules.uml.core.metamodel.infrastructure.IRelationFactory;
0055:        import org.netbeans.modules.uml.core.metamodel.infrastructure.RelationFactory;
0056:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociation;
0057:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociationEnd;
0058:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAttribute;
0059:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
0060:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IGeneralization;
0061:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IImplementation;
0062:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IInterface;
0063:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.INavigableEnd;
0064:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
0065:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IStructuralFeature;
0066:        import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0067:        import org.netbeans.modules.uml.core.roundtripframework.IAttributeChangeFacility;
0068:        import org.netbeans.modules.uml.core.support.umlsupport.Log;
0069:        import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0070:        import org.netbeans.modules.uml.core.support.umlutils.ETList;
0071:        import org.netbeans.modules.uml.ui.support.applicationmanager.IAssociationEdgePresentation;
0072:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProductDiagramManager;
0073:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation;
0074:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ILabelManager;
0075:
0076:        /**
0077:         * Processes the events recieved from the IDE.  The events are translated into
0078:         * GDPro specific commands to accomplished the desired action.
0079:         *
0080:         * Revision History
0081:         * No.  Date        Who         What
0082:         * ---  ----        ---         ----
0083:         *   1  2002-06-14  Darshan     Added check to screen out primitives from the
0084:         *                              search for attribute types in the Describe
0085:         *                              model.
0086:         *   2  2002-06-19  Darshan     Removed unnecessary conversions from Java names
0087:         *                              to UML names, fixed bugs in attribute updates.
0088:         *   3  2002-06-20  Darshan     Changed behaviour of attribute type change to
0089:         *                              delete the IAttribute if a navigable association
0090:         *                              is created for it and to avoid modifying
0091:         *                              existing associations (if an association already
0092:         *                              exists, the IAttribute is not deleted).
0093:         *   4  2002-06-21  Darshan     Reformatted, fixed attribute type handling.
0094:         *   5  2002-07-24  Mukta       Change for displaying role name in the model on
0095:         *                              creating a navigable association.
0096:         */
0097:        public class IDEProcessor implements  EventProcessor {
0098:            //    JavaClassUtils javaUtil = new JavaClassUtils();
0099:
0100:            // Constructor/Destructor
0101:            public IDEProcessor() {
0102:            }
0103:
0104:            /**
0105:             * Start a method transaction.  A method tranaction must be started before
0106:             * any updates to the method can begin.  The method transaction that is
0107:             * returned is to be used in all messages that is to update the method.
0108:             * When locating a method the method name and parameters is used as the
0109:             * signature of the method.
0110:             *
0111:             * @param trans The symbol transaction.
0112:             * @param method The information needed to locate the method.
0113:             * @see MethodTransaction
0114:             * @see #beginClassTransaction(ClassInfo info, IGDSystem system)
0115:             */
0116:            public MethodTransaction beginMethodTransaction(
0117:                    SymbolTransaction trans, ConstructorInfo info) {
0118:                return new MethodTransaction(trans, info);
0119:            }
0120:
0121:            /**
0122:             * Issue a command to Describe to delete a class symbol.
0123:             * @param state The transaction to act upon.
0124:             */
0125:            public void deleteClass(SymbolTransaction state) {
0126:                return;
0127:            }
0128:
0129:            /**
0130:             * Issue a command to Describe to delete a method from a class symbol.
0131:             * @param state The transaction to act upon.
0132:             */
0133:            public void deleteMethod(MethodTransaction state) {
0134:                try {
0135:                    IOperation attr = state.getOperation();
0136:                    if (attr != null) {
0137:                        attr.delete();
0138:                    }
0139:                } catch (Exception E) {
0140:                    String msg = "Error occured while deleting a method from Describe.";
0141:                    ExceptionDialog.showExceptionError(msg, E);
0142:                }
0143:            }
0144:
0145:            /**
0146:             * Issue a command to Describe to delete a data member from a class symbol.
0147:             * @param state The transaction to act upon.
0148:             */
0149:            public void deleteMember(MemberTransaction state) {
0150:                try {
0151:                    IStructuralFeature attr = state.getAttribute();
0152:                    if (attr != null)
0153:                        attr.delete();
0154:                } catch (Exception E) {
0155:                    String msg = "Error occured while deleting a data member from "
0156:                            + "Describe.";
0157:                    ExceptionDialog.showExceptionError(msg, E);
0158:                }
0159:            }
0160:
0161:            /**
0162:             * Issue a command to Describe to update the documentation of a class
0163:             * symbol.
0164:             *
0165:             * @param state The transaction to act upon.
0166:             * @param comment The new value of the symbols docuemtation.
0167:             */
0168:            public void updateClassComment(SymbolTransaction state,
0169:                    String comment) {
0170:                IClassifier clazz = state.getSymbol();
0171:                try {
0172:                    if ((clazz != null)) {
0173:                        clazz.setDocumentation(comment);
0174:                    }
0175:                } catch (Exception E) {
0176:                    String msg = "Error occured while updating a class comment in "
0177:                            + "Describe.";
0178:                    ExceptionDialog.showExceptionError(msg, E);
0179:                }
0180:            }
0181:
0182:            /**
0183:             * Issue a command to Describe remove all imports from a class symbol.
0184:             * @param state The transaction to act upon.
0185:             */
0186:            public void clearImports(SymbolTransaction state) {
0187:                //        IClassifier clazz    = state.getSymbol();
0188:                //        try {
0189:                //            if((clazz != null)) { // dont know  the API for this
0190:                //                //clazz.add.get.getI.setDocumentation(comment);;
0191:                //            }
0192:                //        } catch(Exception E) {
0193:                //            String msg = "Error occured while updating the classes imports " +
0194:                //                         "in Describe.";
0195:                //            ExceptionDialog.showExceptionError(msg, E);
0196:                //        }
0197:            }
0198:
0199:            /**
0200:             * Issue a command to Describe remove all exceptions from a class symbol.
0201:             * @param state The transaction to act upon.
0202:             */
0203:            public void clearExceptions(MethodTransaction state) {
0204:                IOperation oper = state.getOperation();
0205:                if (oper == null)
0206:                    return;
0207:
0208:                ETList<IClassifier> exceptions = state.getOperation()
0209:                        .getRaisedExceptions();
0210:                if (exceptions != null) {
0211:                    int count = exceptions.getCount();
0212:                    for (int i = 0; i < count; i++)
0213:                        state.getOperation().removeRaisedException(
0214:                                exceptions.item(i));
0215:                }
0216:            }
0217:
0218:            /**
0219:             * Issue a command to Describe add an import to a class symbol.
0220:             * @param state The transaction to act upon.
0221:             * @parma value The import to add.
0222:             */
0223:            public void addImport(SymbolTransaction state, String value) {
0224:                return;
0225:            }
0226:
0227:            /**
0228:             * Issue a command to Describe add an interface implementation to a class
0229:             * symbol.
0230:             *
0231:             * @param state The transaction to act upon.
0232:             * @param pName The name of the package that contains the interface.
0233:             * @param name The name of the interface.
0234:             */
0235:            public void addInterface(SymbolTransaction state, String pName,
0236:                    String name) {
0237:                IClassifier sym = state.getSymbol();
0238:                IClassifier interfaceSym = getClassSymbol(state, name, pName,
0239:                        true);
0240:                boolean isInterface = isClassAnInterface(sym);
0241:
0242:                if (doesImplementationExist(sym, interfaceSym) == false) {
0243:                    if (sym != null && interfaceSym != null) {
0244:                        IRelationFactory rFac = new RelationFactory();
0245:                        IProductDiagramManager diaMana = UMLSupport
0246:                                .getUMLSupport().getProduct()
0247:                                .getDiagramManager();
0248:                        if (rFac == null) {
0249:                            Log.out("GOT THE NULL RelationFactory");
0250:                            return;
0251:                        }
0252:
0253:                        if (!isInterface) {
0254:                            IDependency rel = rFac.createImplementation(sym,
0255:                                    interfaceSym,
0256:                                    UMLSupport.getCurrentProject())
0257:                                    .getParamTwo();
0258:                            addRelationshipLinkToDiagram(rel, diaMana
0259:                                    .getCurrentDiagram());
0260:                        } else {
0261:                            IGeneralization gen = rFac.createGeneralization(
0262:                                    interfaceSym, sym);
0263:                            addRelationshipLinkToDiagram(gen, diaMana
0264:                                    .getCurrentDiagram());
0265:                        }
0266:                    } else {
0267:                        Log.out("One of the things is null .......");
0268:                    }
0269:                }
0270:            }
0271:
0272:            protected boolean doesImplementationExist(IClassifier sym,
0273:                    IClassifier interfaceSym) {
0274:                boolean retVal = false;
0275:                if (interfaceSym instanceof  IInterface) {
0276:                    ETList<IImplementation> impls = sym.getImplementations();
0277:                    for (IImplementation curImpl : impls) {
0278:                        IInterface contract = curImpl.getContract();
0279:                        IClassifier implementor = curImpl
0280:                                .getImplementingClassifier();
0281:
0282:                        if ((contract.isSame(interfaceSym) == true)
0283:                                && (implementor.isSame(sym) == true)) {
0284:                            retVal = true;
0285:                        }
0286:                    }
0287:                }
0288:
0289:                return retVal;
0290:            }
0291:
0292:            public static void addRelationshipLinkToDiagram(IElement elem,
0293:                    IDiagram dia) {
0294:                Log.out("Inside addRelationshipLinkToDiagram");
0295:                if (dia == null) {
0296:                    IProductDiagramManager diagMan = UMLSupport.getUMLSupport()
0297:                            .getProduct().getDiagramManager();
0298:                    dia = diagMan.getCurrentDiagram();
0299:                }
0300:                if (elem != null && dia != null
0301:                        && dia.getDiagramKind() == DiagramKind.DK_CLASS_DIAGRAM) {
0302:                    // Check if we already have a presentation element
0303:                    if (!hasPresentationElement(dia, elem)) {
0304:                        Log.out("==== Creating presentation element in "
0305:                                + dia.getName() + "!");
0306:                        ICoreRelationshipDiscovery rel = dia
0307:                                .getRelationshipDiscovery();
0308:                        if (rel == null) {
0309:                            Log.err("addRelationshipLinkToDiagram: Couldn't "
0310:                                    + "obtain relationship discovery element");
0311:                            return;
0312:                        }
0313:                        try {
0314:                            if (elem instanceof  INavigableEnd) {
0315:                                INavigableEnd nav = (INavigableEnd) elem;
0316:
0317:                                ETList<IElement> els = new ETArrayList<IElement>();
0318:                                els.add(nav.getFeaturingClassifier());
0319:                                els.add(nav.getOtherEnd2()
0320:                                        .getFeaturingClassifier());
0321:
0322:                                // TODO:
0323:                                ETList<IPresentationElement> pElems = rel
0324:                                        .discoverCommonRelations(true, els);
0325:                                if (elem != null) {
0326:                                    try {
0327:                                        addLabel(pElems);
0328:                                    } catch (Exception ex) {
0329:                                        Log.stackTrace(ex);
0330:                                    }
0331:
0332:                                }
0333:                            }
0334:                            rel.discoverCommonRelations(true);
0335:                            IPresentationElement ipe = rel
0336:                                    .createPresentationElement(elem);
0337:                            //                    dia.addPresentationElement(ipe);
0338:                            if (elem != null && elem instanceof  IAssociation) {
0339:
0340:                                if (ipe instanceof  IAssociationEdgePresentation) {
0341:                                    IProductGraphPresentation edPre = (IProductGraphPresentation) ipe;
0342:                                    ILabelManager lblMgr = edPre
0343:                                            .getLabelManager();
0344:                                    lblMgr.showLabel(4, true);
0345:                                }
0346:                            }
0347:                        } catch (Exception e) {
0348:                            Log.stackTrace(e);
0349:                        }
0350:                    }
0351:                }
0352:            }
0353:
0354:            private static void addLabel(ETList<IPresentationElement> pElems) {
0355:                int count = 0;
0356:                if (pElems != null && (count = pElems.getCount()) > 0) {
0357:                    Log.out("addRelationshipLinkToDiagram: Got " + count
0358:                            + " presentation elements");
0359:                    IPresentationElement pElem = null;
0360:                    for (int i = 0; i < count; i++) {
0361:                        pElem = pElems.item(i);
0362:
0363:                        if (pElem instanceof  IAssociationEdgePresentation) {
0364:                            IProductGraphPresentation edPre = (IProductGraphPresentation) pElem;
0365:                            ILabelManager lblMgr = edPre.getLabelManager();
0366:                            Log
0367:                                    .out("addRelationshipLinkToDiagram: Showing label");
0368:                            //if(!lblMgr.isDisplayed(4)){
0369:                            lblMgr.createInitialLabels();
0370:                            lblMgr.resetLabels();
0371:                            lblMgr.showLabel(4, true);
0372:                            //lblMgr.relayoutLabels();
0373:                            //}
0374:                        } else
0375:                            Log.out("Ignoring presentation element");
0376:                    }
0377:                }
0378:            }
0379:
0380:            private static boolean hasPresentationElement(IDiagram diag,
0381:                    IElement el) {
0382:                ETList<IElement> elements = diag.getElements();
0383:
0384:                if (elements == null || elements.getCount() == 0)
0385:                    return false;
0386:
0387:                String xmiid = el.getXMIID();
0388:                for (int i = 0; i < elements.getCount(); ++i) {
0389:                    if (elements.item(i).getXMIID().equals(xmiid))
0390:                        return true;
0391:                }
0392:
0393:                return false;
0394:            }
0395:
0396:            /**
0397:             * Issue a command to Describe remvoe an interface implementation from a
0398:             * class symbol.
0399:             *
0400:             * @param state The transaction to act upon.
0401:             * @param pName The name of the package that contains the interface.
0402:             * @param name The name of the interface.
0403:             */
0404:            public void removeInterface(SymbolTransaction state, String pName,
0405:                    String name) {
0406:
0407:                String qualName = JavaClassUtils.formFullClassName(pName, name);
0408:                String sName = "";
0409:
0410:                IClassifier cl = state.getSymbol();
0411:                if (cl instanceof  IClass) {
0412:                    ETList<IImplementation> impls = state.getSymbol()
0413:                            .getImplementations();
0414:                    if (impls == null)
0415:                        return;
0416:                    int size = impls.getCount();
0417:                    for (int i = 0; i < size; i++) {
0418:                        IImplementation impl = impls.item(i);
0419:                        sName = JavaClassUtils.getFullyQualifiedName(impl
0420:                                .getSupplier());
0421:                        if (impl != null && sName.equals(qualName)) {
0422:                            IClassifier interf = (IClassifier) impl
0423:                                    .getSupplier();
0424:                            impl.delete();
0425:                            if ((JavaClassUtils.isReferenceClass(interf) || (interf instanceof  IInterface && ClassInfo
0426:                                    .getSymbolFilename(interf) == null))
0427:                                    && JavaClassUtils.isOrphan(interf)) {
0428:                                boolean rt = UMLSupport.isRoundTripEnabled();
0429:                                UMLSupport.setRoundTripEnabled(false);
0430:                                interf.delete();
0431:                                UMLSupport.setRoundTripEnabled(rt);
0432:                            }
0433:                        }
0434:                    }
0435:                } else if (cl instanceof  IInterface) {
0436:                    ETList<IGeneralization> gens = state.getSymbol()
0437:                            .getGeneralizations();
0438:                    if (gens == null)
0439:                        return;
0440:                    int size = gens.getCount();
0441:                    for (int i = 0; i < size; i++) {
0442:                        IGeneralization gen = gens.item(i);
0443:                        sName = JavaClassUtils.getFullyQualifiedName(gen
0444:                                .getGeneral());
0445:                        if (gen != null && sName.equals(qualName)) {
0446:                            gen.delete();
0447:                        }
0448:                    }
0449:                }
0450:
0451:            }
0452:
0453:            /**
0454:             * Issue a command to Describe add an exception to a class symbol.
0455:             * @param state The transaction to act upon.
0456:             * @param value The exception to add.
0457:             */
0458:            public void addException(MethodTransaction state, String value) {
0459:            }
0460:
0461:            /**
0462:             * Issue a command to Describe add a collection of exceptions to a class
0463:             * symbol.
0464:             *
0465:             * @param state The transaction to act upon.
0466:             * @param value The exceptions to add.
0467:             */
0468:            public void setExceptions(MethodTransaction state, String value) {
0469:
0470:                setAttribute(state, "ThrowType", value);
0471:            }
0472:
0473:            /**
0474:             * Issue a command to Describe to updates a attibute on a class symbol.  The
0475:             * attribute must be specified in a fully qualified manner.
0476:             * <br>
0477:             * <b>Example:</b> setAttribute("ClassIdentifier.FullyScopedName", name);
0478:             *
0479:             * @param state The transaction to act upon.
0480:             * @param attr The fully qualified name of the attribute.
0481:             * @param value The new value of the attribute.
0482:             */
0483:            public void setAttribute(SymbolTransaction state, String attr,
0484:                    String value) {
0485:            }
0486:
0487:            /**
0488:             * Issue a command to Describe to updates a attibute on a <b>Operations</b>
0489:             * attribute.  The attribute must be specified in a fully qualified manner.
0490:             * <br>
0491:             * <b>Example:</b> setAttribute("ClassIdentifier.FullyScopedName", name);
0492:             *
0493:             * @param state The transaction to act upon.
0494:             * @param attr The fully qualified name of the attribute.
0495:             * @param value The new value of the attribute.
0496:             */
0497:            public void setAttribute(MethodTransaction state, String attrName,
0498:                    String value) {
0499:            }
0500:
0501:            /**
0502:             * Issue a command to Describe to updates a attibute on a <b>Attributes</b>
0503:             * attribute.  The attribute must be specified in a fully qualified manner.
0504:             * <br>
0505:             * <b>Example:</b> setAttribute("ClassIdentifier.FullyScopedName", name);
0506:             *
0507:             * @param state The transaction to act upon.
0508:             * @param attr The fully qualified name of the attribute.
0509:             * @param value The new value of the attribute.
0510:             */
0511:            public void setAttribute(MemberTransaction state, String attrName,
0512:                    String value) {
0513:            }
0514:
0515:            /**
0516:             * Issue a command to Describe to remove a generalization associated with a
0517:             * class symbol.
0518:             * @param state The transaction to act upon.
0519:             * @param value The value.
0520:             */
0521:            public void removeSuperClass(SymbolTransaction state, String cName,
0522:                    String pName) {
0523:            }
0524:
0525:            public void addSuperClass(SymbolTransaction state,
0526:                    String className, String packageName) {
0527:            }
0528:
0529:            /**
0530:             * Issue a command to Describe to add a generalization associated with a
0531:             * class symbol.
0532:             * @param state The transaction to act upon.
0533:             * @param value The value.
0534:             */
0535:            public void setMethodParameters(MethodTransaction state,
0536:                    String params) {
0537:                setAttribute(state, "Parameters", params);
0538:            }
0539:
0540:            /**
0541:             * Issue a command to Describe to updates a tagged value on a class symbol.
0542:             *
0543:             * @param state The transaction to act upon.
0544:             * @param tag The name of the tag to be set.
0545:             * @param value The new value of the attribute.
0546:             */
0547:            public void setTaggedValue(SymbolTransaction state, String tag,
0548:                    String value) {
0549:            }
0550:
0551:            /**
0552:             * Issue a command to Describe to updates a tagged value on a
0553:             * <b>Operations</b> attribute.
0554:             *
0555:             * @param state The transaction to act upon.
0556:             * @param tag The name of the tag to be set.
0557:             * @param value The new value of the attribute.
0558:             */
0559:            public void setTaggedValue(MethodTransaction state, String tag,
0560:                    String value) {
0561:            }
0562:
0563:            /**
0564:             * Issue a command to Describe to updates a tagged value on a
0565:             * <b>Attributes</b> attribute.
0566:             *
0567:             * @param state The transaction to act upon.
0568:             * @param tag The name of the tag to be set.
0569:             * @param value The new value of the attribute.
0570:             */
0571:            public void setTaggedValue(MemberTransaction state, String tag,
0572:                    String value) {
0573:            }
0574:
0575:            /**
0576:             * Updates a data members type.  If the data member is current a
0577:             * implementation attribute then then the implementation attribute is
0578:             * updated.  Otherwise, the attribute on the CLD_Class symbol is updated.
0579:             * The parameter fullName is the fully qualified name of the data member's
0580:             * type .  However if the data member's type is a class that Describes knows
0581:             * about then the data member will reside on a <B>Class Associaton</B>
0582:             * between the containing class symbol and the symbol that represents the
0583:             * data type of the data member.
0584:             *
0585:             * @param state The data of the attribute in Describe.
0586:             * @param fullName The fully qualified name of the data member type.
0587:             * @param soruceName How the data member is specified in code.
0588:             */
0589:            public void updateMemberType(MemberTransaction state,
0590:                    String fullName, String sourceName) {
0591:                Log.out("Member type = " + fullName);
0592:                handleUpdateImplAttr(state, fullName, sourceName);
0593:            }
0594:
0595:            public static INavigableEnd makeNavigableAssociation(
0596:                    IClassifier clazz, IClassifier type, String name) {
0597:
0598:                RelationFactory fact = new RelationFactory();
0599:                IProject proj = clazz.getProject();
0600:                IAssociation assoc = fact.createAssociation(clazz, type, proj);
0601:
0602:                // set the navigability for the association added
0603:                ETList<IAssociationEnd> assoEnds = assoc.getEnds();
0604:
0605:                INavigableEnd nav = null;
0606:                //IAssociationEnd ase = null;
0607:                if (assoEnds != null) {
0608:                    int count = assoEnds.getCount();
0609:                    IAssociationEnd assoEnd;
0610:                    for (int i = 0; i < count; i++) {
0611:                        assoEnd = assoEnds.item(i);
0612:                        if (assoEnd.getParticipant().getName().equals(
0613:                                clazz.getName())) {
0614:                            continue;
0615:                        }
0616:                        // make this end navigable
0617:                        if (!assoEnd.getIsNavigable()) {
0618:                            assoEnd.setName(name);
0619:                            nav = assoEnd.makeNavigable();
0620:                            break;
0621:                        }
0622:                    }
0623:                }
0624:
0625:                IProductDiagramManager diaMana = UMLSupport.getUMLSupport()
0626:                        .getProduct().getDiagramManager();
0627:                IDiagram dia = diaMana.getCurrentDiagram();
0628:                if (dia != null) {
0629:                    addRelationshipLinkToDiagram(assoc, dia);
0630:                }
0631:
0632:                return nav;
0633:            }
0634:
0635:            /**
0636:             * Creates a navigable association for the given MemberTransaction, with
0637:             * the given IClassifier. This assumes that the MemberTransaction already
0638:             * has an IAttribute associated with it. The IAttribute of the transaction
0639:             * will be deleted from the model and replaced by the navigable association.
0640:             *
0641:             * @param state   The MemberTransaction
0642:             * @param type    The IClassifier of the attribute's type.
0643:             */
0644:            protected void createAssociation(MemberTransaction state,
0645:                    IClassifier type, String fullName) {
0646:                IStructuralFeature attr = state.getAttribute();
0647:
0648:                IClassifier clazz = state.getSymbol();
0649:                // Check if there's already an association; if there is, don't create
0650:                // another.
0651:                IAssociation assoc = JavaClassUtils
0652:                        .findAssociation(clazz, type);
0653:
0654:                if (assoc != null)
0655:                    return;
0656:
0657:                String doc = attr.getDocumentation();
0658:                boolean vol = attr.getIsVolatile(), fin = attr.getIsFinal(), tra = attr
0659:                        .getIsTransient(), sta = attr.getIsStatic();
0660:                int vis = attr.getVisibility();
0661:
0662:                IAssociation attrAssoc = JavaClassUtils.findAssociation(clazz,
0663:                        attr.getType());
0664:                if (attrAssoc != null) {
0665:                    Log.out("createAssociation: Found association between "
0666:                            + clazz.getName() + " and " + attr.getTypeName()
0667:                            + ", deleting it");
0668:                    attrAssoc.delete();
0669:                } else {
0670:                    Log
0671:                            .out("createAssociation: Found no association, deleting attribute "
0672:                                    + attr.getName());
0673:                    attr.delete();
0674:                }
0675:
0676:                IAttribute nav = null;
0677:                if (type == null && fullName != null) {
0678:                    IAttributeChangeFacility facility = EventManager
0679:                            .getAttributeFacility();
0680:                    if (facility == null) {
0681:                        Log
0682:                                .impossible("createAssociation: No IAttributeChangeFacility?");
0683:                        return;
0684:                    }
0685:                    Log.out("createAssociation: Creating attribute : "
0686:                            + attr.getName() + ": " + fullName);
0687:                    //retVal = facility.createAttribute(name, sourceName, sym);
0688:                    String umlFullName = JavaClassUtils
0689:                            .convertJavaToUML(fullName);
0690:                    nav = facility.addAttribute2(attr.getName(), umlFullName,
0691:                            clazz, true, false);
0692:                } else
0693:                    nav = (IAttribute) makeNavigableAssociation(clazz, type,
0694:                            attr.getName());
0695:
0696:                boolean rtEnabled = UMLSupport.isRoundTripEnabled();
0697:                UMLSupport.setRoundTripEnabled(false);
0698:
0699:                if (nav != null) {
0700:                    if (doc != null)
0701:                        nav.setDocumentation(doc);
0702:                    nav.setIsVolatile(vol);
0703:                    nav.setIsFinal(fin);
0704:                    nav.setIsStatic(sta);
0705:                    nav.setIsTransient(tra);
0706:                    nav.setVisibility(vis);
0707:                    //attr.delete();
0708:
0709:                    state.setAttribute(nav);
0710:                }
0711:                UMLSupport.setRoundTripEnabled(rtEnabled);
0712:            }
0713:
0714:            protected void removeAssociation(MemberTransaction state,
0715:                    String fullName, String sourceName) {
0716:                INavigableEnd attr = (INavigableEnd) state.getAttribute();
0717:                //IAttribute attr = (IAttribute) state.getAttribute();
0718:
0719:                IClassifier clazz = state.getSymbol();
0720:
0721:                String name = attr.getName();
0722:                String doc = attr.getDocumentation();
0723:                boolean vol = attr.getIsVolatile(), fin = attr.getIsFinal(), tra = attr
0724:                        .getIsTransient(), sta = attr.getIsStatic();
0725:                int vis = attr.getVisibility();
0726:
0727:                attr.getAssociation().delete();
0728:
0729:                IAttribute at = clazz.createAttribute(sourceName, name);
0730:                clazz.addAttribute(at);
0731:
0732:                boolean rtEnabled = UMLSupport.isRoundTripEnabled();
0733:                UMLSupport.setRoundTripEnabled(false);
0734:
0735:                if (doc != null)
0736:                    at.setDocumentation(doc);
0737:                at.setIsVolatile(vol);
0738:                at.setIsFinal(fin);
0739:                at.setIsStatic(sta);
0740:                at.setIsTransient(tra);
0741:                at.setVisibility(vis);
0742:
0743:                UMLSupport.setRoundTripEnabled(rtEnabled);
0744:
0745:                state.setAttribute(at);
0746:            }
0747:
0748:            /**
0749:             * The work horse of updateMemberType that updates an implemenation
0750:             * attribute.  If the type ot the data member is no longer in Describe then
0751:             * the data member is moved to the containing classes symbol.  Otherwise, a
0752:             * class association is created to the data members type and the data member
0753:             * is added as a implementation attribute.
0754:             *
0755:             * @param state The data of the attribute in Describe.
0756:             * @param fullName The fully qualified name of the data member's type.
0757:             * @param soruceName How the data member is specified in code.
0758:             */
0759:            protected void handleUpdateImplAttr(MemberTransaction state,
0760:                    String fullName, String sourceName) {
0761:                IStructuralFeature attr = state.getAttribute();
0762:
0763:                MemberInfo modelInfo = new MemberInfo(attr);
0764:                //        String collectionType = UMLSupport.getUMLSupport()
0765:                //                                            .getCollectionOverride();
0766:                String collectionType = modelInfo
0767:                        .getCollectionOverrideDataType();
0768:                if (modelInfo.isUseCollectionOverride()
0769:                        && collectionType != null
0770:                        && (collectionType.equals(sourceName) || collectionType
0771:                                .equals(fullName)))
0772:                    return;
0773:
0774:                int oldMul = MemberInfo.getMultiplicity(attr), newMul = MemberInfo
0775:                        .getMultiplicity(sourceName);
0776:
0777:                fullName = MemberInfo.getTypeName(fullName);
0778:                sourceName = JavaClassUtils.getInnerClassName(MemberInfo
0779:                        .getTypeName(sourceName));
0780:
0781:                String modelFullName = JavaClassUtils
0782:                        .getFullyQualifiedName(attr.getType());
0783:
0784:                Log.out("handleUpdateImplAttr: Attribute type full name : "
0785:                        + fullName + ", source name : " + sourceName);
0786:                Log
0787:                        .out("handleUpdateImplAttr: Attribute type in model, full = "
0788:                                + modelFullName
0789:                                + ", unqualified = "
0790:                                + attr.getTypeName());
0791:
0792:                // set the type of attribute to be added to class
0793:                if ((attr.getTypeName().equals(sourceName) || modelFullName
0794:                        .equals(fullName))
0795:                        && oldMul == newMul)
0796:                    return;
0797:
0798:                String umlName = JavaClassUtils.convertJavaToUML(fullName);
0799:                Log.out("handleUpdateImplAttr: Setting attribute type to "
0800:                        + umlName);
0801:                attr.setType2(umlName);
0802:
0803:                Log.out("Setting multiplicity for '" + attr.getName() + "' to "
0804:                        + newMul + " (was " + oldMul + ")");
0805:                MemberInfo.setMultiplicity(attr, newMul, oldMul);
0806:
0807:                /*
0808:                // Add the association if doesn't exist already
0809:                boolean isAttr = attr instanceof IAttribute;
0810:
0811:                IClassifier attrClazz = JavaClassUtils.findClassSymbol(fullName);
0812:                if (attrClazz != null && !JavaClassUtils.isPrimitive(fullName)) {
0813:                    Log.out(
0814:                        "handleUpdateImplAttr: Creating association for " + fullName);
0815:                    createAssociation(state, attrClazz, fullName);
0816:                } else {
0817:                    Log.out(
0818:                        "handleUpdateImplAttr: Removing association, creating " +                "attribute for " + fullName);
0819:                    if (!isAttr)
0820:                        removeAssociation(state, fullName, sourceName);
0821:                }
0822:                 */
0823:            }
0824:
0825:            /**
0826:             * The work horse of updateMemberType that updates an attribute on a CLD_Class
0827:             * symbol.   If the new type of the data member is known by Describe the
0828:             * data member will be moved to a Class Association and made an implemenation
0829:             * attribute.  If an association does not exist between the data members containing
0830:             * class and the data type then the association will be created.
0831:             *
0832:             * @param state The data of the attribute in Describe.
0833:             * @param fullName The fully qualified name of the data member's type.
0834:             * @param soruceName How the data member is specified in code.
0835:             */
0836:            protected void handleUpdateSymbolAttr(MemberTransaction state,
0837:                    String fullName, String type) {
0838:                /*
0839:                   IGDAttribute attr = state.getAttribute();
0840:                   try {
0841:                   IGDSymbol    ownerSym = attr.getSymbol();
0842:                   IGDSystem    system   = state.getSystem();
0843:                   IGDSymbols   symbols  = system.isDuplicated4("CLD_Class.ClassIdentifier.FullyScopedName", fullName);
0844:
0845:                   RelationshipHelper helper = new RelationshipHelper(system);
0846:                   if(symbols.getCount() > 0) {
0847:                // Get the relationship and the role that the new type plays
0848:                String attrRole = "EndClass";
0849:                IGDRelation rel = helper.findRelationship(ownerSym, "CLD_ClassAssociation", fullName, "CLD_EndClass");
0850:                if(rel == null) {
0851:                // Try search for the start end
0852:                attrRole = "StartClass";
0853:                rel = helper.findRelationship(ownerSym, "CLD_ClassAssociation", fullName, "CLD_StartClass");
0854:                }
0855:
0856:                // If still null the new have to create the relationship.
0857:                IGDSymbol linkSym = null;
0858:                if(rel == null) {
0859:                IGDSymbol otherSym = symbols.item(0);
0860:                linkSym = helper.createRelationship("CLD_ClassAssociation",
0861:                ownerSym, "CLD_StartClass",
0862:                otherSym, "CLD_EndClass",
0863:                "CLD_ClassAssociation","CLD_ClassAssociation");
0864:
0865:                // Now set the navigiablity
0866:                IGDAttribute topAttr = linkSym.getAttributes();
0867:                if(topAttr != null) {
0868:                topAttr.setData3("Role1Navigability", "Composition", true);
0869:                topAttr.setData3("Role2Navigability", "Navigable", true);
0870:                }
0871:
0872:                // Now I have to find the relationship because the API does not return
0873:                // the new relationship
0874:                attrRole = "EndClass";
0875:                rel = helper.findRelationship(ownerSym, "CLD_ClassAssociation", otherSym, "CLD_EndClass");
0876:                }
0877:
0878:                if (linkSym != null) {
0879:                // now move the attribute to the link
0880:                IGDAttribute topLevel = linkSym.getAttributes();
0881:                IGDAttribute newAttr  = topLevel.createSubAttribute("Attributes");
0882:                newAttr.setData2("RoleIdentifier", attrRole);
0883:                copyAttribute(attr, newAttr);
0884:
0885:                state.setAttribute(newAttr);
0886:                state.setMemberRelationship(rel);
0887:                state.setIsImplAttribute(true);
0888:
0889:                attr.delete();
0890:                }
0891:                } else {
0892:                attr.setData2("Type", type);
0893:                }
0894:                } catch(Exception E) {
0895:                String msg = "Error occured while updating a data members type.";
0896:                ExceptionDialog.showExceptionError(msg, E);
0897:                }
0898:                 */
0899:            }
0900:
0901:            /**
0902:             * Generic method for setting the value of a Describe's attribute.
0903:             * @param sym The symbol to update.
0904:             * @param attr The name of the attribute to update.
0905:             * @param value The new value of the symbols attribute.
0906:             */
0907:            protected void setAttribute(IClass sym, String attr, String value) {
0908:                /*
0909:                   try {
0910:                   if(sym != null) {
0911:                   IGDAttribute curAttr = sym.getSubAttribute(attr);
0912:                   if((curAttr == null) || (curAttr.getIsActual() == false)) {
0913:                   IGDAttribute topLevel = sym.getAttributes();
0914:                   curAttr = topLevel.createSubAttribute(attr);
0915:                   }
0916:
0917:                   if((curAttr != null) && (curAttr.getIsActual() == true)) {
0918:                   curAttr.setData(value);
0919:                   }
0920:                   }
0921:                   } catch(Exception E) {
0922:                   String msg = "Error occured while updating a symbols attribute.";
0923:                   msg += "Attribute Name: " + attr + " Value: " + value;
0924:                   ExceptionDialog.showExceptionError(msg, E);
0925:                   }
0926:                 */
0927:            }
0928:
0929:            /**
0930:             * Retievies an interface from Describe.  If the interface does not current exist
0931:             * in Describe it will be created as a <b>Reference Class</b>
0932:             * @param trans The symbols state data.
0933:             * @param name The name of the Interface class.
0934:             * @param packgeName The name of the package that the interface resides.
0935:             */
0936:            /*
0937:               private IClassifier getInterfaceSymbol(SymbolTransaction trans, String name, String packageName) {
0938:               IClassifier retVal = getClassSymbol(trans, name, packageName);
0939:
0940:               try {
0941:               setAttribute(retVal, "ClassType", "Abstract");
0942:               setAttribute(retVal, "ClassFormat", "interface");
0943:
0944:               IGDAttribute sAttr = retVal.getSubAttribute("Stereotype.Stereotype");
0945:               String stereotype = sAttr.getData();
0946:               if(stereotype.length() <= 0) {
0947:               sAttr.setData("Interface");
0948:               }
0949:               } catch(Exception E) {
0950:               String msg = "Error occured while retrieving an interface class from Describe.";
0951:               ExceptionDialog.showExceptionError(msg, E);
0952:               }
0953:
0954:               return retVal;
0955:               }
0956:             */
0957:
0958:            /**
0959:             * Retievies an class symbol from Describe.  If the class symbol does not current exist
0960:             * in Describe it will be created as a <b>Reference Class</b>
0961:             * @param trans The symbols state data.
0962:             * @param name The name of the class.
0963:             * @param packgeName The name of the package that the class resides.
0964:             */
0965:            private IClassifier getClassSymbol(SymbolTransaction trans,
0966:                    String name, String packageName, boolean isInterface) {
0967:                IClassifier retVal = null;
0968:
0969:                if (name.length() > 0) {
0970:                    try {
0971:                        //IProject proj = UMLSupport.getCurrentProject();
0972:                        String qualifiedName = JavaClassUtils
0973:                                .formFullClassName(packageName, name);
0974:                        IClassifier sym = JavaClassUtils
0975:                                .findClassSymbol(qualifiedName);
0976:                        if (sym == null) {
0977:                            boolean evt = UMLSupport.isRoundTripEnabled();
0978:                            UMLSupport.setRoundTripEnabled(false);
0979:                            try {
0980:                                sym = JavaClassUtils
0981:                                        .createDataType(JavaClassUtils
0982:                                                .formFullClassName(packageName,
0983:                                                        name));
0984:                                //sym = trans.createClass(name, packageName, isInterface, null, ElementInfo.CREATE);
0985:                                // Tag it as a reference class
0986:                                //JavaClassUtils.setReferenceClass(sym, true);
0987:                            } finally {
0988:                                UMLSupport.setRoundTripEnabled(evt);
0989:                            }
0990:                        }
0991:                        retVal = sym;
0992:                    } catch (Exception e) {
0993:                        Log.stackTrace(e);
0994:                    }
0995:                }
0996:                return retVal;
0997:            }
0998:
0999:            /**
1000:             * Test if a symbol is a Interface.  First the symbol is verified to be a
1001:             * CLD_Class symbol.  The the class format is checked if it is a interface.
1002:             *
1003:             * @param sym The symbol to check.
1004:             * @param True if the symbol is an interface, false otherwise.
1005:             */
1006:            protected boolean isClassAnInterface(IClassifier sym) {
1007:                boolean retVal = false;
1008:
1009:                try {
1010:                    if (sym instanceof  IInterface || sym instanceof  IInterface) {
1011:                        return true;
1012:                    }
1013:                } catch (Exception E) {
1014:                    String msg = "Error occured while reteiving a format of a class in Describe.";
1015:                    ExceptionDialog.showExceptionError(msg, E);
1016:                }
1017:
1018:                return retVal;
1019:            }
1020:        }
w_w_w_._j___a_v__a___2___s___.___c_o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.