Source Code Cross Referenced for DiagramTypesManager.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » support » diagramsupport » 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.ui.support.diagramsupport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * Created on Jun 11, 2003
044:         *
045:         *
046:         */
047:        package org.netbeans.modules.uml.ui.support.diagramsupport;
048:
049:        import org.dom4j.Document;
050:        import org.dom4j.Element;
051:        import org.dom4j.Node;
052:
053:        import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
054:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
055:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
056:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramKind;
057:        import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
058:        import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
059:
060:        /**
061:         * @author sumitabhk
062:         *
063:         * 
064:         */
065:        public class DiagramTypesManager implements  IDiagramTypesManager {
066:            private static DiagramTypesManager m_Instance = null;
067:            private Document m_Doc = null;
068:
069:            /**
070:             * 
071:             */
072:            private DiagramTypesManager() {
073:                super ();
074:            }
075:
076:            public static DiagramTypesManager instance() {
077:                if (m_Instance == null) {
078:                    m_Instance = new DiagramTypesManager();
079:                }
080:                return m_Instance;
081:            }
082:
083:            /**
084:             * The display name for this diagram type (ie Class Diagram)
085:             *
086:             * @param sDiagramTypeName [in] The diagram type name ie "Class Diagram"
087:             * @param pDiagramKind [out,retval] The DiagramKind enumeration that matches pDiagramTypeName
088:             */
089:            public int getDiagramKind(String sDiagramTypeName) {
090:                int diaKind = IDiagramKind.DK_DIAGRAM;
091:
092:                // Verify that we've setup the xml file correctly
093:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
094:                query += sDiagramTypeName;
095:                query += "']";
096:
097:                String attributeToFind = "DiagramKindEnumValue";
098:
099:                diaKind = getAttributeValue(query, attributeToFind);
100:
101:                return diaKind;
102:            }
103:
104:            /**
105:             * Gets an attribute based on a query
106:             *
107:             * @param query [in] The query to perform
108:             * @param attributeValue [in] The attribute for which we need the value of
109:             * @param nValue [out] The value of attributeValue
110:             *
111:             * @return true if we successfully got the attribute value
112:             */
113:            private int getAttributeValue(String query, String attributeToFind) {
114:                int retVal = 0;
115:                if (verifyFile() == true) {
116:                    if (m_Doc != null) {
117:                        Node n = m_Doc.selectSingleNode(query);
118:                        if (n != null) {
119:                            String value = XMLManip.getAttributeValue(n,
120:                                    attributeToFind);
121:                            String test = value;
122:                            //String value = ((Element)n).attributeValue(attributeToFind);
123:                            if (test != null) {
124:                                retVal = Integer.parseInt(test);
125:                            }
126:                        }
127:                    }
128:                }
129:                return retVal;
130:            }
131:
132:            /**
133:             * Opens and validates that the xml file is ok
134:             *
135:             * @return true if the file exists and we successfully loaded.
136:             */
137:            private boolean verifyFile() {
138:                boolean valid = false;
139:                if (m_Doc == null) {
140:                    String location = retrieveDefaultLocation();
141:                    if (location.length() > 0) {
142:                        m_Doc = XMLManip.getDOMDocument(location);
143:                        if (m_Doc != null) {
144:                            valid = true;
145:                        }
146:                    }
147:                } else {
148:                    valid = true;
149:                }
150:                return valid;
151:            }
152:
153:            /**
154:             * Returns the location of the DiagramTypesManager file
155:             *
156:             * @return The absolute location of the DiagramTypesManager.etc file.
157:             */
158:            private String retrieveDefaultLocation() {
159:                String location = null;
160:                ICoreProduct prod = ProductRetriever.retrieveProduct();
161:                IConfigManager conMan = prod.getConfigManager();
162:                if (conMan != null) {
163:                    location = conMan.getDefaultConfigLocation();
164:                    location += "DiagramTypesManager.etc";
165:                }
166:                return location;
167:            }
168:
169:            /**
170:             * Returns the diagram kind (ie Class Diagram) for the argument diagram
171:             *
172:             * @param pDiagram [in] The diagram for which to get the type
173:             * @param pVal [out,retval] The type of the argument diagram (ie Class Diagram)
174:             */
175:            public String getDiagramTypeName(IDiagram pDiagram) {
176:                String retVal = "";
177:                if (pDiagram != null) {
178:                    retVal = pDiagram.getDiagramKind2();
179:                }
180:                return retVal;
181:            }
182:
183:            /**
184:             * Returns the diagram kind (ie Class Diagram) for the argument enumeration
185:             *
186:             * @param pDiagram [in] The diagram enumeration which we need to convert to a string (ie
187:             * Class Diagram to DK_CLASS_DIAGRAM.
188:             * @param pVal [out,retval] The returned type of the diagram enumeration as a string.
189:             */
190:            public String getDiagramTypeName(int nDiagramKind) {
191:                String retVal = "";
192:                String query = "//DiagramTypes/DiagramType[@DiagramKindEnumValue='";
193:                query += nDiagramKind;
194:                query += "']";
195:
196:                String attributeToFind = "DiagramTypeName";
197:
198:                retVal = getStringAttributeValue(query, attributeToFind);
199:
200:                return retVal;
201:            }
202:
203:            /**
204:             * Gets an attribute based on a query
205:             *
206:             * @param query [in] The query to perform
207:             * @param attributeValue [in] The attribute for which we need the value of
208:             * @param sValue [out] The value of attributeValue
209:             *
210:             * @return true if we successfully got the attribute value
211:             */
212:            private String getStringAttributeValue(String query,
213:                    String attributeToFind) {
214:                String retVal = null;
215:                if (verifyFile() == true) {
216:                    if (m_Doc != null) {
217:                        Node n = m_Doc.selectSingleNode(query);
218:                        if (n != null) {
219:                            retVal = XMLManip.getAttributeValue(n,
220:                                    attributeToFind);
221:                        }
222:                    }
223:                }
224:                return retVal;
225:            }
226:
227:            /**
228:             * Returns the diagram kind without spaces (ie ClassDiagram) for the argument diagram
229:             *
230:             * @param pDiagram [in] The diagram for which to get the type sans spaces
231:             * @param pVal [out,retval] The type of the diagram without spaces (ie ClassDiagram)
232:             */
233:            public String getDiagramTypeNameNoSpaces(IDiagram pDiagram) {
234:                String diaTypeName = "";
235:                if (pDiagram != null) {
236:                    String str = pDiagram.getDiagramKind2();
237:                    diaTypeName = getDiagramTypeNameNoSpaces(str);
238:                }
239:                return diaTypeName;
240:            }
241:
242:            /**
243:             * Returns the diagram kind without spaces (ie ClassDiagram) for the argument diagram kind (ie Class Diagram)
244:             *
245:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
246:             * @param pVal [out,retval] The type of the diagram without spaces (ie ClassDiagram)
247:             */
248:            public String getDiagramTypeNameNoSpaces(String sDiagramTypeName) {
249:                String retVal = "";
250:
251:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
252:                query += sDiagramTypeName;
253:                query += "']";
254:
255:                String attributeToFind = "DiagramTypeNameNoSpaces";
256:
257:                retVal = getStringAttributeValue(query, attributeToFind);
258:
259:                return retVal;
260:            }
261:
262:            /**
263:             * Returns the diagram kind without spaces (ie Class Diagram) for the argument enumeration
264:             *
265:             * @param pDiagram [in] The diagram enumeration which we need to convert to a type string without spaces (ie
266:             * Class Diagram to ClassDiagram.
267:             * @param pVal [out,retval] The type of the diagram without spaces (ie ClassDiagram)
268:             */
269:            public String getDiagramTypeNameNoSpaces(int nDiagramKind) {
270:                String retVal = "";
271:
272:                String query = "//DiagramTypes/DiagramType[@DiagramKindEnumValue='";
273:                query += nDiagramKind;
274:                query += "']";
275:
276:                String attributeToFind = "DiagramTypeNameNoSpaces";
277:
278:                retVal = getStringAttributeValue(query, attributeToFind);
279:
280:                return retVal;
281:            }
282:
283:            /**
284:             * Returns short diagram type for this long diagram type (ie Class Diagram to CLD)
285:             *
286:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
287:             * @param pVal [out,retval] The short kind of this diagram (ie CLD)
288:             */
289:            public String getShortDiagramTypeName(String sDiagramTypeName) {
290:                String retVal = "";
291:
292:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
293:                query += sDiagramTypeName;
294:                query += "']";
295:
296:                String attributeToFind = "ShortDiagramTypeName";
297:
298:                retVal = getStringAttributeValue(query, attributeToFind);
299:
300:                return retVal;
301:            }
302:
303:            /**
304:             * The UML Type for this diagram (ie StructuralDiagram)
305:             *
306:             * @param pDiagram [in] The diagram for which to get the type sans spaces
307:             * @param pVal [out,retval] The uml type of the diagram (ie StructuralDiagram)
308:             */
309:            public String getUMLType(IDiagram pDiagram) {
310:                String diaTypeName = getDiagramTypeName(pDiagram);
311:                String umlVal = getUMLType(diaTypeName);
312:                return umlVal;
313:            }
314:
315:            /**
316:             * The UML Type for this diagram (ie StructuralDiagram)
317:             *
318:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
319:             * @param pVal [out,retval] The uml type of the diagram (ie StructuralDiagram)
320:             */
321:            public String getUMLType(String sDiagramTypeName) {
322:                String retVal = "";
323:
324:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
325:                query += sDiagramTypeName;
326:                query += "']";
327:
328:                String attributeToFind = "UMLTypeName";
329:
330:                retVal = getStringAttributeValue(query, attributeToFind);
331:
332:                return retVal;
333:            }
334:
335:            /**
336:             * The UML Type for this diagram (ie StructuralDiagram)
337:             *
338:             * @param pDiagram [in] The diagram enumeration which we need to convert to a short type string (ie
339:             * Class Diagram to CLD.
340:             * @param pVal [out,retval] The uml type of the diagram (ie StructuralDiagram)
341:             */
342:            public String getUMLType(int nDiagramKind) {
343:                String diaTypeName = getDiagramTypeName(nDiagramKind);
344:                String umlType = getUMLType(diaTypeName);
345:                return umlType;
346:            }
347:
348:            /**
349:             * The diagram engine controlling this behavior (ClassDiagram)
350:             *
351:             * @param pDiagram [in] The diagram for which to get the type sans spaces
352:             * @param pVal [out,retval] The metatype of the engine that controls this diagrams behavior
353:             */
354:            public String getDiagramEngine(IDiagram pDiagram) {
355:                String diaTypeName = getDiagramTypeName(pDiagram);
356:                String engine = getDiagramEngine(diaTypeName);
357:                return engine;
358:            }
359:
360:            /**
361:             * The diagram engine controlling this behavior (ClassDiagram)
362:             *
363:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
364:             * @param pVal [out,retval] The metatype of the engine that controls this diagrams behavior
365:             */
366:            public String getDiagramEngine(String sDiagramTypeName) {
367:                String retVal = "";
368:
369:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
370:                query += sDiagramTypeName;
371:                query += "']";
372:
373:                String attributeToFind = "DiagramEngine";
374:
375:                retVal = getStringAttributeValue(query, attributeToFind);
376:
377:                return retVal;
378:            }
379:
380:            /**
381:             * The diagram engine controlling this behavior (ClassDiagram)
382:             *
383:             * @param nDiagramKind [in] The diagram enumeration which we need to convert to diagram engine type
384:             * @param pVal [out,retval] The metatype of the engine that controls this diagrams behavior
385:             */
386:            public String getDiagramEngine(int nDiagramKind) {
387:                String diaTypeName = getDiagramTypeName(nDiagramKind);
388:                String engine = getDiagramEngine(diaTypeName);
389:                return engine;
390:            }
391:
392:            /**
393:             * The open diagram icon
394:             *
395:             * @param pDiagram [in] The diagram for which to get the icon name in CommonResources
396:             * @param pVal [out,retval] The name of the icon in the CommonResources
397:             */
398:            public String getOpenIcon(IDiagram pDiagram) {
399:                String diaTypeName = getDiagramTypeName(pDiagram);
400:                String icon = getOpenIcon(diaTypeName);
401:                return icon;
402:            }
403:
404:            /**
405:             * The open diagram icon
406:             *
407:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
408:             * @param pVal [out,retval] The name of the icon in the CommonResources
409:             */
410:            public String getOpenIcon(String sDiagramTypeName) {
411:                String retVal = "";
412:
413:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
414:                query += sDiagramTypeName;
415:                query += "']";
416:
417:                String attributeToFind = "OpenIcon";
418:
419:                retVal = getStringAttributeValue(query, attributeToFind);
420:
421:                return retVal;
422:            }
423:
424:            /**
425:             * The open diagram icon
426:             *
427:             * @param nDiagramKind [in] The diagram enumeration which we need to convert to diagram engine type
428:             * @param pVal [out,retval] The name of the icon in the CommonResources
429:             */
430:            public String getOpenIcon(int nDiagramKind) {
431:                String diaTypeName = getDiagramTypeName(nDiagramKind);
432:                String icon = getOpenIcon(diaTypeName);
433:                return icon;
434:            }
435:
436:            /**
437:             * The closed diagram icon
438:             *
439:             * @param pDiagram [in] The diagram for which to get the icon name in CommonResources
440:             * @param pVal [out,retval] The name of the icon in the CommonResources
441:             */
442:            public String getClosedIcon(IDiagram pDiagram) {
443:                String diaTypeName = getDiagramTypeName(pDiagram);
444:                String icon = getClosedIcon(diaTypeName);
445:                return icon;
446:            }
447:
448:            /**
449:             * The closed diagram icon
450:             *
451:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
452:             * @param pVal [out,retval] The name of the icon in the CommonResources
453:             */
454:            public String getClosedIcon(String sDiagramTypeName) {
455:                String retVal = "";
456:
457:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
458:                query += sDiagramTypeName;
459:                query += "']";
460:
461:                String attributeToFind = "ClosedIcon";
462:
463:                retVal = getStringAttributeValue(query, attributeToFind);
464:
465:                return retVal;
466:            }
467:
468:            /**
469:             * The closed diagram icon
470:             *
471:             * @param nDiagramKind [in] The diagram enumeration which we need to convert to diagram engine type
472:             * @param pVal [out,retval] The name of the icon in the CommonResources
473:             */
474:            public String getClosedIcon(int nDiagramKind) {
475:                String diaTypeName = getDiagramTypeName(nDiagramKind);
476:                String icon = getClosedIcon(diaTypeName);
477:                return icon;
478:            }
479:
480:            /**
481:             * The broken diagram icon
482:             *
483:             * @param pDiagram [in] The diagram for which to get the icon name in CommonResources
484:             * @param pVal [out,retval] The name of the icon in the CommonResources
485:             */
486:            public String getBrokenIcon(IDiagram pDiagram) {
487:                String diaTypeName = getDiagramTypeName(pDiagram);
488:                String icon = getBrokenIcon(diaTypeName);
489:                return icon;
490:            }
491:
492:            /**
493:             * The broken diagram icon
494:             *
495:             * @param sDiagramTypeName [in] The diagram type name, with spaces (ie Class Diagram)
496:             * @param pVal [out,retval] The name of the icon in the CommonResources
497:             */
498:            public String getBrokenIcon(String sDiagramTypeName) {
499:                String retVal = "";
500:
501:                String query = "//DiagramTypes/DiagramType[@DiagramTypeName='";
502:                query += sDiagramTypeName;
503:                query += "']";
504:
505:                String attributeToFind = "BrokenIcon";
506:
507:                retVal = getStringAttributeValue(query, attributeToFind);
508:
509:                return retVal;
510:            }
511:
512:            /**
513:             * The broken diagram icon
514:             *
515:             * @param nDiagramKind [in] The diagram enumeration which we need to convert to diagram engine type
516:             * @param pVal [out,retval] The name of the icon in the CommonResources
517:             */
518:            public String getBrokenIcon(int nDiagramKind) {
519:                String diaTypeName = getDiagramTypeName(nDiagramKind);
520:                String icon = getBrokenIcon(diaTypeName);
521:                return icon;
522:            }
523:
524:        }
ww___w_.__j___av___a_2s_.__co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.