Source Code Cross Referenced for ModelElement.java in  » UML » AndroMDA-3.2 » org » andromda » core » cartridge » template » 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 » UML » AndroMDA 3.2 » org.andromda.core.cartridge.template 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.core.cartridge.template;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.Iterator;
006:
007:        import org.andromda.core.common.ClassUtils;
008:        import org.andromda.core.common.ExceptionUtils;
009:        import org.andromda.core.common.Introspector;
010:        import org.andromda.core.profile.Profile;
011:        import org.apache.commons.lang.StringUtils;
012:
013:        /**
014:         * Represents a single template <modelElement/> nested within the <modelElements/> element. It stores the
015:         * actual metafacade instances which match the model element criteria (i.e. stereotype, type, etc) defined by this
016:         * instance.
017:         *
018:         * @author Chad Brandon
019:         * @see ModelElements
020:         */
021:        public class ModelElement {
022:            private String stereotype;
023:
024:            /**
025:             * Gets the stereotype of this modelElement.
026:             *
027:             * @return Returns the stereotype.
028:             */
029:            public String getStereotype() {
030:                return Profile.instance().get(this .stereotype);
031:            }
032:
033:            /**
034:             * Returns <code>true</code> or <code>false</code> depending on whether or not this model element has a stereotype
035:             * defined.
036:             *
037:             * @return true/false
038:             */
039:            public boolean hasStereotype() {
040:                return this .stereotype != null;
041:            }
042:
043:            /**
044:             * Stores the types defined for this model element.
045:             */
046:            private final Collection types = new ArrayList();
047:
048:            /**
049:             * Gets all types associated with this model element.
050:             *
051:             * @return the collection of types.
052:             */
053:            public Collection getTypes() {
054:                return this .types;
055:            }
056:
057:            /**
058:             * Returns <code>true</code> or <code>false</code> depending on whether or not this model element has any type
059:             * elements defined.
060:             *
061:             * @return true/false
062:             */
063:            public boolean hasTypes() {
064:                return !this .getTypes().isEmpty();
065:            }
066:
067:            /**
068:             * Sets the stereotype of the ModelElement.
069:             *
070:             * @param stereotype The stereotype to set.
071:             */
072:            public void setStereotype(final String stereotype) {
073:                this .stereotype = stereotype;
074:                ExceptionUtils.checkEmpty("stereotype", this .stereotype);
075:            }
076:
077:            /**
078:             * Adds the <code>type</code> to the collection of types belonging to this model element.
079:             *
080:             * @param type the {@link Type}instance.
081:             */
082:            public void addType(final Type type) {
083:                ExceptionUtils.checkNull("type", type);
084:                this .types.add(type);
085:            }
086:
087:            /**
088:             * Stores the name of the variable for this model element.
089:             */
090:            private String variable;
091:
092:            /**
093:             * Gets the variable stereotype of this modelElement (this is what is made available to a template during
094:             * processing).
095:             *
096:             * @return Returns the variable.
097:             */
098:            public String getVariable() {
099:                return this .variable;
100:            }
101:
102:            /**
103:             * Sets the variable name.
104:             *
105:             * @param variable The variable to set.
106:             */
107:            public void setVariable(final String variable) {
108:                this .variable = StringUtils.trimToEmpty(variable);
109:            }
110:
111:            /**
112:             * The metafacades for this model element.
113:             */
114:            private Collection metafacades = new ArrayList();
115:
116:            /**
117:             * Sets the current metafacades that belong to this ModelElement instance.
118:             *
119:             * @param metafacades the collection of metafacdes
120:             */
121:            public void setMetafacades(final Collection metafacades) {
122:                ExceptionUtils.checkNull("metafacades", metafacades);
123:                this .metafacades = metafacades;
124:                this .applyTypeFiltering();
125:            }
126:
127:            /**
128:             * Gets the metafacades that belong to this ModelElement instance. These are the actual elements from the model.
129:             *
130:             * @return the collection of metafacades.
131:             */
132:            public Collection getMetafacades() {
133:                return this .metafacades;
134:            }
135:
136:            /**
137:             * Applies any filtering by any types specified within this model element.
138:             */
139:            private void applyTypeFiltering() {
140:                if (this .hasTypes()) {
141:                    for (final Iterator iterator = this .metafacades.iterator(); iterator
142:                            .hasNext();) {
143:                        if (!accept(iterator.next())) {
144:                            iterator.remove();
145:                        }
146:                    }
147:                }
148:            }
149:
150:            /**
151:             * Checks the <code>object</code> to see whether or not its acceptable. It matches on the types and each type's
152:             * properties. <strong>NOTE:</strong> protected visibility to improve performance from within {@link
153:             * #applyTypeFiltering()}
154:             *
155:             * @param metafacade the metafacade to check
156:             * @return true/false
157:             */
158:            private boolean accept(final Object metafacade) {
159:                boolean accept = true;
160:                for (final Iterator iterator = this .types.iterator(); iterator
161:                        .hasNext()
162:                        && accept;) {
163:                    final Type type = (Type) iterator.next();
164:                    if (StringUtils.isNotBlank(type.getName())) {
165:                        try {
166:                            accept = ClassUtils.loadClass(type.getName())
167:                                    .isAssignableFrom(metafacade.getClass());
168:
169:                            // if the type matches the name, continue
170:                            if (accept) {
171:                                for (final Iterator properties = type
172:                                        .getProperties().iterator(); properties
173:                                        .hasNext();) {
174:                                    final Type.Property property = (Type.Property) properties
175:                                            .next();
176:                                    accept = Introspector.instance()
177:                                            .containsValidProperty(metafacade,
178:                                                    property.getName(),
179:                                                    property.getValue());
180:                                    if (!accept) {
181:                                        // break out of the loop on the first invalid
182:                                        // property since all propertie should be valid.
183:                                        break;
184:                                    }
185:                                }
186:                            }
187:                        } catch (final Throwable throwable) {
188:                            accept = false;
189:                        }
190:                    }
191:                }
192:                return accept;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.