Source Code Cross Referenced for ModelAssistantImpl.java in  » UML » MetaBoss » com » metaboss » sdlctools » models » modelassistant » metabossmodel » codeconstraints » 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 » MetaBoss » com.metaboss.sdlctools.models.modelassistant.metabossmodel.codeconstraints 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.sdlctools.models.modelassistant.metabossmodel.codeconstraints;
016:
017:        import java.util.ArrayList;
018:        import java.util.Arrays;
019:        import java.util.Collection;
020:        import java.util.Collections;
021:        import java.util.HashSet;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Set;
025:
026:        import javax.jmi.reflect.ConstraintViolationException;
027:        import javax.jmi.reflect.RefObject;
028:        import javax.naming.Context;
029:        import javax.naming.InitialContext;
030:        import javax.naming.NamingException;
031:
032:        import com.metaboss.sdlctools.models.ModelAssistant;
033:        import com.metaboss.sdlctools.models.ModelRepository;
034:        import com.metaboss.sdlctools.models.ModelRepositoryException;
035:        import com.metaboss.sdlctools.models.ModelRepositoryInternalException;
036:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
037:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
038:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
039:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageFieldClass;
040:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
041:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityClass;
042:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
043:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
044:
045:        /** Implementation of the assistant to MetaBoss models.
046:         * Looks after some constraints imposed by Java and particular style of code generation imposed by MetaBoss generators
047:         * such as:
048:         * <UL>
049:         * <LI>Selector name must not match the name of any entity, which is a subtype to the entity, which owns this selector. This is because
050:         * MetaBoss generates select&lt;Supertype Entity Plural Name&gt;() method used to narrow collection down to entities of a particular type.</LI>
051:         * </UL> */
052:        public class ModelAssistantImpl implements  ModelAssistant {
053:            private static final Set sReservedMessageFieldNames = new HashSet(
054:                    Arrays.asList(new String[] { "Id", "MessageArguments",
055:                            "MessageText", "MessageType",
056:                            "TextResourcePackage", "TextResourceId" }));
057:
058:            // This implementation logs absolutely nothing. It is used as default, so
059:            // we do not have to check for nulls everywhere in the code
060:            private static ModelAssistant.ModelActionsLogger sNullModelActionsLogger = new ModelAssistant.ModelActionsLogger() {
061:                public void info(String pModelName, String pMessage) {
062:                }
063:
064:                public void warn(String pModelName, String pMessage) {
065:                }
066:
067:                public void error(String pModelName, String pMessage) {
068:                }
069:            };
070:
071:            ModelAssistant.ModelActionsLogger mActionsLogger = sNullModelActionsLogger;
072:            // Variables below are cached for whole session with the model regardless of the kind of model it is
073:            ModelRepository mModelRepository = null;
074:            MetaBossModelPackage mRootPackage = null;
075:            EnterpriseModelPackage mEnterpriseModel = null;
076:            SystemImplementationModelPackage mSystemImplementationModel = null;
077:            EntityClass mEntityClass = null;
078:            MessageFieldClass mMessageFieldClass = null;
079:
080:            // As per interface 
081:            public void assignToModel(String pModelName)
082:                    throws ModelRepositoryException {
083:                try {
084:                    Context lContext = new InitialContext();
085:                    mModelRepository = (ModelRepository) lContext
086:                            .lookup(ModelRepository.COMPONENT_URL);
087:                    mRootPackage = (MetaBossModelPackage) mModelRepository
088:                            .getModelExtent(pModelName);
089:                    mEnterpriseModel = mRootPackage.getEnterpriseModel();
090:                    mMessageFieldClass = mEnterpriseModel.getMessageField();
091:                    mSystemImplementationModel = mEnterpriseModel
092:                            .getSystemImplementationModel();
093:                    mEntityClass = mSystemImplementationModel.getEntity();
094:                } catch (NamingException e) {
095:                    throw new ModelRepositoryInternalException(
096:                            "Unable to looklup repository", e);
097:                }
098:            }
099:
100:            // As per interface 
101:            public void dismissFromModel(String pModelName) {
102:                mModelRepository = null;
103:                mRootPackage = null;
104:                mEnterpriseModel = null;
105:                mMessageFieldClass = null;
106:                mSystemImplementationModel = null;
107:                mEntityClass = null;
108:            }
109:
110:            // Assign the actions loger to this assistantis Assistant to look after a particular model.
111:            public void setActionsLogger(String pModelName,
112:                    ModelAssistant.ModelActionsLogger pModelActionsLogger)
113:                    throws ModelRepositoryException {
114:                mActionsLogger = pModelActionsLogger != null ? pModelActionsLogger
115:                        : sNullModelActionsLogger;
116:            }
117:
118:            // As per interface 
119:            public Collection verifyConstraints(String pModelName) {
120:                List lViolations = new ArrayList();
121:                // Constaint #1 - check that all selectors have a name not matching a plural name of all owner entity supertypes
122:                {
123:                    for (Iterator lEntitiesIterator = mEntityClass
124:                            .refAllOfType().iterator(); lEntitiesIterator
125:                            .hasNext();) {
126:                        Entity lEntity = (Entity) lEntitiesIterator.next();
127:                        Collection lSelectors = lEntity.getSelectors();
128:                        if (!lSelectors.isEmpty()) {
129:                            Collection lSubtypeEntities = lEntity
130:                                    .getCombinedSubtypes();
131:                            if (!lSubtypeEntities.isEmpty()) {
132:                                for (Iterator lSelectorsIterator = lSelectors
133:                                        .iterator(); lSelectorsIterator
134:                                        .hasNext();) {
135:                                    Selector lSelector = (Selector) lSelectorsIterator
136:                                            .next();
137:                                    for (Iterator lSubtypeEntitiesIterator = lSubtypeEntities
138:                                            .iterator(); lSubtypeEntitiesIterator
139:                                            .hasNext();) {
140:                                        Entity lSubtypeEntity = (Entity) lSubtypeEntitiesIterator
141:                                                .next();
142:                                        if (lSelector.getName().equals(
143:                                                lSubtypeEntity.getPluralName())) {
144:                                            lViolations
145:                                                    .add(new ConstraintViolationException(
146:                                                            lSelector,
147:                                                            lSelector
148:                                                                    .refMetaObject(),
149:                                                            "Selector name must not match plural name of any Entity which is a subtype to the Entity which owns the Selector."));
150:                                            lViolations
151:                                                    .add(new ConstraintViolationException(
152:                                                            lSubtypeEntity,
153:                                                            lSubtypeEntity
154:                                                                    .refMetaObject(),
155:                                                            "Entity plural name must not match the name of any selector owned by any Entity which is a supertype to this Entity."));
156:                                        }
157:                                    }
158:                                }
159:                            }
160:                        }
161:                    }
162:                }
163:                // Constaint #2 - Message Fields can not have certain names
164:                {
165:                    for (Iterator lMessageFieldsIterator = mMessageFieldClass
166:                            .refAllOfType().iterator(); lMessageFieldsIterator
167:                            .hasNext();) {
168:                        MessageField lMessageField = (MessageField) lMessageFieldsIterator
169:                                .next();
170:                        if (sReservedMessageFieldNames.contains(lMessageField
171:                                .getName())) {
172:                            lViolations
173:                                    .add(new ConstraintViolationException(
174:                                            lMessageField,
175:                                            lMessageField.refMetaObject(),
176:                                            "Name '"
177:                                                    + lMessageField.getName()
178:                                                    + "' is reserved and can not be used as the name of the Message Field."));
179:                        }
180:                    }
181:                }
182:                // Return what we have
183:                return Collections.unmodifiableCollection(lViolations);
184:            }
185:
186:            // As per interface 
187:            public void rectifyModel(String pModelName) {
188:            }
189:
190:            // As per interface 
191:            public void onModelElementAttributeBeingUpdated(String pModelName,
192:                    RefObject pModelElementBeingUpdated, String pAttributeName,
193:                    Object pOldAttributeValue, Object pNewAttributeValue)
194:                    throws ModelRepositoryException {
195:                // Nothing to do for now
196:            }
197:
198:            // As per interface		
199:            public void onModelElementReferenceBeingUpdated(String pModelName,
200:                    RefObject pModelElementBeingUpdated, String pReferenceName,
201:                    RefObject pReferencedModelElementToRemove,
202:                    RefObject pReferencedModelElementToAdd)
203:                    throws ModelRepositoryException {
204:            }
205:
206:            // As per interface 
207:            public void onModelElementBeingDeleted(String pModelName,
208:                    RefObject pModelElementToBeDeleted)
209:                    throws ModelRepositoryException {
210:                // Nothing to do for now
211:            }
212:
213:            // As per interface 
214:            public void onModelElementJustCreated(String pModelName,
215:                    RefObject pModelElementJustCreated)
216:                    throws ModelRepositoryException {
217:                // Nothing to do for now
218:            }
219:        }
w_w__w___.__j_a__v___a_2__s_.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.