Source Code Cross Referenced for BOAssociationRoleImpl.java in  » UML » MetaBoss » com » metaboss » sdlctools » domains » enterprisemodel » impl » 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.domains.enterprisemodel.impl 
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.domains.enterprisemodel.impl;
016:
017:        import javax.naming.Context;
018:        import javax.naming.InitialContext;
019:        import javax.naming.NamingException;
020:
021:        import com.metaboss.enterprise.bo.BOException;
022:        import com.metaboss.enterprise.bo.BOIllegalArgumentException;
023:        import com.metaboss.enterprise.bo.BOInvalidOperationForObjectException;
024:        import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
025:        import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
026:        import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
027:        import com.metaboss.enterprise.ps.PSException;
028:        import com.metaboss.sdlctools.domains.enterprisemodel.BOAssociation;
029:        import com.metaboss.sdlctools.domains.enterprisemodel.BOAssociationRole;
030:        import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
031:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSAssociationRole;
032:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.STAssociationRole;
033:        import com.metaboss.sdlctools.types.enterprisemodel.AssociationRoleCardinality;
034:        import com.metaboss.sdlctools.types.enterprisemodel.AssociationRoleStereotype;
035:        import com.oldboss.framework.bo.BOTransaction;
036:        import com.oldboss.framework.bo.impl.BOObjectImpl;
037:
038:        public class BOAssociationRoleImpl extends BOObjectImpl implements 
039:                BOAssociationRole {
040:            private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
041:            private BOAssociation mAssociation = null;
042:            private Boolean mIsRoleA = null; // Together with association forms the unique key for the role
043:            private STAssociationRole mDetails = null;
044:
045:            /* Instance creator */
046:            public static BOAssociationRole createInstanceForExisting(
047:                    BOMetaBossDomainImpl pMetaBossDomainImpl,
048:                    BOAssociation pAssociation, boolean pIsRoleA)
049:                    throws BOException {
050:                // Validate essential input arguments
051:                if (pAssociation == null)
052:                    throw new BOIllegalArgumentException(
053:                            "Empty association reference");
054:                String lCacheKey = pAssociation.getRef()
055:                        + (pIsRoleA ? ".A" : ".B");
056:                // See if we have this object in cache
057:                BOAssociationRoleImpl lImpl = (BOAssociationRoleImpl) pMetaBossDomainImpl
058:                        .retrieveExistingBOInstance(BOAssociationRole.class,
059:                                lCacheKey);
060:                if (lImpl != null)
061:                    return lImpl;
062:                lImpl = new BOAssociationRoleImpl();
063:                lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
064:                lImpl.mAssociation = pAssociation;
065:                lImpl.mIsRoleA = new Boolean(pIsRoleA);
066:                lImpl.setupForExisting();
067:                pMetaBossDomainImpl.saveNewBOInstance(BOAssociationRole.class,
068:                        lCacheKey, lImpl);
069:                return lImpl;
070:            }
071:
072:            /* Instance creator */
073:            public static BOAssociationRole createInstanceForExisting(
074:                    BOMetaBossDomainImpl pMetaBossDomainImpl, String pRoleRef)
075:                    throws BOException {
076:                // Validate essential input arguments
077:                if (pRoleRef == null || pRoleRef.length() == 0)
078:                    throw new BOIllegalArgumentException(
079:                            "Empty AssociationRoleRef");
080:                // See if we have this object in cache
081:                // Key is AssociationRoleRef.A or AssociationRoleRef.B
082:                int lLastDot = pRoleRef.lastIndexOf('.');
083:                if (lLastDot <= 0)
084:                    throw new BOIllegalArgumentException(
085:                            "Invalid format of AssociationRoleRef: " + pRoleRef);
086:                String lAssociationRef = pRoleRef.substring(0, lLastDot);
087:                // Load the role details from the database and create the BO if necessary    
088:                STAssociationRole lDetails = null;
089:                try {
090:                    Context ctx = new InitialContext();
091:                    PSAssociationRole lPs = (PSAssociationRole) ctx
092:                            .lookup(PSAssociationRole.COMPONENT_URL);
093:                    if ((lDetails = lPs.getAssociationRole(pRoleRef)) == null)
094:                        throw new BOException(
095:                                "AssociationRole not found. AssociationRoleRef: "
096:                                        + pRoleRef);
097:                } catch (NamingException e) {
098:                    throw new BONamingAndDirectoryServiceInvocationException(
099:                            "", e);
100:                } catch (PSException e) {
101:                    throw new BOPersistenceServiceInvocationException("", e);
102:                }
103:                String lCacheKey = lAssociationRef
104:                        + (lDetails.IsRoleA ? ".A" : ".B");
105:                BOAssociationRoleImpl lImpl = (BOAssociationRoleImpl) pMetaBossDomainImpl
106:                        .retrieveExistingBOInstance(BOAssociationRole.class,
107:                                lCacheKey);
108:                if (lImpl != null)
109:                    return lImpl;
110:                lImpl = new BOAssociationRoleImpl();
111:                lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
112:                lImpl.mIsRoleA = new Boolean(lDetails.IsRoleA);
113:                lImpl.mDetails = lDetails;
114:                lImpl.mAssociation = BOAssociationImpl
115:                        .createInstanceForExisting(pMetaBossDomainImpl,
116:                                lAssociationRef);
117:                lImpl.setupForExisting();
118:                pMetaBossDomainImpl.saveNewBOInstance(BOAssociationRole.class,
119:                        lCacheKey, lImpl);
120:                return lImpl;
121:            }
122:
123:            /* Instance creator */
124:            public static BOAssociationRole createInstanceForNew(
125:                    BOTransaction pTransaction,
126:                    BOMetaBossDomainImpl pMetaBossDomainImpl,
127:                    BOAssociation pAssociation, boolean pIsRoleA)
128:                    throws BOException {
129:                String lCacheKey = pAssociation.getRef()
130:                        + (pIsRoleA ? ".A" : ".B");
131:                // See if we have this object in cache already
132:                BOAssociationRoleImpl lImpl = (BOAssociationRoleImpl) pMetaBossDomainImpl
133:                        .retrieveExistingBOInstance(BOAssociationRole.class,
134:                                lCacheKey);
135:                if (lImpl != null)
136:                    throw new BOIllegalArgumentException("AssociationRole"
137:                            + (pIsRoleA ? "A" : "B")
138:                            + " already exists. AssociationRef: "
139:                            + pAssociation.getRef());
140:                lImpl = new BOAssociationRoleImpl();
141:                lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
142:                lImpl.mAssociation = pAssociation;
143:                lImpl.mIsRoleA = new Boolean(pIsRoleA);
144:                lImpl.setupForNew(pTransaction);
145:                pMetaBossDomainImpl.saveNewBOInstance(BOAssociationRole.class,
146:                        lCacheKey, lImpl);
147:                return lImpl;
148:            }
149:
150:            /* Retrieves association this role belongs to. Together with name
151:             *  forms primary key for this object */
152:            public BOAssociation getAssociation() throws BOException {
153:                return mAssociation;
154:            }
155:
156:            /* Retrieves role's ref. Ref is globally unique */
157:            public String getRef() throws BOException {
158:                return getAssociation().getRef() + "." + getName();
159:            }
160:
161:            /* Retrieves role's position. */
162:            public boolean isRoleA() throws BOException {
163:                return mIsRoleA.booleanValue();
164:            }
165:
166:            /* Retrieves element's name. Name is only unique within parent entity */
167:            public String getName() throws BOException {
168:                loadDetailsIfNecessary();
169:                return mDetails.Name;
170:            }
171:
172:            /* Sets singular role name. */
173:            public void setName(String pName) throws BOException {
174:                if (!isBeingEdited())
175:                    throw new BOInvalidOperationForReadOnlyObjectException();
176:                mDetails.Name = pName;
177:            }
178:
179:            /* Retrieves plural role name */
180:            public String getPluralName() throws BOException {
181:                loadDetailsIfNecessary();
182:                return mDetails.PluralName;
183:            }
184:
185:            /* Sets plural role name. */
186:            public void setPluralName(String pPluralName) throws BOException {
187:                if (!isBeingEdited())
188:                    throw new BOInvalidOperationForReadOnlyObjectException();
189:                mDetails.PluralName = pPluralName;
190:            }
191:
192:            /* Retrieves entity for which this role is described */
193:            public BOEntity getEntity() throws BOException {
194:                loadDetailsIfNecessary();
195:                return BOEntityImpl.createInstanceForExisting(
196:                        mMetaBossDomainImpl, mDetails.EntityRef);
197:            }
198:
199:            /* Sets entity for which this role is described. This method
200:             * will remove the role from the entity it was previously associated with and
201:             * add this role to the entity passed to it. */
202:            public void setEntity(BOEntity pEntity) throws BOException {
203:                if (!isBeingEdited())
204:                    throw new BOInvalidOperationForReadOnlyObjectException();
205:                if (pEntity == null)
206:                    throw new BOIllegalArgumentException(
207:                            "Entity reference in AssociationRole is mandatory and can not be set to null");
208:                // We need to remove our sibling role from the old entity
209:                BOAssociationRole lSiblingAssociationRole = isRoleA() ? mAssociation
210:                        .getRoleB()
211:                        : mAssociation.getRoleA();
212:                BOEntityAssociationRoleListImpl lOldEntityAssociationRoleList = (BOEntityAssociationRoleListImpl) BOEntityImpl
213:                        .createInstanceForExisting(mMetaBossDomainImpl,
214:                                mDetails.EntityRef).getAssociationRoles();
215:                lOldEntityAssociationRoleList.beginEdit(fetchTransaction());
216:                lOldEntityAssociationRoleList
217:                        .removeAssociationRole(lSiblingAssociationRole);
218:                // Now we need to add sibling association role to the new entity
219:                mDetails.EntityRef = pEntity.getRef();
220:                BOEntityAssociationRoleListImpl lNewEntityAssociationRoleList = (BOEntityAssociationRoleListImpl) pEntity
221:                        .getAssociationRoles();
222:                lNewEntityAssociationRoleList.beginEdit(fetchTransaction());
223:                lNewEntityAssociationRoleList
224:                        .addAssociationRole(lSiblingAssociationRole);
225:            }
226:
227:            /* Returns element's  description */
228:            public String getDescription() throws BOException {
229:                loadDetailsIfNecessary();
230:                return mDetails.Description;
231:            }
232:
233:            /* Sets description */
234:            public void setDescription(String pDescription) throws BOException {
235:                if (!isBeingEdited())
236:                    throw new BOInvalidOperationForReadOnlyObjectException();
237:                mDetails.Description = pDescription;
238:            }
239:
240:            /** Retrieves cardinality for this role */
241:            public AssociationRoleCardinality getCardinality()
242:                    throws BOException {
243:                loadDetailsIfNecessary();
244:                return mDetails.Cardinality;
245:            }
246:
247:            /** Sets cardinality */
248:            public void setCardinality(AssociationRoleCardinality pCardinality)
249:                    throws BOException {
250:                if (!isBeingEdited())
251:                    throw new BOInvalidOperationForReadOnlyObjectException();
252:                mDetails.Cardinality = pCardinality;
253:            }
254:
255:            /* Returns stereotype for this association role */
256:            public AssociationRoleStereotype getStereotype() throws BOException {
257:                loadDetailsIfNecessary();
258:                return mDetails.Stereotype;
259:            }
260:
261:            /** Sets stereotype */
262:            public void setStereotype(AssociationRoleStereotype pStereotype)
263:                    throws BOException {
264:                if (!isBeingEdited())
265:                    throw new BOInvalidOperationForReadOnlyObjectException();
266:                mDetails.Stereotype = pStereotype;
267:            }
268:
269:            protected void onBeginEdit() throws BOException {
270:                // Fully load the object
271:                loadDetailsIfNecessary();
272:            }
273:
274:            protected void onDelete() throws BOException {
275:                throw new BOInvalidOperationForObjectException(
276:                        "BOAssociationRole can not be deleted or created separately from BOAssociation.");
277:            }
278:
279:            private void loadDetailsIfNecessary() throws BOException {
280:                if (mDetails == null) {
281:                    try {
282:                        // Get the instance of the enterprise ps home via jndi
283:                        Context lCtx = new InitialContext();
284:                        PSAssociationRole lPs = (PSAssociationRole) lCtx
285:                                .lookup(PSAssociationRole.COMPONENT_URL);
286:                        if ((mDetails = lPs.getAssociationRole(mAssociation
287:                                .getRef(), mIsRoleA.booleanValue())) == null)
288:                            throw new BOException("AssociationRole"
289:                                    + (mIsRoleA.booleanValue() ? "A" : "B")
290:                                    + " not found. AssociationRef: "
291:                                    + mAssociation.getRef());
292:                    } catch (NamingException e) {
293:                        throw new BONamingAndDirectoryServiceInvocationException(
294:                                "", e);
295:                    } catch (PSException e) {
296:                        throw new BOPersistenceServiceInvocationException("", e);
297:                    }
298:                }
299:            }
300:
301:            /* Encapsulates commit action by this object */
302:            protected void onCommitCreation() throws BOException {
303:                try {
304:                    // Get the instance of the enterprise ps home via jndi
305:                    Context lCtx = new InitialContext();
306:                    PSAssociationRole lPs = (PSAssociationRole) lCtx
307:                            .lookup(PSAssociationRole.COMPONENT_URL);
308:                    lPs.insertAssociationRole(mAssociation.getRef(), mDetails);
309:                } catch (NamingException e) {
310:                    throw new BONamingAndDirectoryServiceInvocationException(
311:                            "", e);
312:                } catch (PSException e) {
313:                    throw new BOPersistenceServiceInvocationException("", e);
314:                }
315:            }
316:
317:            /* Encapsulates commit action by this object */
318:            protected void onCommitUpdate() throws BOException {
319:                try {
320:                    // Get the instance of the enterprise ps home via jndi
321:                    Context lCtx = new InitialContext();
322:                    PSAssociationRole lPs = (PSAssociationRole) lCtx
323:                            .lookup(PSAssociationRole.COMPONENT_URL);
324:                    lPs.updateAssociationRole(mAssociation.getRef(), mDetails);
325:                } catch (NamingException e) {
326:                    throw new BONamingAndDirectoryServiceInvocationException(
327:                            "", e);
328:                } catch (PSException e) {
329:                    throw new BOPersistenceServiceInvocationException("", e);
330:                }
331:            }
332:
333:            /** Overriden to provide check reference equality */
334:            public boolean equals(Object pOther) {
335:                if (pOther == null)
336:                    return false;
337:                if (!(pOther instanceof  BOAssociationRoleImpl))
338:                    return false;
339:                return ((BOAssociationRoleImpl) pOther).mAssociation
340:                        .equals(mAssociation)
341:                        && ((BOAssociationRoleImpl) pOther).mIsRoleA
342:                                .equals(mIsRoleA);
343:            }
344:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.