Source Code Cross Referenced for IncludedEnterpriseReferenceImpl.java in  » UML » MetaBoss » com » metaboss » sdlctools » models » impl » metabossmodel » designlibrarymodel » 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.impl.metabossmodel.designlibrarymodel 
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.impl.metabossmodel.designlibrarymodel;
016:
017:        import java.io.File;
018:        import java.io.FileOutputStream;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.net.MalformedURLException;
022:        import java.net.URL;
023:        import java.util.zip.ZipEntry;
024:        import java.util.zip.ZipInputStream;
025:
026:        import javax.jmi.reflect.ConstraintViolationException;
027:
028:        import org.netbeans.mdr.storagemodel.StorableObject;
029:
030:        import com.metaboss.sdlctools.models.ModelRepository;
031:        import com.metaboss.sdlctools.models.ModelRepositoryException;
032:        import com.metaboss.sdlctools.models.ModelRepositoryRuntimeException;
033:        import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
034:        import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementResolverImpl;
035:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
036:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachment;
037:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachmentUtils;
038:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.IncludedEnterpriseReference;
039:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
040:        import com.metaboss.util.ByteUtils;
041:        import com.metaboss.util.DirectoryUtils;
042:        import com.metaboss.util.StreamUtils;
043:
044:        public abstract class IncludedEnterpriseReferenceImpl extends
045:                ModelElementImpl implements  IncludedEnterpriseReference {
046:            private static final String MODELELEMENT_ATTACHMENT_NAME = "ModelArchive";
047:            private static final String MODEL_FILE_PREFIX_IN_ARCHIVE = "model/metaboss/";
048:            private static final String MODEL_FILE_NAME = "Model.xml";
049:
050:            // Required constructor
051:            protected IncludedEnterpriseReferenceImpl(StorableObject storable) {
052:                super (storable);
053:            }
054:
055:            // Forward declaration of automatically generated setter method
056:            protected abstract void super _setModelArchiveUrl(String pUrl);
057:
058:            /** Sets the value of modelArchiveURL attribute */
059:            public void setModelArchiveUrl(String pModelArchiveUrl) {
060:                // First see if there is already Url and Enterprise stored
061:                // and delete it if it is not the same
062:                if (getModelArchiveUrl() != null) {
063:                    if (!getModelArchiveUrl().equals(pModelArchiveUrl)) {
064:                        try {
065:                            Enterprise lOldEnterprise = getEnterprise();
066:                            ModelElementAttachment lOldAttachment = getAttachment(MODELELEMENT_ATTACHMENT_NAME);
067:                            ModelElementAttachmentUtils
068:                                    .deleteAttachmentData(lOldAttachment);
069:                            lOldAttachment.refDelete();
070:                            lOldEnterprise.refDelete();
071:                        } catch (ModelRepositoryException e) {
072:                            throw new ModelRepositoryRuntimeException(e);
073:                        }
074:                    } else {
075:                        // TODO: Latter on we will need to implement some sort of checksum verification
076:                        // but for now lets just say that they are the same
077:                        return;
078:                    }
079:                }
080:                // We need to do a number of things
081:                try {
082:                    URL lModelArchiveUrl = new URL(pModelArchiveUrl);
083:                    // 1- open the model in the repository as a separate model and copy the Enterprise and all subelements under here
084:                    {
085:                        File lTempDir = null;
086:                        try {
087:                            File lModelFile = null;
088:                            InputStream lInputStream = null;
089:                            try {
090:                                if ((lInputStream = lModelArchiveUrl
091:                                        .openStream()) == null)
092:                                    throw new ConstraintViolationException(
093:                                            null,
094:                                            null,
095:                                            "The ModelArchiveUrl attribute must contain URL, which is reachable at the time when it is being set. URL '"
096:                                                    + pModelArchiveUrl
097:                                                    + "' is not reachable");
098:                                ZipInputStream lZipInputStream = null;
099:                                try {
100:                                    lZipInputStream = new ZipInputStream(
101:                                            lInputStream);
102:                                    for (ZipEntry lZipEntry = lZipInputStream
103:                                            .getNextEntry(); lZipEntry != null; lZipEntry = lZipInputStream
104:                                            .getNextEntry()) {
105:                                        // We are only interested in extracting the bits and pieces of the metaboss model
106:                                        String lEntryName = lZipEntry.getName();
107:                                        if ((lEntryName
108:                                                .startsWith(MODEL_FILE_PREFIX_IN_ARCHIVE))
109:                                                && (lEntryName
110:                                                        .equals(MODEL_FILE_PREFIX_IN_ARCHIVE) == false)) {
111:                                            lEntryName = lEntryName
112:                                                    .substring(MODEL_FILE_PREFIX_IN_ARCHIVE
113:                                                            .length());
114:                                            if (lTempDir == null)
115:                                                lTempDir = DirectoryUtils
116:                                                        .createTempDir(
117:                                                                "includedEnterprise",
118:                                                                "");
119:                                            File lTargetFile = new File(
120:                                                    lTempDir.getAbsolutePath()
121:                                                            + File.separator
122:                                                            + lEntryName);
123:                                            // Keep the top model file handler, so we can open it 
124:                                            if (lEntryName
125:                                                    .equals(MODEL_FILE_NAME))
126:                                                lModelFile = lTargetFile;
127:                                            // Save the file where it belongs
128:                                            DirectoryUtils
129:                                                    .ensureThereIsDirectory(lTargetFile
130:                                                            .getParentFile()
131:                                                            .getAbsolutePath());
132:                                            FileOutputStream lFileOutputStream = null;
133:                                            try {
134:                                                lFileOutputStream = new FileOutputStream(
135:                                                        lTargetFile, false);
136:                                                StreamUtils.copyData(
137:                                                        lZipInputStream,
138:                                                        lFileOutputStream,
139:                                                        lZipEntry.getSize());
140:                                            } finally {
141:                                                if (lFileOutputStream != null)
142:                                                    lFileOutputStream.close();
143:                                            }
144:                                        }
145:                                    }
146:                                } finally {
147:                                    if (lZipInputStream != null)
148:                                        lZipInputStream.close();
149:                                }
150:                            } finally {
151:                                if (lInputStream != null)
152:                                    lInputStream.close();
153:                            }
154:                            if (lModelFile == null)
155:                                throw new ConstraintViolationException(
156:                                        null,
157:                                        null,
158:                                        "The ModelArchiveUrl attribute must point to the model archive, which contains "
159:                                                + MODEL_FILE_PREFIX_IN_ARCHIVE
160:                                                + MODEL_FILE_NAME
161:                                                + " model definition file. URL '"
162:                                                + pModelArchiveUrl
163:                                                + "' does not conform to this rule.");
164:                            // Now we are ready to open the model
165:                            ModelRepository lRepository = getModelRepository();
166:                            try {
167:                                lRepository
168:                                        .openModel(
169:                                                pModelArchiveUrl,
170:                                                lModelFile,
171:                                                ModelRepository.METAMODEL_NAME_METABOSS);
172:                                MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lRepository
173:                                        .getModelExtent(pModelArchiveUrl);
174:                                Enterprise lEnterpriseToImport = (Enterprise) lMetaBossModelPackage
175:                                        .getModelElement().getByRef(
176:                                                "Enterprise");
177:                                Enterprise lImportedEnterprise = (Enterprise) lRepository
178:                                        .copyModelElement(
179:                                                lEnterpriseToImport,
180:                                                lRepository
181:                                                        .getOwnerModelName(this ),
182:                                                true, ModelElementResolverImpl
183:                                                        .getInstance());
184:                                setEnterprise(lImportedEnterprise);
185:                            } finally {
186:                                if (lRepository.containsModel(pModelArchiveUrl))
187:                                    lRepository.closeModel(pModelArchiveUrl);
188:                            }
189:                        } finally {
190:                            if (lTempDir != null)
191:                                DirectoryUtils.deleteDirectory(lTempDir);
192:                        }
193:                    }
194:                    // 2- load the model archive from the specified Url and save it as an attachment to this element
195:                    {
196:                        InputStream lInputStream = null;
197:                        try {
198:                            if ((lInputStream = lModelArchiveUrl.openStream()) == null)
199:                                throw new ConstraintViolationException(
200:                                        null,
201:                                        null,
202:                                        "The ModelArchiveUrl attribute must contain URL, which is reachable at the time when it is being set. URL '"
203:                                                + pModelArchiveUrl
204:                                                + "' is not reachable");
205:                            ModelElementAttachment lAttachment = ((MetaBossModelPackage) refOutermostPackage())
206:                                    .getModelElementAttachment()
207:                                    .createModelElementAttachment();
208:                            lAttachment.setName(MODELELEMENT_ATTACHMENT_NAME);
209:                            lAttachment
210:                                    .setDescription("The imported model archive");
211:                            ModelElementAttachmentUtils.setAttachmentData(
212:                                    lAttachment, ByteUtils
213:                                            .readByteStreamFully(lInputStream));
214:                        } finally {
215:                            if (lInputStream != null)
216:                                lInputStream.close();
217:                        }
218:                    }
219:                } catch (ModelRepositoryException e) {
220:                    throw new ModelRepositoryRuntimeException(e);
221:                } catch (MalformedURLException e) {
222:                    ConstraintViolationException lException = new ConstraintViolationException(
223:                            null, null,
224:                            "The ModelArchiveUrl attribute must contain valid URL");
225:                    lException.initCause(e);
226:                    throw lException;
227:                } catch (IOException e) {
228:                    throw new ModelRepositoryRuntimeException(
229:                            "Caught IOException while trying to import the model archive",
230:                            e);
231:                }
232:                // Call the superclass attribute setter
233:                super_setModelArchiveUrl(pModelArchiveUrl);
234:
235:            }
236:        }
w_ww_.___ja___va_2__s___.co_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.