Source Code Cross Referenced for Storage.java in  » UML » MetaBoss » com » metaboss » sdlctools » domains » visualmodel » storage » xmlfileimpl » 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.visualmodel.storage.xmlfileimpl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012:        // POSSIBILITY OF SUCH DAMAGE.
0013:        //
0014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015:        package com.metaboss.sdlctools.domains.visualmodel.storage.xmlfileimpl;
0016:
0017:        import java.io.File;
0018:        import java.io.FileInputStream;
0019:        import java.io.FileNotFoundException;
0020:        import java.io.FileOutputStream;
0021:        import java.io.FileWriter;
0022:        import java.io.IOException;
0023:        import java.io.InputStream;
0024:        import java.util.ArrayList;
0025:        import java.util.HashMap;
0026:        import java.util.HashSet;
0027:        import java.util.Iterator;
0028:        import java.util.List;
0029:        import java.util.StringTokenizer;
0030:
0031:        import javax.xml.bind.JAXBContext;
0032:        import javax.xml.bind.JAXBException;
0033:        import javax.xml.bind.Marshaller;
0034:        import javax.xml.bind.Unmarshaller;
0035:        import javax.xml.bind.ValidationException;
0036:        import javax.xml.bind.Validator;
0037:
0038:        import org.apache.commons.logging.Log;
0039:        import org.apache.commons.logging.LogFactory;
0040:
0041:        import com.metaboss.enterprise.ps.PSContentConstraintViolationException;
0042:        import com.metaboss.enterprise.ps.PSDataSourceOperationInvocationException;
0043:        import com.metaboss.enterprise.ps.PSException;
0044:        import com.metaboss.enterprise.ps.PSIllegalArgumentException;
0045:        import com.metaboss.enterprise.ps.PSReadDataIntegrityViolationException;
0046:        import com.metaboss.enterprise.ps.PSUndefinedSystemPropertyException;
0047:        import com.metaboss.enterprise.ps.PSUnexpectedProgramConditionException;
0048:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ApplicationDefType;
0049:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.AssociationDefType;
0050:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.DataTypeDefType;
0051:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.DomainDefType;
0052:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.EnterpriseDefType;
0053:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.EntityDefType;
0054:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageDefType;
0055:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportDefType;
0056:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServiceDefType;
0057:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServicemoduleDefType;
0058:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.StructureDefType;
0059:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.SystemDefType;
0060:        import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.TypeTemplateDefType;
0061:        import com.metaboss.sdlctools.types.enterprisemodel.TemplateSourceType;
0062:        import com.metaboss.util.DirectoryUtils;
0063:        import com.metaboss.util.StringUtils;
0064:
0065:        /** This class is an interface between ps layer and dom storage */
0066:        public class Storage {
0067:            private static final Log sLogger = LogFactory.getLog(Storage.class);
0068:
0069:            // Will make it into settable thing in the future
0070:            private static final String cRootDir = System.getProperty(
0071:                    "MetaBoss.SystemDefinitionPath",
0072:                    "C:\\MetaBoss\\SampleSystemDefinition");
0073:            private static final String cEnterpriseRootDir = cRootDir
0074:                    + File.separator + "Enterprises";
0075:            private static final String cEnterpriseSystemsSubDir = "Systems";
0076:            private static final String cEnterpriseDatatypesSubDir = "Types";
0077:            private static final String cEnterpriseDomainsSubDir = "Domains";
0078:            private static final String cEnterpriseServicemodulesSubDir = "Services";
0079:            private static final String cEnterpriseServicemodulesServicesSubDir = "service";
0080:            private static final String cEnterpriseServicemodulesDatastructuresSubDir = "datastructure";
0081:            private static final String cEnterpriseApplicationsSubDir = File.separator
0082:                    + "Applications";
0083:            private static final String cDatatypesSubDir = "datatype";
0084:            private static final String cTypetemplatesSubDir = "typetemplate";
0085:
0086:            // Subdirectory of the metalib where all typetemplates can be found
0087:            private static final String sTypeTemplateMetaLibSubDir = File.separator
0088:                    + "EnterpriseModel" + File.separator + "typetemplate";
0089:            // Subdirectory of the metalib where all datatypes can be found
0090:            private static final String sDataTypeMetaLibSubDir = File.separator
0091:                    + "EnterpriseModel" + File.separator + "datatype";
0092:
0093:            private static JAXBContext cJAXBContext = null;
0094:            private static Unmarshaller cUnmarshaller = null;
0095:            private static Marshaller cMarshaller = null;
0096:            private static Validator cValidator = null;
0097:
0098:            // Helper. Provides single point of access to JAXBContext
0099:            private static JAXBContext getJAXBContext() throws JAXBException {
0100:                if (cJAXBContext == null) {
0101:                    // create a JAXBContext capable of handling classes generated into the package
0102:                    cJAXBContext = JAXBContext
0103:                            .newInstance("com.metaboss.sdlctools.domains.visualmodel.storage.xmlfileimpl.dom");
0104:                }
0105:                return cJAXBContext;
0106:            }
0107:
0108:            // Helper. Provides single point of access to Unmarshaller
0109:            private static Unmarshaller getUnmarshaller() throws JAXBException {
0110:                if (cUnmarshaller == null) {
0111:                    // create an Unmarshaller
0112:                    cUnmarshaller = getJAXBContext().createUnmarshaller();
0113:                }
0114:                return cUnmarshaller;
0115:            }
0116:
0117:            // Helper. Provides single point of access to Marshaller
0118:            private static Marshaller getMarshaller() throws JAXBException {
0119:                if (cMarshaller == null) {
0120:                    // create an Marshaller
0121:                    cMarshaller = getJAXBContext().createMarshaller();
0122:                    cMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
0123:                            Boolean.TRUE);
0124:                }
0125:                return cMarshaller;
0126:            }
0127:
0128:            // Helper. Provides single point of access to Validator
0129:            private static Validator getValidator() throws JAXBException {
0130:                if (cValidator == null) {
0131:                    // create an Marshaller
0132:                    cValidator = getJAXBContext().createValidator();
0133:                }
0134:                return cValidator;
0135:            }
0136:
0137:            private static HashMap cDOMObjectsCache = new HashMap();
0138:
0139:            /** Returns enterprise def or null if none found */
0140:            public static EnterpriseDefType getEnterprise(String pEnterpriseRef)
0141:                    throws PSException {
0142:                // First see if we have this object already
0143:                EnterpriseDefType lRet = (EnterpriseDefType) cDOMObjectsCache
0144:                        .get(pEnterpriseRef + ";"
0145:                                + EnterpriseDefType.class.getName());
0146:                if (lRet == null) {
0147:                    // EnterpriseRef always consists of single part - enterprise name
0148:                    StringTokenizer lTokenizer = new StringTokenizer(
0149:                            pEnterpriseRef, ".", false);
0150:                    if (lTokenizer.countTokens() != 1)
0151:                        throw new PSException("Invalid EnterpriseRef: "
0152:                                + pEnterpriseRef);
0153:                    String lEnterpriseName = lTokenizer.nextToken();
0154:                    // Enterprise definition is located right under enterprises
0155:                    String lEnterpriseFileName = cEnterpriseRootDir
0156:                            + File.separator + pEnterpriseRef + File.separator
0157:                            + "Descriptor.xml";
0158:                    InputStream lInputStream = null;
0159:                    try {
0160:                        lInputStream = openFileStream(lEnterpriseFileName);
0161:                        if (lInputStream != null) {
0162:                            if ((lRet = (EnterpriseDefType) getUnmarshaller()
0163:                                    .unmarshal(lInputStream)) != null) {
0164:                                if (!lRet.getEnterpriseRef().equals(
0165:                                        pEnterpriseRef))
0166:                                    throw new PSReadDataIntegrityViolationException(
0167:                                            "Mismatch between EnterpriseRef stored in file and the one implied by its location. EnterpriseRef : "
0168:                                                    + lRet.getEnterpriseRef()
0169:                                                    + ", Location : "
0170:                                                    + lEnterpriseFileName);
0171:                                cDOMObjectsCache.put(pEnterpriseRef + ";"
0172:                                        + EnterpriseDefType.class.getName(),
0173:                                        lRet);
0174:                            }
0175:                        }
0176:                    } catch (JAXBException e) {
0177:                        throw new PSDataSourceOperationInvocationException(e);
0178:                    } finally {
0179:                        try {
0180:                            if (lInputStream != null)
0181:                                lInputStream.close();
0182:                        } catch (IOException e) {
0183:                        }
0184:                    }
0185:                }
0186:                return lRet;
0187:            }
0188:
0189:            /** All services found in the module */
0190:            public static String[] getServicemoduleServiceRefs(
0191:                    String pServicemoduleRef) throws PSException {
0192:                ServicemoduleDefType lServicemoduleDef = getServicemodule(pServicemoduleRef);
0193:                if (lServicemoduleDef == null)
0194:                    throw new PSException("Invalid ServicemoduleRef: "
0195:                            + pServicemoduleRef);
0196:                ArrayList lServiceRefs = new ArrayList();
0197:                List lServices = lServicemoduleDef.getServiceDefList()
0198:                        .getServiceDef();
0199:                Iterator lIter = lServices.iterator();
0200:                while (lIter.hasNext()) {
0201:                    ServiceDefType lServiceDef = (ServiceDefType) lIter.next();
0202:                    lServiceRefs.add(lServiceDef.getServiceRef());
0203:                }
0204:                return (String[]) lServiceRefs.toArray(new String[lServiceRefs
0205:                        .size()]);
0206:            }
0207:
0208:            /** All structures found in the module */
0209:            public static String[] getServicemoduleStructureRefs(
0210:                    String pServicemoduleRef) throws PSException {
0211:                ServicemoduleDefType lServicemoduleDef = getServicemodule(pServicemoduleRef);
0212:                if (lServicemoduleDef == null)
0213:                    throw new PSException("Invalid ServicemoduleRef: "
0214:                            + pServicemoduleRef);
0215:                ArrayList lStructureRefs = new ArrayList();
0216:                List lStructures = lServicemoduleDef.getStructureDefList()
0217:                        .getStructureDef();
0218:                Iterator lIter = lStructures.iterator();
0219:                while (lIter.hasNext()) {
0220:                    StructureDefType lStructureDef = (StructureDefType) lIter
0221:                            .next();
0222:                    lStructureRefs.add(lStructureDef.getStructureRef());
0223:                }
0224:                return (String[]) lStructureRefs
0225:                        .toArray(new String[lStructureRefs.size()]);
0226:            }
0227:
0228:            /** All messages found in the module */
0229:            public static String[] getServicemoduleMessageRefs(
0230:                    String pServicemoduleRef) throws PSException {
0231:                ServicemoduleDefType lServicemoduleDef = getServicemodule(pServicemoduleRef);
0232:                if (lServicemoduleDef == null)
0233:                    throw new PSException("Invalid ServicemoduleRef: "
0234:                            + pServicemoduleRef);
0235:                ArrayList lMessageRefs = new ArrayList();
0236:                List lMessages = lServicemoduleDef.getMessageDefList()
0237:                        .getMessageDef();
0238:                Iterator lIter = lMessages.iterator();
0239:                while (lIter.hasNext()) {
0240:                    MessageDefType lMessageDef = (MessageDefType) lIter.next();
0241:                    lMessageRefs.add(lMessageDef.getMessageRef());
0242:                }
0243:                return (String[]) lMessageRefs.toArray(new String[lMessageRefs
0244:                        .size()]);
0245:            }
0246:
0247:            /** All entities found in the domain */
0248:            public static String[] getDomainEntityRefs(String pDomainRef)
0249:                    throws PSException {
0250:                DomainDefType lDomainDef = getDomain(pDomainRef);
0251:                if (lDomainDef == null)
0252:                    throw new com.metaboss.enterprise.ps.PSIllegalArgumentException(
0253:                            "Unknown domain. DomainRef: " + pDomainRef);
0254:                // Iterate through associations - building matching datatype references
0255:                List lEntities = lDomainDef.getEntityDefList().getEntityDef();
0256:                String[] lReturnEntityRefs = new String[lEntities.size()];
0257:                Iterator lIter = lEntities.iterator();
0258:                for (int i = 0; lIter.hasNext(); i++) {
0259:                    EntityDefType lEntityDef = (EntityDefType) lIter.next();
0260:                    lReturnEntityRefs[i] = lEntityDef.getEntityRef();
0261:                }
0262:                return lReturnEntityRefs;
0263:            }
0264:
0265:            /** All enterprises found in the installation */
0266:            public static String[] getEnterpriseRefs() throws PSException {
0267:                // Loop through directory and report enterprise names
0268:                String lEnterprisesDirName = cEnterpriseRootDir;
0269:
0270:                File lEnterprisesDir = new File(lEnterprisesDirName);
0271:                if (!lEnterprisesDir.exists())
0272:                    return new String[0]; // No entities
0273:
0274:                File[] lEnterpriseDirs = lEnterprisesDir.listFiles();
0275:                if (lEnterpriseDirs == null)
0276:                    return new String[0]; // No entities
0277:
0278:                // Iterate through directories - building matching enterprise references
0279:                String[] lReturnEnterpriseRefs = new String[lEnterpriseDirs.length];
0280:                for (int i = 0; i < lEnterpriseDirs.length; i++)
0281:                    lReturnEnterpriseRefs[i] = lEnterpriseDirs[i].getName();
0282:                return lReturnEnterpriseRefs;
0283:            }
0284:
0285:            /** All datatypes  found in the domain */
0286:            public static String[] getSystemDatatypeRefs(String pSystemRef)
0287:                    throws PSException {
0288:                try {
0289:                    String lDatatypeDirRootName = getSystemDirectory(pSystemRef)
0290:                            + File.separator + cEnterpriseDatatypesSubDir;
0291:                    File lEnterpriseDatatypeDir = new File(lDatatypeDirRootName);
0292:                    if (!lEnterpriseDatatypeDir.exists()) {
0293:                        // There are not types directory - may be there are no types ?
0294:                        if (lEnterpriseDatatypeDir.getParentFile().exists())
0295:                            return new String[0]; // No types, but there is a system. This is as good as no types defined
0296:                        throw new PSIllegalArgumentException(
0297:                                "System not found. SystemRef: " + pSystemRef);
0298:                    }
0299:                    String[] lAllDatatypeDirectories = DirectoryUtils
0300:                            .listAllDirectoriesWithName(lDatatypeDirRootName,
0301:                                    "datatype");
0302:                    // Iterate through directories - building matching datatype references
0303:                    ArrayList lAllRefs = new ArrayList();
0304:                    for (int i = 0; i < lAllDatatypeDirectories.length; i++) {
0305:                        String lDatatypeDirName = lAllDatatypeDirectories[i];
0306:                        String lDatatypeDirMiddleName = lDatatypeDirName
0307:                                .substring(lDatatypeDirRootName.length() + 1,
0308:                                        lDatatypeDirName.length() - 9);
0309:                        String lBeginningOfRef = pSystemRef + ".";
0310:                        if (!lDatatypeDirMiddleName.equals("-"))
0311:                            lBeginningOfRef += StringUtils
0312:                                    .replace(lDatatypeDirMiddleName,
0313:                                            File.separator, ".")
0314:                                    + ".";
0315:
0316:                        File lDatatypeDir = new File(lDatatypeDirName);
0317:                        File[] lDatatypeDirs = lDatatypeDir.listFiles();
0318:                        if (lDatatypeDirs != null && lDatatypeDirs.length > 0) {
0319:                            // Iterate through this datatype directory and build matching datatype references
0320:                            for (int j = 0; j < lDatatypeDirs.length; j++) {
0321:                                lAllRefs.add(lBeginningOfRef
0322:                                        + lDatatypeDirs[j].getName());
0323:                            }
0324:                        }
0325:                    }
0326:                    return (String[]) lAllRefs.toArray(new String[lAllRefs
0327:                            .size()]);
0328:                } catch (java.io.FileNotFoundException e) {
0329:                    throw new PSException(
0330:                            "Caught exception while scanning for System Datatypes. SystemRef: "
0331:                                    + pSystemRef, e);
0332:                }
0333:
0334:            }
0335:
0336:            /** All typetemplates  found in the domain */
0337:            public static String[] getSystemTypetemplateRefs(String pSystemRef)
0338:                    throws PSException {
0339:                try {
0340:                    String lDatatypeDirRootName = getSystemDirectory(pSystemRef)
0341:                            + File.separator + cEnterpriseDatatypesSubDir;
0342:                    File lEnterpriseDatatypeDir = new File(lDatatypeDirRootName);
0343:                    if (!lEnterpriseDatatypeDir.exists()) {
0344:                        // There are not types directory - may be there are no types ?
0345:                        if (lEnterpriseDatatypeDir.getParentFile().exists())
0346:                            return new String[0]; // No types, but there is a system. This is as good as no types defined
0347:                        throw new PSIllegalArgumentException(
0348:                                "System not found. SystemRef: " + pSystemRef);
0349:                    }
0350:                    String[] lAllTypetemplateDirectories = DirectoryUtils
0351:                            .listAllDirectoriesWithName(lDatatypeDirRootName,
0352:                                    "typetemplate");
0353:                    // Iterate through directories - building matching datatype references
0354:                    ArrayList lAllRefs = new ArrayList();
0355:                    for (int i = 0; i < lAllTypetemplateDirectories.length; i++) {
0356:                        String lTypetemplateDirName = lAllTypetemplateDirectories[i];
0357:                        String lTypetemplateDirMiddleName = lTypetemplateDirName
0358:                                .substring(lDatatypeDirRootName.length() + 1,
0359:                                        lTypetemplateDirName.length() - 13);
0360:                        String lBeginningOfRef = pSystemRef + ".";
0361:                        if (!lTypetemplateDirMiddleName.equals("-"))
0362:                            lBeginningOfRef += StringUtils.replace(
0363:                                    lTypetemplateDirMiddleName, File.separator,
0364:                                    ".")
0365:                                    + ".";
0366:
0367:                        File lTypetemplateDir = new File(lTypetemplateDirName);
0368:                        File[] lTypetemplateDirs = lTypetemplateDir.listFiles();
0369:                        if (lTypetemplateDirs != null
0370:                                && lTypetemplateDirs.length > 0) {
0371:                            // Iterate through this datatype directory and build matching datatype references
0372:                            for (int j = 0; j < lTypetemplateDirs.length; j++) {
0373:                                lAllRefs.add(lBeginningOfRef
0374:                                        + lTypetemplateDirs[j].getName());
0375:                            }
0376:                        }
0377:                    }
0378:                    return (String[]) lAllRefs.toArray(new String[lAllRefs
0379:                            .size()]);
0380:                } catch (java.io.FileNotFoundException e) {
0381:                    throw new PSException(
0382:                            "Caught exception while scanning for System Typetemplates. SystemRef: "
0383:                                    + pSystemRef, e);
0384:                }
0385:
0386:            }
0387:
0388:            /** All systems found in this enterprise */
0389:            public static String[] getEnterpriseSystemRefs(String pEnterpriseRef)
0390:                    throws PSException {
0391:                try {
0392:                    // EnterpriseRef always consists of single part - enterprise name
0393:                    StringTokenizer lTokenizer = new StringTokenizer(
0394:                            pEnterpriseRef, ".", false);
0395:                    if (lTokenizer.countTokens() != 1)
0396:                        throw new PSException("Invalid EnterpriseRef: "
0397:                                + pEnterpriseRef);
0398:                    String lEnterpriseName = lTokenizer.nextToken();
0399:                    String lSystemsRootDirName = cEnterpriseRootDir
0400:                            + File.separator + lEnterpriseName + File.separator
0401:                            + cEnterpriseSystemsSubDir;
0402:                    File lSystemsRootDir = new File(lSystemsRootDirName);
0403:                    if (!lSystemsRootDir.exists()) {
0404:                        // There are no systems directory - may be there are no systems ?
0405:                        if (lSystemsRootDir.getParentFile().exists())
0406:                            return new String[0]; // No systems, but there is an enterprise. This is as good as no systems defined
0407:                        throw new PSIllegalArgumentException(
0408:                                "Enterprise not found. EnterpriseRef : "
0409:                                        + pEnterpriseRef);
0410:                    }
0411:                    String[] lAllSystemsDirectories = DirectoryUtils
0412:                            .listAllChildDirectoriesInDirectory(lSystemsRootDir
0413:                                    .getAbsolutePath());
0414:                    // Iterate through directories - building matching system references
0415:                    ArrayList lAllRefs = new ArrayList();
0416:                    for (int i = 0; i < lAllSystemsDirectories.length; i++) {
0417:                        String lSystemDirName = lAllSystemsDirectories[i];
0418:                        int lLastDir = lSystemDirName
0419:                                .lastIndexOf(File.separator);
0420:                        String lSystemName = lSystemDirName
0421:                                .substring(lLastDir + 1);
0422:                        lAllRefs.add(lEnterpriseName + "." + lSystemName);
0423:                    }
0424:                    return (String[]) lAllRefs.toArray(new String[lAllRefs
0425:                            .size()]);
0426:                } catch (java.io.FileNotFoundException e) {
0427:                    throw new PSException(
0428:                            "Caught exception while scanning for System references. EnterpriseRef: "
0429:                                    + pEnterpriseRef, e);
0430:                }
0431:
0432:            }
0433:
0434:            /** All datatypes  found in the domain */
0435:            public static String[] getSystemServicemoduleRefs(String pSystemRef)
0436:                    throws PSException {
0437:                String lSystemDirectoryName = getSystemDirectory(pSystemRef);
0438:                if (new File(lSystemDirectoryName).exists() == false)
0439:                    throw new PSException(
0440:                            "Directory "
0441:                                    + lSystemDirectoryName
0442:                                    + " does not exist. Unable to read system definition. SystemRef:"
0443:                                    + pSystemRef);
0444:                String lSystemName = pSystemRef.substring(pSystemRef
0445:                        .lastIndexOf(".") + 1);
0446:                String lServicemoduleDirRootName = lSystemDirectoryName
0447:                        + File.separator + cEnterpriseServicemodulesSubDir;
0448:                File lServicemoduleDir = new File(lServicemoduleDirRootName);
0449:                if ((!lServicemoduleDir.isDirectory())
0450:                        || (!lServicemoduleDir.exists()))
0451:                    return new String[0];
0452:                // Iterate through directories - building matching datatype references
0453:                ArrayList lAllRefs = new ArrayList();
0454:                File[] lServicemoduleDirs = lServicemoduleDir.listFiles();
0455:                if (lServicemoduleDirs != null && lServicemoduleDirs.length > 0) {
0456:                    // Iterate through this datatype directory and build matching datatype references
0457:                    for (int j = 0; j < lServicemoduleDirs.length; j++) {
0458:                        File lFile = lServicemoduleDirs[j];
0459:                        if (lFile.isDirectory())
0460:                            lAllRefs.add(pSystemRef + "."
0461:                                    + lServicemoduleDirs[j].getName());
0462:                    }
0463:                }
0464:                return (String[]) lAllRefs.toArray(new String[lAllRefs.size()]);
0465:            }
0466:
0467:            /** All associations found in the domain */
0468:            public static String[] getDomainReportRefs(String pDomainRef)
0469:                    throws PSException {
0470:                DomainDefType lDomainDef = getDomain(pDomainRef);
0471:                if (lDomainDef == null)
0472:                    throw new PSIllegalArgumentException(
0473:                            "Unknown domain. DomainRef : " + pDomainRef);
0474:                // Iterate through associations - building matching datatype references
0475:                List lReports = lDomainDef.getReportDefList().getReportDef();
0476:                String[] lReturnReportRefs = new String[lReports.size()];
0477:                Iterator lIter = lReports.iterator();
0478:                for (int i = 0; lIter.hasNext(); i++) {
0479:                    ReportDefType lReportDef = (ReportDefType) lIter.next();
0480:                    lReturnReportRefs[i] = lReportDef.getReportRef();
0481:                }
0482:                return lReturnReportRefs;
0483:            }
0484:
0485:            /** All associations found in the domain */
0486:            public static String[] getDomainAssociationRefs(String pDomainRef)
0487:                    throws PSException {
0488:                DomainDefType lDomainDef = getDomain(pDomainRef);
0489:                if (lDomainDef == null)
0490:                    throw new PSIllegalArgumentException(
0491:                            "Unknown domain. DomainRef: " + pDomainRef);
0492:                // Iterate through associations - building matching datatype references
0493:                List lAssociations = lDomainDef.getAssociationDefList()
0494:                        .getAssociationDef();
0495:                String[] lReturnAssociationRefs = new String[lAssociations
0496:                        .size()];
0497:                Iterator lIter = lAssociations.iterator();
0498:                for (int i = 0; lIter.hasNext(); i++) {
0499:                    AssociationDefType lAssociationDef = (AssociationDefType) lIter
0500:                            .next();
0501:                    lReturnAssociationRefs[i] = lAssociationDef
0502:                            .getAssociationRef();
0503:                }
0504:                return lReturnAssociationRefs;
0505:            }
0506:
0507:            /** Returns domain def or null if none found */
0508:            public static DomainDefType getDomain(String pDomainRef)
0509:                    throws PSException {
0510:                // First see if we have this object already
0511:                DomainDefType lRet = (DomainDefType) cDOMObjectsCache
0512:                        .get(pDomainRef + ";" + DomainDefType.class.getName());
0513:                if (lRet == null) {
0514:                    // DomainRef always consists of three parts - enterprise name . system name . domain name
0515:                    StringTokenizer lTokenizer = new StringTokenizer(
0516:                            pDomainRef, ".", false);
0517:                    if (lTokenizer.countTokens() != 3)
0518:                        throw new PSException("Invalid DomainRef: "
0519:                                + pDomainRef);
0520:                    String lEnterpriseName = lTokenizer.nextToken();
0521:                    String lSystemName = lTokenizer.nextToken();
0522:                    String lDomainName = lTokenizer.nextToken();
0523:                    String lDomainFileName = cEnterpriseRootDir
0524:                            + File.separator + lEnterpriseName + File.separator
0525:                            + cEnterpriseSystemsSubDir + File.separator
0526:                            + lSystemName + File.separator
0527:                            + cEnterpriseDomainsSubDir + File.separator
0528:                            + lDomainName + "DomainDescriptor.xml";
0529:
0530:                    InputStream lInputStream = null;
0531:                    try {
0532:                        lInputStream = openFileStream(lDomainFileName);
0533:                        if (lInputStream != null) {
0534:                            if ((lRet = (DomainDefType) getUnmarshaller()
0535:                                    .unmarshal(lInputStream)) != null) {
0536:                                if (!lRet.getDomainRef().equals(pDomainRef))
0537:                                    throw new PSReadDataIntegrityViolationException(
0538:                                            "Mismatch between DomainRef stored in file and the one implied by its location. DomainRef : "
0539:                                                    + lRet.getDomainRef()
0540:                                                    + ", Location : "
0541:                                                    + lDomainFileName);
0542:                                cDOMObjectsCache.put(pDomainRef + ";"
0543:                                        + DomainDefType.class.getName(), lRet);
0544:                            }
0545:                        }
0546:                    } catch (JAXBException e) {
0547:                        throw new PSDataSourceOperationInvocationException(e);
0548:                    } finally {
0549:                        try {
0550:                            if (lInputStream != null)
0551:                                lInputStream.close();
0552:                        } catch (IOException e) {
0553:                        }
0554:                    }
0555:                }
0556:                return lRet;
0557:            }
0558:
0559:            /** Returns system def or null if none found */
0560:            public static SystemDefType getSystem(String pSystemRef)
0561:                    throws PSException {
0562:                // First see if we have this object already
0563:                SystemDefType lRet = (SystemDefType) cDOMObjectsCache
0564:                        .get(pSystemRef + ";" + SystemDefType.class.getName());
0565:                if (lRet == null) {
0566:                    String lSystemDirectoryName = getSystemDirectory(pSystemRef);
0567:                    if (new File(lSystemDirectoryName).exists() == false)
0568:                        throw new PSException(
0569:                                "Directory "
0570:                                        + lSystemDirectoryName
0571:                                        + " does not exist. Unable to read system definition. SystemRef:"
0572:                                        + pSystemRef);
0573:                    String lSystemFileName = lSystemDirectoryName
0574:                            + File.separator + "Descriptor.xml";
0575:                    InputStream lInputStream = null;
0576:                    try {
0577:                        lInputStream = openFileStream(lSystemFileName);
0578:                        if (lInputStream != null) {
0579:                            if ((lRet = (SystemDefType) getUnmarshaller()
0580:                                    .unmarshal(lInputStream)) != null) {
0581:                                if (!lRet.getSystemRef().equals(pSystemRef))
0582:                                    throw new PSReadDataIntegrityViolationException(
0583:                                            "Mismatch between SystemRef stored in file and the one implied by its location. SystemRef: "
0584:                                                    + lRet.getSystemRef()
0585:                                                    + ", Location: "
0586:                                                    + lSystemFileName);
0587:                                cDOMObjectsCache.put(pSystemRef + ";"
0588:                                        + SystemDefType.class.getName(), lRet);
0589:                            }
0590:                        }
0591:                    } catch (JAXBException e) {
0592:                        throw new PSDataSourceOperationInvocationException(e);
0593:                    } finally {
0594:                        try {
0595:                            if (lInputStream != null)
0596:                                lInputStream.close();
0597:                        } catch (IOException e) {
0598:                        }
0599:                    }
0600:                }
0601:                return lRet;
0602:            }
0603:
0604:            /** Returns DataType def or null if none found */
0605:            public static DataTypeDefType getDatatype(String pDataTypeRef)
0606:                    throws PSException {
0607:                // First see if we have this object already
0608:                DataTypeDefType lRet = (DataTypeDefType) cDOMObjectsCache
0609:                        .get(pDataTypeRef + ";"
0610:                                + DataTypeDefType.class.getName());
0611:                if (lRet == null) {
0612:                    String lDatatypeDirectoryName = getDataTypeDirectory(pDataTypeRef);
0613:                    if (lDatatypeDirectoryName == null)
0614:                        throw new PSException(
0615:                                "DataType directory not found. Unable to resolve data type. DataTypeRef="
0616:                                        + pDataTypeRef);
0617:                    String lDataTypeFileName = lDatatypeDirectoryName
0618:                            + File.separator + "Descriptor.xml";
0619:                    InputStream lInputStream = null;
0620:                    try {
0621:                        lInputStream = openFileStream(lDataTypeFileName);
0622:                        if (lInputStream != null) {
0623:                            if ((lRet = (DataTypeDefType) getUnmarshaller()
0624:                                    .unmarshal(lInputStream)) != null) {
0625:                                if (!lRet.getDataTypeRef().equals(pDataTypeRef))
0626:                                    throw new PSReadDataIntegrityViolationException(
0627:                                            "Mismatch between DatatypeRef stored in file and the one implied by its location. DatatypeRef : "
0628:                                                    + lRet.getDataTypeRef()
0629:                                                    + ", Location : "
0630:                                                    + lDataTypeFileName);
0631:                                cDOMObjectsCache
0632:                                        .put(pDataTypeRef
0633:                                                + ";"
0634:                                                + DataTypeDefType.class
0635:                                                        .getName(), lRet);
0636:                            }
0637:                        }
0638:                    } catch (JAXBException e) {
0639:                        throw new PSDataSourceOperationInvocationException(
0640:                                "Exception caught during processing of Data Type. DataTypeRef : "
0641:                                        + pDataTypeRef, e);
0642:                    } finally {
0643:                        try {
0644:                            if (lInputStream != null)
0645:                                lInputStream.close();
0646:                        } catch (IOException e) {
0647:                        }
0648:                    }
0649:                }
0650:                return lRet;
0651:            }
0652:
0653:            /** Returns DataType def or null if none found */
0654:            public static void deleteDatatype(String pDataTypeRef)
0655:                    throws PSException {
0656:                if (pDataTypeRef.startsWith("."))
0657:                    throw new PSIllegalArgumentException(
0658:                            "Attempt to delete public Datatype. DatatypeRef : "
0659:                                    + pDataTypeRef);
0660:                String lDatatypeDirectoryName = getDataTypeDirectory(pDataTypeRef);
0661:                if (lDatatypeDirectoryName == null)
0662:                    throw new PSException(
0663:                            "Attempt to delete nonexistent Datatype. DatatypeRef : "
0664:                                    + pDataTypeRef);
0665:                String lDatatypeFileName = lDatatypeDirectoryName
0666:                        + File.separator + "Descriptor.xml";
0667:                cDOMObjectsCache.remove(lDatatypeFileName + ";"
0668:                        + DataTypeDefType.class.getName());
0669:            }
0670:
0671:            /** Deletes Servicemodule */
0672:            public static void deleteServicemodule(String pServicemoduleRef)
0673:                    throws PSException {
0674:                // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
0675:                StringTokenizer lTokenizer = new StringTokenizer(
0676:                        pServicemoduleRef, ".", false);
0677:                if (lTokenizer.countTokens() != 3)
0678:                    throw new PSException("Invalid ServicemoduleRef: "
0679:                            + pServicemoduleRef);
0680:                String lEnterpriseName = lTokenizer.nextToken();
0681:                String lSystemName = lTokenizer.nextToken();
0682:                String lServicemoduleName = lTokenizer.nextToken();
0683:                String lServicemoduleFileName = cEnterpriseRootDir
0684:                        + File.separator + lEnterpriseName + File.separator
0685:                        + cEnterpriseSystemsSubDir + File.separator
0686:                        + lSystemName + File.separator
0687:                        + cEnterpriseServicemodulesSubDir + File.separator
0688:                        + lServicemoduleName + "ServicemoduleDescriptor.xml";
0689:                File lServicemoduleFile = new File(lServicemoduleFileName);
0690:                if (lServicemoduleFile.exists() == false)
0691:                    throw new PSException(
0692:                            "File "
0693:                                    + lServicemoduleFileName
0694:                                    + " does not exist. Unable to delete servicemodule. ServicemoduleRef: "
0695:                                    + pServicemoduleRef);
0696:                if (lServicemoduleFile.canWrite() == false)
0697:                    throw new PSException(
0698:                            "File "
0699:                                    + lServicemoduleFileName
0700:                                    + " is read-only. Unable to delete servicemodule. ServicemoduleRef: "
0701:                                    + pServicemoduleRef);
0702:                if (!lServicemoduleFile.delete())
0703:                    throw new PSException(
0704:                            "Unable to delete servicemodule. ServicemoduleRef: "
0705:                                    + pServicemoduleRef);
0706:                cDOMObjectsCache.remove(pServicemoduleRef + ";"
0707:                        + ServicemoduleDefType.class.getName());
0708:            }
0709:
0710:            /** Deletes Enterprise */
0711:            public static void deleteEnterprise(String pEnterpriseRef)
0712:                    throws PSException {
0713:                try {
0714:                    String lEnterpriseDirectoryName = getEnterpriseDirectory(pEnterpriseRef);
0715:                    File lEnterpriseDirectory = new File(
0716:                            lEnterpriseDirectoryName);
0717:                    if (!lEnterpriseDirectory.exists())
0718:                        throw new PSException(
0719:                                "Directory "
0720:                                        + lEnterpriseDirectoryName
0721:                                        + " does not exist. Unable to delete enterprise. EnterpriseRef: "
0722:                                        + pEnterpriseRef);
0723:                    if (!DirectoryUtils.canDelete(lEnterpriseDirectory))
0724:                        throw new PSException(
0725:                                "Directory "
0726:                                        + lEnterpriseDirectoryName
0727:                                        + " is not writeable. Unable to delete enterprise. EnterpriseRef: "
0728:                                        + pEnterpriseRef);
0729:                    cDOMObjectsCache.remove(pEnterpriseRef + ";"
0730:                            + EnterpriseDefType.class.getName());
0731:                    DirectoryUtils.deleteDirectory(lEnterpriseDirectory);
0732:                } catch (IOException e) {
0733:                    throw new PSException(
0734:                            "Caught exception while deleting Enterprise. EnterpriseRef: "
0735:                                    + pEnterpriseRef, e);
0736:                }
0737:            }
0738:
0739:            /** Returns DataType def or null if none found */
0740:            public static void insertDatatype(DataTypeDefType pDataTypeDef)
0741:                    throws PSException {
0742:                try {
0743:                    try {
0744:                        getValidator().validate(pDataTypeDef);
0745:                    } catch (ValidationException e) {
0746:                        throw new PSContentConstraintViolationException(
0747:                                "Datatype definition validation exception. DatatypeRef: "
0748:                                        + pDataTypeDef.getDataTypeRef(), e);
0749:                    }
0750:                    if (pDataTypeDef.getDataTypeRef().startsWith("."))
0751:                        throw new PSIllegalArgumentException(
0752:                                "Attempt to insert public Datatype. DatatypeRef : "
0753:                                        + pDataTypeDef.getDataTypeRef());
0754:                    String lDatatypeDirectoryName = getDataTypeDirectory(pDataTypeDef
0755:                            .getDataTypeRef());
0756:                    if (lDatatypeDirectoryName != null)
0757:                        throw new PSException(
0758:                                "Attempt to insert alredy existing Datatype. DatatypeRef : "
0759:                                        + pDataTypeDef.getDataTypeRef());
0760:                    lDatatypeDirectoryName = suggestEnterpriseDataTypeDirectory(pDataTypeDef
0761:                            .getDataTypeRef());
0762:                    String lDatatypeFileName = lDatatypeDirectoryName
0763:                            + File.separator + "Descriptor.xml";
0764:                    FileOutputStream lFileOutputStream = null;
0765:                    try {
0766:                        DirectoryUtils
0767:                                .ensureNewCleanDirectory(lDatatypeDirectoryName);
0768:                        lFileOutputStream = new FileOutputStream(
0769:                                lDatatypeFileName, false);
0770:                        getMarshaller()
0771:                                .marshal(pDataTypeDef, lFileOutputStream);
0772:                        lFileOutputStream.flush();
0773:                        lFileOutputStream.close();
0774:                        lFileOutputStream = null;
0775:                        cDOMObjectsCache.put(pDataTypeDef.getDataTypeRef()
0776:                                + ";" + DataTypeDefType.class.getName(),
0777:                                pDataTypeDef);
0778:                    } catch (IOException e) {
0779:                        throw new PSException(
0780:                                "Caught exception while writing file : "
0781:                                        + lDatatypeFileName, e);
0782:                    } finally {
0783:                        try {
0784:                            if (lFileOutputStream != null)
0785:                                lFileOutputStream.close();
0786:                        } catch (IOException e) {
0787:                        }
0788:                    }
0789:                } catch (JAXBException e) {
0790:                    throw new PSDataSourceOperationInvocationException(e);
0791:                }
0792:            }
0793:
0794:            /** Returns DataType def or null if none found */
0795:            public static void updateDatatype(DataTypeDefType pDataTypeDef)
0796:                    throws PSException {
0797:                try {
0798:                    try {
0799:                        getValidator().validate(pDataTypeDef);
0800:                    } catch (ValidationException e) {
0801:                        throw new PSContentConstraintViolationException(
0802:                                "Datatype definition validation exception. DatatypeRef: "
0803:                                        + pDataTypeDef.getDataTypeRef(), e);
0804:                    }
0805:                    if (pDataTypeDef.getDataTypeRef().startsWith("."))
0806:                        throw new PSIllegalArgumentException(
0807:                                "Attempt to update public Datatype. DatatypeRef : "
0808:                                        + pDataTypeDef.getDataTypeRef());
0809:                    String lDatatypeDirectoryName = getDataTypeDirectory(pDataTypeDef
0810:                            .getDataTypeRef());
0811:                    if (lDatatypeDirectoryName == null)
0812:                        throw new PSException(
0813:                                "Datatype directory not found. Unable to resolve data type. DataTypeRef: "
0814:                                        + pDataTypeDef.getDataTypeRef());
0815:                    String lDataTypeFileName = lDatatypeDirectoryName
0816:                            + File.separator + "Descriptor.xml";
0817:                    File lDataTypeFile = new File(lDataTypeFileName);
0818:                    if (lDataTypeFile.exists() == false
0819:                            || lDataTypeFile.isFile() == false)
0820:                        throw new PSException(
0821:                                "Attempt to update Datatype, which does not exists. DataTypeRef : "
0822:                                        + pDataTypeDef.getDataTypeRef());
0823:                    if (!lDataTypeFile.canWrite())
0824:                        throw new PSException(
0825:                                "Datatype file is read-only. DataTypeRef : "
0826:                                        + pDataTypeDef.getDataTypeRef());
0827:                    // Clean up the cache prior to saving the new file
0828:                    cDOMObjectsCache.remove(pDataTypeDef.getDataTypeRef() + ";"
0829:                            + DataTypeDefType.class.getName());
0830:                    FileOutputStream lFileOutputStream = null;
0831:                    try {
0832:                        lFileOutputStream = new FileOutputStream(
0833:                                lDataTypeFileName, false);
0834:                        getMarshaller()
0835:                                .marshal(pDataTypeDef, lFileOutputStream);
0836:                        lFileOutputStream.flush();
0837:                        lFileOutputStream.close();
0838:                        lFileOutputStream = null;
0839:                        cDOMObjectsCache.put(pDataTypeDef.getDataTypeRef()
0840:                                + ";" + DataTypeDefType.class.getName(),
0841:                                pDataTypeDef);
0842:                    } catch (IOException e) {
0843:                        throw new PSException(
0844:                                "Caught exception while writing file : "
0845:                                        + lDataTypeFileName, e);
0846:                    } finally {
0847:                        try {
0848:                            if (lFileOutputStream != null)
0849:                                lFileOutputStream.close();
0850:                        } catch (IOException e) {
0851:                        }
0852:                    }
0853:                } catch (JAXBException e) {
0854:                    throw new PSDataSourceOperationInvocationException(e);
0855:                }
0856:            }
0857:
0858:            /** Returns DataType source or null if none found */
0859:            public static String getDatatypeSource(String pDataTypeRef,
0860:                    String pFileSuffix) throws PSException {
0861:                String lDatatypeDirectoryName = getDataTypeDirectory(pDataTypeRef);
0862:                if (lDatatypeDirectoryName == null)
0863:                    throw new PSException(
0864:                            "DataType directory not found. Unable to resolve data type. DataTypeRef: "
0865:                                    + pDataTypeRef);
0866:                int lLastDotIndex = pDataTypeRef.lastIndexOf(".");
0867:                String lDataTypeSourceFileName = lDatatypeDirectoryName
0868:                        + File.separator
0869:                        + pDataTypeRef.substring(lLastDotIndex + 1)
0870:                        + pFileSuffix + ".java";
0871:
0872:                // Load this file
0873:                InputStream lInputStream = null;
0874:                try {
0875:                    lInputStream = openFileStream(lDataTypeSourceFileName);
0876:                    if (lInputStream != null) {
0877:                        return StringUtils.readTextStreamFully(lInputStream);
0878:                    }
0879:                    return null;
0880:                } catch (IOException e) {
0881:                    throw new PSException(
0882:                            "Caught exception while reading file : "
0883:                                    + lDataTypeSourceFileName, e);
0884:                } finally {
0885:                    try {
0886:                        if (lInputStream != null)
0887:                            lInputStream.close();
0888:                    } catch (IOException e) {
0889:                    }
0890:                }
0891:            }
0892:
0893:            /** Returns Service implementation source */
0894:            public static com.metaboss.sdlctools.types.enterprisemodel.ZipArchive getServiceImplementationSource(
0895:                    String pServiceRef, String pSourceName) throws PSException {
0896:                try {
0897:                    String lServiceDirectoryName = getServiceDirectory(pServiceRef);
0898:                    File lDirectoryFile = new File(lServiceDirectoryName);
0899:                    if (lDirectoryFile.exists() == false
0900:                            || lDirectoryFile.isDirectory() == false)
0901:                        throw new PSException(
0902:                                "Directory "
0903:                                        + lServiceDirectoryName
0904:                                        + " does not exist. Unable to resolve service. ServiceRef="
0905:                                        + pServiceRef);
0906:                    String lSourceArchiveFileName = lServiceDirectoryName
0907:                            + File.separator + pSourceName + ".zip";
0908:                    File lSourceArchiveFile = new File(lServiceDirectoryName
0909:                            + File.separator + pSourceName + ".zip");
0910:                    if (lSourceArchiveFile.exists() == false
0911:                            || lSourceArchiveFile.isFile() == false
0912:                            || lSourceArchiveFile.canRead() == false)
0913:                        throw new PSException(
0914:                                "Source archive "
0915:                                        + lSourceArchiveFileName
0916:                                        + " does not exist. Unable to resolve service the implementation source . ServiceRef : "
0917:                                        + pServiceRef + " SourceName : "
0918:                                        + pSourceName);
0919:                    return com.metaboss.sdlctools.types.enterprisemodel.ZipArchive
0920:                            .createFromFile(pSourceName, lSourceArchiveFile);
0921:                } catch (com.metaboss.enterprise.datatypes.DataTypeException e) {
0922:                    throw new com.metaboss.enterprise.ps.PSDatatypeOperationException(
0923:                            e);
0924:                }
0925:            }
0926:
0927:            /** Returns Service implementation source */
0928:            public static void updateServiceImplementationSource(
0929:                    String pServiceRef,
0930:                    com.metaboss.sdlctools.types.enterprisemodel.ZipArchive pSourceArchive)
0931:                    throws PSException {
0932:                if (pSourceArchive.isConcealed())
0933:                    return; // Stop unathorised updates
0934:                if (pSourceArchive.isEmpty())
0935:                    throw new PSException(
0936:                            "Unable to update source from an empty archive. ServiceRef="
0937:                                    + pServiceRef);
0938:                String lServiceDirectoryName = getServiceDirectory(pServiceRef);
0939:                File lDirectoryFile = new File(lServiceDirectoryName);
0940:                if (lDirectoryFile.exists() == false
0941:                        || lDirectoryFile.isDirectory() == false)
0942:                    throw new PSException(
0943:                            "Directory "
0944:                                    + lServiceDirectoryName
0945:                                    + " does not exist. Unable to resolve service. ServiceRef="
0946:                                    + pServiceRef);
0947:                String lSourceArchiveFileName = lServiceDirectoryName
0948:                        + File.separator + pSourceArchive.getName() + ".zip";
0949:                // Save this file
0950:                FileOutputStream lFileOutputStream = null;
0951:                try {
0952:                    lFileOutputStream = new FileOutputStream(
0953:                            lSourceArchiveFileName);
0954:                    lFileOutputStream.write(pSourceArchive.getData());
0955:                    lFileOutputStream.flush();
0956:                } catch (IOException e) {
0957:                    throw new PSException(
0958:                            "Caught exception while writing file : "
0959:                                    + lSourceArchiveFileName, e);
0960:                } finally {
0961:                    try {
0962:                        if (lFileOutputStream != null)
0963:                            lFileOutputStream.close();
0964:                    } catch (IOException e) {
0965:                    }
0966:                }
0967:            }
0968:
0969:            /** Returns DataType def or null if none found */
0970:            public static TypeTemplateDefType getTypeTemplate(
0971:                    String pTypeTemplateRef) throws PSException {
0972:                // First see if we have this object already
0973:                TypeTemplateDefType lRet = (TypeTemplateDefType) cDOMObjectsCache
0974:                        .get(pTypeTemplateRef + ";"
0975:                                + TypeTemplateDefType.class.getName());
0976:                if (lRet == null) {
0977:                    String lTypeTemplateDirectory = getTypeTemplateDirectory(pTypeTemplateRef);
0978:                    if (lTypeTemplateDirectory == null)
0979:                        throw new PSException(
0980:                                "TypeTemplate directory not found. Unable to read TypeTemplate definition. TypeTemplateRef: "
0981:                                        + pTypeTemplateRef);
0982:                    String lTypeTemplateFileName = lTypeTemplateDirectory
0983:                            + File.separator + "Descriptor.xml";
0984:                    InputStream lInputStream = null;
0985:                    try {
0986:                        lInputStream = openFileStream(lTypeTemplateFileName);
0987:                        if (lInputStream != null) {
0988:                            if ((lRet = (TypeTemplateDefType) getUnmarshaller()
0989:                                    .unmarshal(lInputStream)) != null) {
0990:                                if (!lRet.getTypeTemplateRef().equals(
0991:                                        pTypeTemplateRef))
0992:                                    throw new PSReadDataIntegrityViolationException(
0993:                                            "Mismatch between TypeTemplateRef stored in file and the one implied by its location. TypeTemplateRef : "
0994:                                                    + lRet.getTypeTemplateRef()
0995:                                                    + ", Location : "
0996:                                                    + lTypeTemplateFileName);
0997:                                cDOMObjectsCache.put(pTypeTemplateRef + ";"
0998:                                        + TypeTemplateDefType.class.getName(),
0999:                                        lRet);
1000:                            }
1001:                        }
1002:                    } catch (JAXBException e) {
1003:                        throw new PSDataSourceOperationInvocationException(
1004:                                "Exception caught during reading of Type Template. TypeTemplateRef : "
1005:                                        + pTypeTemplateRef, e);
1006:                    } finally {
1007:                        try {
1008:                            if (lInputStream != null)
1009:                                lInputStream.close();
1010:                        } catch (IOException e) {
1011:                        }
1012:                    }
1013:                }
1014:                return lRet;
1015:            }
1016:
1017:            /** Returns TypeTemplate source or null if none found */
1018:            public static String getTypeTemplateSource(String pTypeTemplateRef)
1019:                    throws PSException {
1020:                TypeTemplateDefType lDef = getTypeTemplate(pTypeTemplateRef);
1021:                String lTypeTemplateName = pTypeTemplateRef
1022:                        .substring(pTypeTemplateRef.lastIndexOf(".") + 1);
1023:                // Work on file extension
1024:                String lFileExtension = null;
1025:                TemplateSourceType lSourceType = TemplateSourceType
1026:                        .createFromString(lDef.getTypeTemplateSourceType());
1027:                if (lSourceType.equals(TemplateSourceType.VELOCITY))
1028:                    lFileExtension = "vtl";
1029:                else if (lSourceType.equals(TemplateSourceType.JAVA))
1030:                    lFileExtension = "java";
1031:                else
1032:                    throw new PSException(
1033:                            "SourceType element is empty or has invalid value. Unable to read TypeTemplate source file. TypeTemplate Ref : "
1034:                                    + pTypeTemplateRef);
1035:                String lTypeTemplateDirectory = getTypeTemplateDirectory(pTypeTemplateRef);
1036:                if (lTypeTemplateDirectory == null)
1037:                    throw new PSException(
1038:                            "TypeTemplate directory not found. Unable to read TypeTemplate source. TypeTemplateRef: "
1039:                                    + pTypeTemplateRef);
1040:                String lTypeTemplateSourceFileName = lTypeTemplateDirectory
1041:                        + File.separator + lTypeTemplateName + "."
1042:                        + lFileExtension;
1043:                // Load this file
1044:                InputStream lInputStream = null;
1045:                try {
1046:                    lInputStream = openFileStream(lTypeTemplateSourceFileName);
1047:                    if (lInputStream != null) {
1048:                        return StringUtils.readTextStreamFully(lInputStream);
1049:                    }
1050:                    throw new PSException(
1051:                            "Unable to find or read TypeTemplate source file. TypeTemplate Ref : "
1052:                                    + pTypeTemplateRef + "  Expected file : "
1053:                                    + lTypeTemplateSourceFileName);
1054:                } catch (IOException e) {
1055:                    throw new PSException(
1056:                            "Caught exception while reading file : "
1057:                                    + lTypeTemplateSourceFileName, e);
1058:                } finally {
1059:                    try {
1060:                        if (lInputStream != null)
1061:                            lInputStream.close();
1062:                    } catch (IOException e) {
1063:                    }
1064:                }
1065:            }
1066:
1067:            /** Stores given tytpe template source in its place */
1068:            public static void updateTypeTemplateSource(
1069:                    String pTypeTemplateRef, String pTypeTemplateSource)
1070:                    throws PSException {
1071:                if (pTypeTemplateRef.startsWith("."))
1072:                    throw new PSIllegalArgumentException(
1073:                            "Attempt to update public TypeTemplate. TypeTemplateRef : "
1074:                                    + pTypeTemplateRef);
1075:                TypeTemplateDefType lDef = getTypeTemplate(pTypeTemplateRef);
1076:                String lTypeTemplateName = pTypeTemplateRef
1077:                        .substring(pTypeTemplateRef.lastIndexOf("."));
1078:                // Work on file extension
1079:                String lFileExtension = null;
1080:                TemplateSourceType lSourceType = TemplateSourceType
1081:                        .createFromString(lDef.getTypeTemplateSourceType());
1082:                if (lSourceType.equals(TemplateSourceType.VELOCITY))
1083:                    lFileExtension = "vtl";
1084:                else if (lSourceType.equals(TemplateSourceType.JAVA))
1085:                    lFileExtension = "java";
1086:                else
1087:                    throw new PSException(
1088:                            "SourceType element is empty or has invalid value. Unable to read TypeTemplate source file. TypeTemplate Ref : "
1089:                                    + pTypeTemplateRef);
1090:                String lTypeTemplateDirectory = getTypeTemplateDirectory(pTypeTemplateRef);
1091:                if (lTypeTemplateDirectory == null)
1092:                    throw new PSException(
1093:                            "TypeTemplate directory not found. Unable to update TypeTemplate source. TypeTemplateRef: "
1094:                                    + pTypeTemplateRef);
1095:                String lTypeTemplateSourceFileName = lTypeTemplateDirectory
1096:                        + File.separator + lTypeTemplateName + "."
1097:                        + lFileExtension;
1098:                // Save this file
1099:                FileWriter lWriter = null;
1100:                try {
1101:                    lWriter = new FileWriter(lTypeTemplateSourceFileName, false);
1102:                    lWriter.write(pTypeTemplateSource);
1103:                } catch (IOException e) {
1104:                    throw new PSException(e);
1105:                } finally {
1106:                    if (lWriter != null) {
1107:                        try {
1108:                            lWriter.flush();
1109:                        } catch (IOException e) {
1110:                            // Ignore
1111:                        }
1112:                        try {
1113:                            lWriter.close();
1114:                        } catch (IOException e) {
1115:                            // Ignore
1116:                        }
1117:                    }
1118:                }
1119:            }
1120:
1121:            /** Returns all references to type templates stored in libraries */
1122:            public static String[] getPublicTypeTemplateRefs()
1123:                    throws PSException {
1124:                try {
1125:                    HashSet lRefs = new HashSet();
1126:                    String[] lMetaLibPath = getPublicMetaModelPath();
1127:                    for (int i = 0; i < lMetaLibPath.length; i++) {
1128:                        String lTypetemplatesLibDir = lMetaLibPath[i]
1129:                                + sTypeTemplateMetaLibSubDir;
1130:                        // Directory may not exist - just skip
1131:                        if (new File(lTypetemplatesLibDir).exists() == false)
1132:                            continue; // No typetemplates here
1133:                        String[] lAllTypeTemplateDirs = DirectoryUtils
1134:                                .listAllDescendantDirectoriesInDirectory(lTypetemplatesLibDir);
1135:                        int lPrefixLength = lTypetemplatesLibDir.length();
1136:                        for (int j = 0; j < lAllTypeTemplateDirs.length; j++) {
1137:                            String lTypetemplateDir = lAllTypeTemplateDirs[j];
1138:                            // We will only consider directory if it has Descriptor.xml in it
1139:                            File lDescriptorFile = new File(lTypetemplateDir
1140:                                    + File.separator + "Descriptor.xml");
1141:                            if (lDescriptorFile.exists()
1142:                                    && lDescriptorFile.isFile()) {
1143:                                // Cut out root dir prefix from the beginning and replace file separators with dots
1144:                                // Note that File.separator will remain in front after cutting out the root dir
1145:                                // therefore leading dot will appear after replacement
1146:                                String lTypetemplateRef = StringUtils.replace(
1147:                                        lTypetemplateDir
1148:                                                .substring(lPrefixLength),
1149:                                        File.separator, ".");
1150:                                // Add to the refs
1151:                                lRefs.add(lTypetemplateRef);
1152:                            }
1153:                        }
1154:                    }
1155:                    return (String[]) lRefs.toArray(new String[lRefs.size()]);
1156:                } catch (java.io.FileNotFoundException e) {
1157:                    throw new PSException(
1158:                            "Caught exception while scanning for Public Typetemplate references.",
1159:                            e);
1160:                }
1161:            }
1162:
1163:            /** Returns all references to universal type templates */
1164:            public static String[] getPublicDatatypeRefs() throws PSException {
1165:                try {
1166:                    HashSet lRefs = new HashSet();
1167:                    String[] lMetaLibPath = getPublicMetaModelPath();
1168:                    for (int i = 0; i < lMetaLibPath.length; i++) {
1169:                        String lDatatypesLibDir = lMetaLibPath[i]
1170:                                + sDataTypeMetaLibSubDir;
1171:                        // Directory may not exist - just skip
1172:                        if (new File(lDatatypesLibDir).exists() == false)
1173:                            continue; // No typetemplates here
1174:                        String[] lAllDataTypeDirs = DirectoryUtils
1175:                                .listAllDescendantDirectoriesInDirectory(lDatatypesLibDir);
1176:                        int lPrefixLength = lDatatypesLibDir.length();
1177:                        for (int j = 0; j < lAllDataTypeDirs.length; j++) {
1178:                            String lDataTypeDir = lAllDataTypeDirs[j];
1179:                            // We will only consider directory if it has Descriptor.xml in it
1180:                            File lDescriptorFile = new File(lDataTypeDir
1181:                                    + File.separator + "Descriptor.xml");
1182:                            if (lDescriptorFile.exists()
1183:                                    && lDescriptorFile.isFile()) {
1184:                                // Cut out root dir prefix from the beginning and replace file separators with dots
1185:                                // Note that File.separator will remain in front after cutting out the root dir
1186:                                // therefore leading dot will appear after replacement
1187:                                String lDataTypeRef = StringUtils.replace(
1188:                                        lDataTypeDir.substring(lPrefixLength),
1189:                                        File.separator, ".");
1190:                                // Add to the refs
1191:                                lRefs.add(lDataTypeRef);
1192:                            }
1193:                        }
1194:                    }
1195:                    return (String[]) lRefs.toArray(new String[lRefs.size()]);
1196:                } catch (java.io.FileNotFoundException e) {
1197:                    throw new PSException(
1198:                            "Caught exception while scanning for Public DataType references.",
1199:                            e);
1200:                }
1201:            }
1202:
1203:            // Helper. Returns fully qualified directory where data type details can be found
1204:            private static String getDataTypeDirectory(String pDataTypeRef)
1205:                    throws PSException {
1206:                // Data Type may be in public use packages (ref must begin with dot in this case)
1207:                // Otherwise DataTypeRef consists of three or more parts - enterprise name . system name [. sub package name] . datatype name
1208:                if (pDataTypeRef.startsWith(".")) {
1209:                    // Public datatype, convert its name back to the directory name
1210:                    // and try on a path until we will get it
1211:                    String lDataTypeSubdirectoryName = StringUtils.replace(
1212:                            pDataTypeRef, ".", File.separator);
1213:                    String[] lMetaLibPath = getPublicMetaModelPath();
1214:                    for (int i = 0; i < lMetaLibPath.length; i++) {
1215:                        String lProspectiveDirectoryPath = lMetaLibPath[i]
1216:                                + sDataTypeMetaLibSubDir
1217:                                + lDataTypeSubdirectoryName;
1218:                        File lProspectiveDirectory = new File(
1219:                                lProspectiveDirectoryPath);
1220:                        if (lProspectiveDirectory.exists()
1221:                                && lProspectiveDirectory.isDirectory())
1222:                            return lProspectiveDirectoryPath; // Found first hit
1223:                    }
1224:                    return null;
1225:                }
1226:                // Enterprise datatype below this point
1227:                String lProspectiveDirectoryPath = suggestEnterpriseDataTypeDirectory(pDataTypeRef);
1228:                File lProspectiveDirectory = new File(lProspectiveDirectoryPath);
1229:                if (lProspectiveDirectory.exists()
1230:                        && lProspectiveDirectory.isDirectory())
1231:                    return lProspectiveDirectoryPath; // Found first hit
1232:                return null;
1233:            }
1234:
1235:            // Helper. Returns prospective fully qualified directory where data type details can be found
1236:            // only works for enterprise datatypes
1237:            private static String suggestEnterpriseDataTypeDirectory(
1238:                    String pDataTypeRef) throws PSException {
1239:                // Data Type may be in public use packages (ref must begin with dot in this case)
1240:                // Otherwise DataTypeRef consists of three or more parts - enterprise name . system name [. sub package name] . datatype name
1241:                if (pDataTypeRef.startsWith("."))
1242:                    throw new PSIllegalArgumentException(
1243:                            "Unable to suggest directory name for the public datatype. DataTypeRef: "
1244:                                    + pDataTypeRef);
1245:                // Enterprise datatype below this point
1246:                StringBuffer lDataTypeDirectoryName = new StringBuffer();
1247:                StringTokenizer lTokenizer = new StringTokenizer(pDataTypeRef,
1248:                        ".", false);
1249:                int lTokenCount = lTokenizer.countTokens();
1250:                if (lTokenCount < 3)
1251:                    throw new PSIllegalArgumentException(
1252:                            "Invalid DataTypeRef: " + pDataTypeRef);
1253:                String lEnterpriseName = lTokenizer.nextToken();
1254:                String lSystemName = lTokenizer.nextToken();
1255:                lDataTypeDirectoryName.append(cEnterpriseRootDir);
1256:                lDataTypeDirectoryName.append(File.separator);
1257:                lDataTypeDirectoryName.append(lEnterpriseName);
1258:                lDataTypeDirectoryName.append(File.separator);
1259:                lDataTypeDirectoryName.append(cEnterpriseSystemsSubDir);
1260:                lDataTypeDirectoryName.append(File.separator);
1261:                lDataTypeDirectoryName.append(lSystemName);
1262:                lDataTypeDirectoryName.append(File.separator);
1263:                lDataTypeDirectoryName.append(cEnterpriseDatatypesSubDir);
1264:                // Append posible subdirectories
1265:                if (lTokenCount == 3) {
1266:                    lDataTypeDirectoryName.append(File.separator);
1267:                    lDataTypeDirectoryName.append("-");
1268:                } else {
1269:                    for (int i = 2; i < lTokenCount - 1; i++) {
1270:                        lDataTypeDirectoryName.append(File.separator);
1271:                        lDataTypeDirectoryName.append(lTokenizer.nextToken());
1272:                    }
1273:                }
1274:                lDataTypeDirectoryName.append(File.separator);
1275:                lDataTypeDirectoryName.append(cDatatypesSubDir);
1276:                lDataTypeDirectoryName.append(File.separator);
1277:                lDataTypeDirectoryName.append(lTokenizer.nextToken());
1278:                return lDataTypeDirectoryName.toString();
1279:            }
1280:
1281:            // Helper. Returns fully qualified directory where system details can be found
1282:            private static String getSystemDirectory(String pSystemRef)
1283:                    throws PSException {
1284:                // SystemRef always consists of two parts - enterprise name . system name
1285:                StringTokenizer lTokenizer = new StringTokenizer(pSystemRef,
1286:                        ".", false);
1287:                if (lTokenizer.countTokens() != 2)
1288:                    throw new PSException("Invalid SystemRef: " + pSystemRef);
1289:                String lEnterpriseName = lTokenizer.nextToken();
1290:                String lSystemName = lTokenizer.nextToken();
1291:
1292:                // Build the name
1293:                StringBuffer lSystemDirectoryName = new StringBuffer();
1294:                lSystemDirectoryName.append(cEnterpriseRootDir);
1295:                lSystemDirectoryName.append(File.separator);
1296:                lSystemDirectoryName.append(lEnterpriseName);
1297:                lSystemDirectoryName.append(File.separator);
1298:                lSystemDirectoryName.append(cEnterpriseSystemsSubDir);
1299:                lSystemDirectoryName.append(File.separator);
1300:                lSystemDirectoryName.append(lSystemName);
1301:                return lSystemDirectoryName.toString();
1302:            }
1303:
1304:            // Helper. Returns fully qualified directory where enterprise details can be found
1305:            private static String getEnterpriseDirectory(String pEnterpriseRef)
1306:                    throws PSException {
1307:                // SystemRef always consists of two parts - enterprise name . system name
1308:                StringTokenizer lTokenizer = new StringTokenizer(
1309:                        pEnterpriseRef, ".", false);
1310:                if (lTokenizer.countTokens() != 1)
1311:                    throw new PSIllegalArgumentException(
1312:                            "Invalid EnterpriseRef: " + pEnterpriseRef);
1313:                String lEnterpriseName = lTokenizer.nextToken();
1314:                // Build the name
1315:                StringBuffer lEnterpriseDirectoryName = new StringBuffer();
1316:                lEnterpriseDirectoryName.append(cEnterpriseRootDir);
1317:                lEnterpriseDirectoryName.append(File.separator);
1318:                lEnterpriseDirectoryName.append(lEnterpriseName);
1319:                return lEnterpriseDirectoryName.toString();
1320:            }
1321:
1322:            // Helper. Returns fully qualified directory where service details can be found
1323:            private static String getServiceDirectory(String pServiceRef)
1324:                    throws PSException {
1325:                // Service ref consists of four parts - enterprise name . system name . servicemodule name . service name
1326:                StringTokenizer lTokenizer = new StringTokenizer(pServiceRef,
1327:                        ".", false);
1328:                int lTokenCount = lTokenizer.countTokens();
1329:                if (lTokenCount != 4)
1330:                    throw new PSException("Invalid ServiceRef : " + pServiceRef);
1331:                // Build the name
1332:                StringBuffer lServiceDirectoryName = new StringBuffer();
1333:                lServiceDirectoryName.append(cEnterpriseRootDir);
1334:                lServiceDirectoryName.append(File.separator);
1335:                lServiceDirectoryName.append(lTokenizer.nextToken()); // Enterprise
1336:                lServiceDirectoryName.append(File.separator);
1337:                lServiceDirectoryName.append(cEnterpriseSystemsSubDir);
1338:                lServiceDirectoryName.append(File.separator);
1339:                lServiceDirectoryName.append(lTokenizer.nextToken()); // System
1340:                lServiceDirectoryName.append(File.separator);
1341:                lServiceDirectoryName.append(cEnterpriseServicemodulesSubDir);
1342:                lServiceDirectoryName.append(File.separator);
1343:                lServiceDirectoryName.append(lTokenizer.nextToken()); // Servicemodule
1344:                lServiceDirectoryName.append(File.separator);
1345:                lServiceDirectoryName
1346:                        .append(cEnterpriseServicemodulesServicesSubDir);
1347:                lServiceDirectoryName.append(File.separator);
1348:                lServiceDirectoryName.append(lTokenizer.nextToken()); // Service name
1349:                return lServiceDirectoryName.toString();
1350:            }
1351:
1352:            // Helper. Returns fully qualified directory where service details can be found
1353:            private static String getServicemoduleDirectory(
1354:                    String pServicemoduleRef) throws PSException {
1355:                // Servicemodule ref consists of three  parts - enterprise name . system name . servicemodule name
1356:                StringTokenizer lTokenizer = new StringTokenizer(
1357:                        pServicemoduleRef, ".", false);
1358:                int lTokenCount = lTokenizer.countTokens();
1359:                if (lTokenCount != 3)
1360:                    throw new PSException("Invalid ServicemoduleRef : "
1361:                            + pServicemoduleRef);
1362:                // Build the name
1363:                StringBuffer lServicemoduleDirectoryName = new StringBuffer();
1364:                lServicemoduleDirectoryName.append(cEnterpriseRootDir);
1365:                lServicemoduleDirectoryName.append(File.separator);
1366:                lServicemoduleDirectoryName.append(lTokenizer.nextToken()); // Enterprise
1367:                lServicemoduleDirectoryName.append(File.separator);
1368:                lServicemoduleDirectoryName.append(cEnterpriseSystemsSubDir);
1369:                lServicemoduleDirectoryName.append(File.separator);
1370:                lServicemoduleDirectoryName.append(lTokenizer.nextToken()); // System
1371:                lServicemoduleDirectoryName.append(File.separator);
1372:                lServicemoduleDirectoryName
1373:                        .append(cEnterpriseServicemodulesSubDir);
1374:                lServicemoduleDirectoryName.append(File.separator);
1375:                lServicemoduleDirectoryName.append(lTokenizer.nextToken()); // Servicemodulemodule
1376:                return lServicemoduleDirectoryName.toString();
1377:            }
1378:
1379:            // Helper. Returns fully qualified directory where type template details can be found
1380:            private static String getTypeTemplateDirectory(
1381:                    String pTypeTemplateRef) throws PSException {
1382:                // Typetemplate may be in public use packages (ref must begin with dot in this case)
1383:                // Otherwise TypeTemplateRef consists of three or more parts - enterprise name . system name [. sub package name] . typetemplate name
1384:                if (pTypeTemplateRef.startsWith(".")) {
1385:                    // Public typetemplate, convert its name back to the directory name
1386:                    // and try on a path until we will get it
1387:                    String lTypeTemplateSubdirectoryName = StringUtils.replace(
1388:                            pTypeTemplateRef, ".", File.separator);
1389:                    String[] lMetaLibPath = getPublicMetaModelPath();
1390:                    for (int i = 0; i < lMetaLibPath.length; i++) {
1391:                        String lProspectiveDirectoryPath = lMetaLibPath[i]
1392:                                + sTypeTemplateMetaLibSubDir
1393:                                + lTypeTemplateSubdirectoryName;
1394:                        File lProspectiveDirectory = new File(
1395:                                lProspectiveDirectoryPath);
1396:                        if (lProspectiveDirectory.exists()
1397:                                && lProspectiveDirectory.isDirectory())
1398:                            return lProspectiveDirectoryPath; // Found first hit
1399:                    }
1400:                    return null;
1401:                }
1402:                // Enterprise typetemplate below this point
1403:                String lProspectiveDirectoryPath = suggestEnterpriseTypeTemplateDirectory(pTypeTemplateRef);
1404:                File lProspectiveDirectory = new File(lProspectiveDirectoryPath);
1405:                if (lProspectiveDirectory.exists()
1406:                        && lProspectiveDirectory.isDirectory())
1407:                    return lProspectiveDirectoryPath; // Found first hit
1408:                return null;
1409:            }
1410:
1411:            // Helper. Returns prospective fully qualified directory where typetemplate details can be found
1412:            // only works for enterprise typetemplates
1413:            private static String suggestEnterpriseTypeTemplateDirectory(
1414:                    String pTypeTemplateRef) throws PSException {
1415:                // Typetemplate may be in public use packages (ref must begin with dot in this case)
1416:                // Otherwise TypetemplateRef consists of three or more parts - enterprise name . system name [. sub package name] . typetemplate name
1417:                if (pTypeTemplateRef.startsWith("."))
1418:                    throw new PSIllegalArgumentException(
1419:                            "Unable to suggest directory name for the public typetemplate. TypeTemplateRef: "
1420:                                    + pTypeTemplateRef);
1421:                // Enterprise typetemplate below this point
1422:                StringBuffer lTypeTemplateDirectoryName = new StringBuffer();
1423:                StringTokenizer lTokenizer = new StringTokenizer(
1424:                        pTypeTemplateRef, ".", false);
1425:                int lTokenCount = lTokenizer.countTokens();
1426:                if (lTokenCount < 3)
1427:                    throw new PSIllegalArgumentException(
1428:                            "Invalid TypeTemplateRef: " + pTypeTemplateRef);
1429:                String lEnterpriseName = lTokenizer.nextToken();
1430:                String lSystemName = lTokenizer.nextToken();
1431:                lTypeTemplateDirectoryName.append(cEnterpriseRootDir);
1432:                lTypeTemplateDirectoryName.append(File.separator);
1433:                lTypeTemplateDirectoryName.append(lEnterpriseName);
1434:                lTypeTemplateDirectoryName.append(File.separator);
1435:                lTypeTemplateDirectoryName.append(cEnterpriseSystemsSubDir);
1436:                lTypeTemplateDirectoryName.append(File.separator);
1437:                lTypeTemplateDirectoryName.append(lSystemName);
1438:                lTypeTemplateDirectoryName.append(File.separator);
1439:                lTypeTemplateDirectoryName.append(cEnterpriseDatatypesSubDir);
1440:                // Append posible subdirectories
1441:                if (lTokenCount == 3) {
1442:                    lTypeTemplateDirectoryName.append(File.separator);
1443:                    lTypeTemplateDirectoryName.append("-");
1444:                } else {
1445:                    for (int i = 1; i < lTokenCount - 1; i++) {
1446:                        lTypeTemplateDirectoryName.append(File.separator);
1447:                        lTypeTemplateDirectoryName.append(lTokenizer
1448:                                .nextToken());
1449:                    }
1450:                }
1451:                lTypeTemplateDirectoryName.append(File.separator);
1452:                lTypeTemplateDirectoryName.append(cTypetemplatesSubDir);
1453:                lTypeTemplateDirectoryName.append(File.separator);
1454:                lTypeTemplateDirectoryName.append(lTokenizer.nextToken());
1455:                return lTypeTemplateDirectoryName.toString();
1456:            }
1457:
1458:            /** Returns Entity def or null if none found */
1459:            public static EntityDefType getEntity(String pEntityRef)
1460:                    throws PSException {
1461:                // First see if we have this object already
1462:                EntityDefType lRet = (EntityDefType) cDOMObjectsCache
1463:                        .get(pEntityRef + ";" + EntityDefType.class.getName());
1464:                if (lRet == null) {
1465:                    // EntityRef always consists of four parts - enterprise name . system name . domain name . entity name
1466:                    StringTokenizer lTokenizer = new StringTokenizer(
1467:                            pEntityRef, ".", false);
1468:                    if (lTokenizer.countTokens() != 4)
1469:                        throw new PSException("Invalid EntityRef: "
1470:                                + pEntityRef);
1471:                    String lEnterpriseName = lTokenizer.nextToken();
1472:                    String lSystemName = lTokenizer.nextToken();
1473:                    String lDomainName = lTokenizer.nextToken();
1474:                    String lEntityName = lTokenizer.nextToken();
1475:                    DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
1476:                            + lSystemName + "." + lDomainName);
1477:                    List lEntities = lDomainDef.getEntityDefList()
1478:                            .getEntityDef();
1479:                    Iterator lIter = lEntities.iterator();
1480:                    while (lIter.hasNext()) {
1481:                        EntityDefType lEntityDef = (EntityDefType) lIter.next();
1482:                        if (lEntityDef.getEntityRef().equals(pEntityRef)) {
1483:                            cDOMObjectsCache.put(pEntityRef + ";"
1484:                                    + EntityDefType.class.getName(),
1485:                                    lRet = lEntityDef);
1486:                            break;
1487:                        }
1488:                    }
1489:                }
1490:                return lRet;
1491:            }
1492:
1493:            /** Returns Report def or null if none found */
1494:            public static ReportDefType getReport(String pReportRef)
1495:                    throws PSException {
1496:                // First see if we have this object already
1497:                ReportDefType lRet = (ReportDefType) cDOMObjectsCache
1498:                        .get(pReportRef + ";" + ReportDefType.class.getName());
1499:                if (lRet == null) {
1500:                    // ReportRef always consists of four parts - enterprise name . system name . domain name . report name
1501:                    StringTokenizer lTokenizer = new StringTokenizer(
1502:                            pReportRef, ".", false);
1503:                    if (lTokenizer.countTokens() != 4)
1504:                        throw new PSException("Invalid ReportRef: "
1505:                                + pReportRef);
1506:                    String lEnterpriseName = lTokenizer.nextToken();
1507:                    String lSystemName = lTokenizer.nextToken();
1508:                    String lDomainName = lTokenizer.nextToken();
1509:                    String lReportName = lTokenizer.nextToken();
1510:                    DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
1511:                            + lSystemName + "." + lDomainName);
1512:                    List lReports = lDomainDef.getReportDefList()
1513:                            .getReportDef();
1514:                    Iterator lIter = lReports.iterator();
1515:                    while (lIter.hasNext()) {
1516:                        ReportDefType lReportDef = (ReportDefType) lIter.next();
1517:                        if (lReportDef.getReportRef().equals(pReportRef)) {
1518:                            cDOMObjectsCache.put(pReportRef + ";"
1519:                                    + ReportDefType.class.getName(),
1520:                                    lRet = lReportDef);
1521:                            break;
1522:                        }
1523:                    }
1524:                }
1525:                return lRet;
1526:            }
1527:
1528:            /** Returns Service def or null if none found */
1529:            public static ServiceDefType getService(String pServiceRef)
1530:                    throws PSException {
1531:                // First see if we have this object already
1532:                ServiceDefType lRet = (ServiceDefType) cDOMObjectsCache
1533:                        .get(pServiceRef + ";" + ServiceDefType.class.getName());
1534:                if (lRet == null) {
1535:                    // ServiceRef always consists of four parts - enterprise name . system name . servicemodule name . service name
1536:                    StringTokenizer lTokenizer = new StringTokenizer(
1537:                            pServiceRef, ".", false);
1538:                    if (lTokenizer.countTokens() != 4)
1539:                        throw new PSException("Invalid ServiceRef: "
1540:                                + pServiceRef);
1541:                    String lEnterpriseName = lTokenizer.nextToken();
1542:                    String lSystemName = lTokenizer.nextToken();
1543:                    String lServicemoduleName = lTokenizer.nextToken();
1544:                    String lServiceName = lTokenizer.nextToken();
1545:                    ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
1546:                            + "." + lSystemName + "." + lServicemoduleName);
1547:                    if (lServicemoduleDef == null)
1548:                        return null; // Servicemodule does not exist, so is service
1549:                    List lServices = lServicemoduleDef.getServiceDefList()
1550:                            .getServiceDef();
1551:                    Iterator lIter = lServices.iterator();
1552:                    while (lIter.hasNext()) {
1553:                        ServiceDefType lServiceDef = (ServiceDefType) lIter
1554:                                .next();
1555:                        if (lServiceDef.getServiceRef().equals(pServiceRef)) {
1556:                            cDOMObjectsCache.put(pServiceRef + ";"
1557:                                    + ServiceDefType.class.getName(),
1558:                                    lRet = lServiceDef);
1559:                            break;
1560:                        }
1561:                    }
1562:                }
1563:                return lRet;
1564:            }
1565:
1566:            /** Returns Servicemodule def or null if none found */
1567:            public static ServicemoduleDefType getServicemodule(
1568:                    String pServicemoduleRef) throws PSException {
1569:                // First see if we have this object already
1570:                ServicemoduleDefType lRet = (ServicemoduleDefType) cDOMObjectsCache
1571:                        .get(pServicemoduleRef + ";"
1572:                                + ServicemoduleDefType.class.getName());
1573:                if (lRet == null) {
1574:                    // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
1575:                    StringTokenizer lTokenizer = new StringTokenizer(
1576:                            pServicemoduleRef, ".", false);
1577:                    if (lTokenizer.countTokens() != 3)
1578:                        throw new PSException("Invalid ServicemoduleRef: "
1579:                                + pServicemoduleRef);
1580:                    String lEnterpriseName = lTokenizer.nextToken();
1581:                    String lSystemName = lTokenizer.nextToken();
1582:                    String lServicemoduleName = lTokenizer.nextToken();
1583:                    String lServicemoduleFileName = cEnterpriseRootDir
1584:                            + File.separator + lEnterpriseName + File.separator
1585:                            + cEnterpriseSystemsSubDir + File.separator
1586:                            + lSystemName + File.separator
1587:                            + cEnterpriseServicemodulesSubDir + File.separator
1588:                            + lServicemoduleName
1589:                            + "ServicemoduleDescriptor.xml";
1590:                    File lServicemoduleFile = new File(lServicemoduleFileName);
1591:                    if (lServicemoduleFile.exists() == false)
1592:                        return null;
1593:                    InputStream lInputStream = null;
1594:                    try {
1595:                        lInputStream = openFileStream(lServicemoduleFileName);
1596:                        if (lInputStream != null) {
1597:                            if ((lRet = (ServicemoduleDefType) getUnmarshaller()
1598:                                    .unmarshal(lInputStream)) != null) {
1599:                                if (!lRet.getServicemoduleRef().equals(
1600:                                        pServicemoduleRef))
1601:                                    throw new PSReadDataIntegrityViolationException(
1602:                                            "Mismatch between ServicemoduleRef stored in file and the one implied by its location. ServicemoduleRef : "
1603:                                                    + lRet
1604:                                                            .getServicemoduleRef()
1605:                                                    + ", Location : "
1606:                                                    + lServicemoduleFileName);
1607:                                cDOMObjectsCache.put(pServicemoduleRef + ";"
1608:                                        + ServicemoduleDefType.class.getName(),
1609:                                        lRet);
1610:                            }
1611:                        }
1612:                    } catch (JAXBException e) {
1613:                        throw new PSDataSourceOperationInvocationException(e);
1614:                    } finally {
1615:                        try {
1616:                            if (lInputStream != null)
1617:                                lInputStream.close();
1618:                        } catch (IOException e) {
1619:                        }
1620:                    }
1621:                }
1622:                return lRet;
1623:            }
1624:
1625:            /** Inserts new Servicemodule def */
1626:            public static void insertServicemodule(
1627:                    ServicemoduleDefType pServicemoduleDef) throws PSException {
1628:                try {
1629:                    try {
1630:                        getValidator().validate(pServicemoduleDef);
1631:                    } catch (ValidationException e) {
1632:                        throw new PSContentConstraintViolationException(
1633:                                "Servicemodule definition validation exception. ServicemoduleRef: "
1634:                                        + pServicemoduleDef
1635:                                                .getServicemoduleRef(), e);
1636:                    }
1637:
1638:                    // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
1639:                    StringTokenizer lTokenizer = new StringTokenizer(
1640:                            pServicemoduleDef.getServicemoduleRef(), ".", false);
1641:                    if (lTokenizer.countTokens() != 3)
1642:                        throw new PSException("Invalid ServicemoduleRef: "
1643:                                + pServicemoduleDef.getServicemoduleRef());
1644:                    String lEnterpriseName = lTokenizer.nextToken();
1645:                    String lSystemName = lTokenizer.nextToken();
1646:                    String lServicemoduleName = lTokenizer.nextToken();
1647:                    String lServicemoduleFileName = cEnterpriseRootDir
1648:                            + File.separator + lEnterpriseName + File.separator
1649:                            + cEnterpriseSystemsSubDir + File.separator
1650:                            + lSystemName + File.separator
1651:                            + cEnterpriseServicemodulesSubDir + File.separator
1652:                            + lServicemoduleName
1653:                            + "ServicemoduleDescriptor.xml";
1654:                    File lServicemoduleFile = new File(lServicemoduleFileName);
1655:                    if (lServicemoduleFile.exists() == true)
1656:                        throw new PSException(
1657:                                "File "
1658:                                        + lServicemoduleFileName
1659:                                        + " already exists. Unable to insert servicemodule. ServicemoduleRef: "
1660:                                        + pServicemoduleDef
1661:                                                .getServicemoduleRef());
1662:                    // Ensure that system exists
1663:                    File lSystemServicemodulesDirectoryFile = lServicemoduleFile
1664:                            .getParentFile();
1665:                    File lSystemDirectoryFile = lSystemServicemodulesDirectoryFile
1666:                            .getParentFile();
1667:                    if (lSystemDirectoryFile.exists() == false)
1668:                        throw new PSException(
1669:                                "Attempt to insert Servicemodule into non existant System. ServicemoduleRef: "
1670:                                        + pServicemoduleDef
1671:                                                .getServicemoduleRef());
1672:                    DirectoryUtils
1673:                            .ensureThereIsDirectory(lSystemServicemodulesDirectoryFile
1674:                                    .getAbsolutePath());
1675:                    // Clean up the cache prior to saving the new file
1676:                    cDOMObjectsCache.remove(pServicemoduleDef
1677:                            .getServicemoduleRef()
1678:                            + ";" + ServicemoduleDefType.class.getName());
1679:                    FileOutputStream lFileOutputStream = null;
1680:                    try {
1681:                        lFileOutputStream = new FileOutputStream(
1682:                                lServicemoduleFile);
1683:                        getMarshaller().marshal(pServicemoduleDef,
1684:                                lFileOutputStream);
1685:                        lFileOutputStream.flush();
1686:                        lFileOutputStream.close();
1687:                        lFileOutputStream = null;
1688:                        cDOMObjectsCache.put(pServicemoduleDef
1689:                                .getServicemoduleRef()
1690:                                + ";" + ServicemoduleDefType.class.getName(),
1691:                                pServicemoduleDef);
1692:                    } catch (IOException e) {
1693:                        throw new PSException(
1694:                                "Caught exception while writing file : "
1695:                                        + lServicemoduleFileName, e);
1696:                    } finally {
1697:                        try {
1698:                            if (lFileOutputStream != null)
1699:                                lFileOutputStream.close();
1700:                        } catch (IOException e) {
1701:                        }
1702:                    }
1703:                } catch (JAXBException e) {
1704:                    throw new PSDataSourceOperationInvocationException(e);
1705:                }
1706:            }
1707:
1708:            /** Inserts new Enterprise def */
1709:            public static void insertEnterprise(EnterpriseDefType pEnterpriseDef)
1710:                    throws PSException {
1711:                try {
1712:                    try {
1713:                        getValidator().validate(pEnterpriseDef);
1714:                    } catch (ValidationException e) {
1715:                        throw new PSContentConstraintViolationException(
1716:                                "Enterprise definition validation exception. EnterpriseRef: "
1717:                                        + pEnterpriseDef.getEnterpriseRef(), e);
1718:                    }
1719:
1720:                    // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
1721:                    StringTokenizer lTokenizer = new StringTokenizer(
1722:                            pEnterpriseDef.getEnterpriseRef(), ".", false);
1723:                    if (lTokenizer.countTokens() != 1)
1724:                        throw new PSException("Invalid EnterpriseRef: "
1725:                                + pEnterpriseDef.getEnterpriseRef());
1726:                    String lEnterpriseName = lTokenizer.nextToken();
1727:                    String lEnterpriseFileName = cEnterpriseRootDir
1728:                            + File.separator + lEnterpriseName + File.separator
1729:                            + "Descriptor.xml";
1730:                    File lEnterpriseFile = new File(lEnterpriseFileName);
1731:                    if (lEnterpriseFile.exists() == true)
1732:                        throw new PSException(
1733:                                "File "
1734:                                        + lEnterpriseFileName
1735:                                        + " already exists. Unable to insert enterprise. EnterpriseRef: "
1736:                                        + pEnterpriseDef.getEnterpriseRef());
1737:                    // Ensure that system exists
1738:                    File lEnterpriseDirectoryFile = lEnterpriseFile
1739:                            .getParentFile();
1740:                    DirectoryUtils
1741:                            .ensureThereIsDirectory(lEnterpriseDirectoryFile
1742:                                    .getAbsolutePath());
1743:                    // Clean up the cache prior to saving the new file
1744:                    cDOMObjectsCache.remove(pEnterpriseDef.getEnterpriseRef()
1745:                            + ";" + EnterpriseDefType.class.getName());
1746:                    FileOutputStream lFileOutputStream = null;
1747:                    try {
1748:                        lFileOutputStream = new FileOutputStream(
1749:                                lEnterpriseFile);
1750:                        getMarshaller().marshal(pEnterpriseDef,
1751:                                lFileOutputStream);
1752:                        lFileOutputStream.flush();
1753:                        lFileOutputStream.close();
1754:                        lFileOutputStream = null;
1755:                        cDOMObjectsCache.put(pEnterpriseDef.getEnterpriseRef()
1756:                                + ";" + EnterpriseDefType.class.getName(),
1757:                                pEnterpriseDef);
1758:                    } catch (IOException e) {
1759:                        throw new PSException(
1760:                                "Caught exception while writing file : "
1761:                                        + lEnterpriseFileName, e);
1762:                    } finally {
1763:                        try {
1764:                            if (lFileOutputStream != null)
1765:                                lFileOutputStream.close();
1766:                        } catch (IOException e) {
1767:                        }
1768:                    }
1769:                } catch (JAXBException e) {
1770:                    throw new PSDataSourceOperationInvocationException(e);
1771:                }
1772:            }
1773:
1774:            /** Inserts new system def */
1775:            public static void insertSystem(SystemDefType pSystemDef)
1776:                    throws PSException {
1777:                try {
1778:                    try {
1779:                        getValidator().validate(pSystemDef);
1780:                    } catch (ValidationException e) {
1781:                        throw new PSContentConstraintViolationException(
1782:                                "System definition validation exception. SystemRef: "
1783:                                        + pSystemDef.getSystemRef(), e);
1784:                    }
1785:                    String lSystemDirectoryName = getSystemDirectory(pSystemDef
1786:                            .getSystemRef());
1787:                    File lSystemDirectory = new File(lSystemDirectoryName);
1788:                    if (lSystemDirectory.exists())
1789:                        throw new PSException(
1790:                                "Directory "
1791:                                        + lSystemDirectoryName
1792:                                        + " already exists. Unable to create system. SystemRef: "
1793:                                        + pSystemDef.getSystemRef());
1794:                    DirectoryUtils.ensureThereIsDirectory(lSystemDirectory
1795:                            .getAbsolutePath());
1796:                    String lSystemFileName = lSystemDirectoryName
1797:                            + File.separator + "Descriptor.xml";
1798:                    File lSystemFile = new File(lSystemFileName);
1799:                    FileOutputStream lFileOutputStream = null;
1800:                    try {
1801:                        lFileOutputStream = new FileOutputStream(lSystemFile);
1802:                        getMarshaller().marshal(pSystemDef, lFileOutputStream);
1803:                        lFileOutputStream.flush();
1804:                        lFileOutputStream.close();
1805:                        lFileOutputStream = null;
1806:                        cDOMObjectsCache.put(pSystemDef.getSystemRef() + ";"
1807:                                + SystemDefType.class.getName(), pSystemDef);
1808:                    } catch (IOException e) {
1809:                        throw new PSException(
1810:                                "Caught exception while writing file : "
1811:                                        + lSystemFileName, e);
1812:                    } finally {
1813:                        try {
1814:                            if (lFileOutputStream != null)
1815:                                lFileOutputStream.close();
1816:                        } catch (IOException e) {
1817:                        }
1818:                    }
1819:                } catch (JAXBException e) {
1820:                    throw new PSDataSourceOperationInvocationException(e);
1821:                }
1822:            }
1823:
1824:            /** Inserts new service def */
1825:            public static void insertService(ServiceDefType pServiceDef)
1826:                    throws PSException {
1827:                try {
1828:                    getValidator().validate(pServiceDef);
1829:                } catch (ValidationException e) {
1830:                    throw new PSContentConstraintViolationException(
1831:                            "Service definition validation exception. ServiceRef: "
1832:                                    + pServiceDef.getServiceRef(), e);
1833:                } catch (JAXBException e) {
1834:                    throw new PSDataSourceOperationInvocationException(e);
1835:                }
1836:
1837:                if (getService(pServiceDef.getServiceRef()) != null)
1838:                    throw new PSException(
1839:                            "Attempt to insert alredy existing Service into Servicemodule. ServiceRef: "
1840:                                    + pServiceDef.getServiceRef());
1841:                // ServiceRef always consists of four parts - enterprise name . system name . servicemodule name . service name
1842:                StringTokenizer lTokenizer = new StringTokenizer(pServiceDef
1843:                        .getServiceRef(), ".", false);
1844:                if (lTokenizer.countTokens() != 4)
1845:                    throw new PSException("Invalid ServiceRef: "
1846:                            + pServiceDef.getServiceRef());
1847:                String lEnterpriseName = lTokenizer.nextToken();
1848:                String lSystemName = lTokenizer.nextToken();
1849:                String lServicemoduleName = lTokenizer.nextToken();
1850:                String lServiceName = lTokenizer.nextToken();
1851:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
1852:                        + "." + lSystemName + "." + lServicemoduleName);
1853:                if (lServicemoduleDef == null)
1854:                    throw new PSException(
1855:                            "Attempt to insert Service into Servicemodule, which does not exists. ServiceRef: "
1856:                                    + pServiceDef.getServiceRef());
1857:                lServicemoduleDef.getServiceDefList().getServiceDef().add(
1858:                        pServiceDef);
1859:                updateServicemodule(lServicemoduleDef);
1860:                cDOMObjectsCache.put(pServiceDef.getServiceRef() + ";"
1861:                        + ServiceDefType.class.getName(), pServiceDef);
1862:            }
1863:
1864:            /** Updates service details on storage */
1865:            public static void updateService(ServiceDefType pServiceDef)
1866:                    throws PSException {
1867:                try {
1868:                    getValidator().validate(pServiceDef);
1869:                } catch (ValidationException e) {
1870:                    throw new PSContentConstraintViolationException(
1871:                            "Service definition validation exception. ServiceRef: "
1872:                                    + pServiceDef.getServiceRef(), e);
1873:                } catch (JAXBException e) {
1874:                    throw new PSDataSourceOperationInvocationException(e);
1875:                }
1876:
1877:                ServiceDefType lCurrentCopy = getService(pServiceDef
1878:                        .getServiceRef());
1879:                if (lCurrentCopy == null)
1880:                    throw new PSException(
1881:                            "Attempt to update Service, which does not exists. ServiceRef: "
1882:                                    + pServiceDef.getServiceRef());
1883:                // ServiceRef always consists of four parts - enterprise name . system name . servicemodule name . service name
1884:                StringTokenizer lTokenizer = new StringTokenizer(pServiceDef
1885:                        .getServiceRef(), ".", false);
1886:                if (lTokenizer.countTokens() != 4)
1887:                    throw new PSException("Invalid ServiceRef: "
1888:                            + pServiceDef.getServiceRef());
1889:                String lEnterpriseName = lTokenizer.nextToken();
1890:                String lSystemName = lTokenizer.nextToken();
1891:                String lServicemoduleName = lTokenizer.nextToken();
1892:                String lServiceName = lTokenizer.nextToken();
1893:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
1894:                        + "." + lSystemName + "." + lServicemoduleName);
1895:                if (lServicemoduleDef == null)
1896:                    throw new PSException(
1897:                            "Attempt to update Service into Servicemodule, which does not exists. ServiceRef: "
1898:                                    + pServiceDef.getServiceRef());
1899:                cDOMObjectsCache.remove(pServiceDef.getServiceRef() + ";"
1900:                        + ServiceDefType.class.getName());
1901:                if (!lServicemoduleDef.getServiceDefList().getServiceDef()
1902:                        .remove(lCurrentCopy))
1903:                    throw new PSUnexpectedProgramConditionException(
1904:                            "Remove of previous version of the service definition has failed. ServiceRef: "
1905:                                    + pServiceDef.getServiceRef());
1906:                lServicemoduleDef.getServiceDefList().getServiceDef().add(
1907:                        pServiceDef);
1908:                updateServicemodule(lServicemoduleDef);
1909:                cDOMObjectsCache.put(pServiceDef.getServiceRef() + ";"
1910:                        + ServiceDefType.class.getName(), pServiceDef);
1911:            }
1912:
1913:            /** Returns Structure def or null if none found */
1914:            public static StructureDefType getStructure(String pStructureRef)
1915:                    throws PSException {
1916:                // First see if we have this object already
1917:                StructureDefType lRet = (StructureDefType) cDOMObjectsCache
1918:                        .get(pStructureRef + ";"
1919:                                + StructureDefType.class.getName());
1920:                if (lRet == null) {
1921:                    // StructureRef always consists of four parts - enterprise name . system name . servicemodule name . structure name
1922:                    StringTokenizer lTokenizer = new StringTokenizer(
1923:                            pStructureRef, ".", false);
1924:                    if (lTokenizer.countTokens() != 4)
1925:                        throw new PSException("Invalid StructureRef: "
1926:                                + pStructureRef);
1927:                    String lEnterpriseName = lTokenizer.nextToken();
1928:                    String lSystemName = lTokenizer.nextToken();
1929:                    String lServicemoduleName = lTokenizer.nextToken();
1930:                    String lStructureName = lTokenizer.nextToken();
1931:                    String lServicemoduleRef = lEnterpriseName + "."
1932:                            + lSystemName + "." + lServicemoduleName;
1933:                    ServicemoduleDefType lServicemoduleDef = getServicemodule(lServicemoduleRef);
1934:                    if (lServicemoduleDef == null)
1935:                        throw new PSException(
1936:                                "Servicemodule not found. ServicemoduleRef: "
1937:                                        + lServicemoduleRef);
1938:                    List lStructures = lServicemoduleDef.getStructureDefList()
1939:                            .getStructureDef();
1940:                    Iterator lIter = lStructures.iterator();
1941:                    while (lIter.hasNext()) {
1942:                        StructureDefType lStructureDef = (StructureDefType) lIter
1943:                                .next();
1944:                        if (lStructureDef.getStructureRef().equals(
1945:                                pStructureRef)) {
1946:                            cDOMObjectsCache.put(pStructureRef + ";"
1947:                                    + StructureDefType.class.getName(),
1948:                                    lRet = lStructureDef);
1949:                            break;
1950:                        }
1951:                    }
1952:                }
1953:                return lRet;
1954:            }
1955:
1956:            /** Returns Message def or null if none found */
1957:            public static MessageDefType getMessage(String pMessageRef)
1958:                    throws PSException {
1959:                // First see if we have this object already
1960:                MessageDefType lRet = (MessageDefType) cDOMObjectsCache
1961:                        .get(pMessageRef + ";" + MessageDefType.class.getName());
1962:                if (lRet == null) {
1963:                    // MessageRef always consists of four parts - enterprise name . system name . servicemodule name . message name
1964:                    StringTokenizer lTokenizer = new StringTokenizer(
1965:                            pMessageRef, ".", false);
1966:                    if (lTokenizer.countTokens() != 4)
1967:                        throw new PSException("Invalid MessageRef: "
1968:                                + pMessageRef);
1969:                    String lEnterpriseName = lTokenizer.nextToken();
1970:                    String lSystemName = lTokenizer.nextToken();
1971:                    String lServicemoduleName = lTokenizer.nextToken();
1972:                    String lMessageName = lTokenizer.nextToken();
1973:                    ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
1974:                            + "." + lSystemName + "." + lServicemoduleName);
1975:                    List lMessages = lServicemoduleDef.getMessageDefList()
1976:                            .getMessageDef();
1977:                    Iterator lIter = lMessages.iterator();
1978:                    while (lIter.hasNext()) {
1979:                        MessageDefType lMessageDef = (MessageDefType) lIter
1980:                                .next();
1981:                        if (lMessageDef.getMessageRef().equals(pMessageRef)) {
1982:                            cDOMObjectsCache.put(pMessageRef + ";"
1983:                                    + MessageDefType.class.getName(),
1984:                                    lRet = lMessageDef);
1985:                            break;
1986:                        }
1987:                    }
1988:                }
1989:                return lRet;
1990:            }
1991:
1992:            /** Inserts new structure def */
1993:            public static void insertStructure(StructureDefType pStructureDef)
1994:                    throws PSException {
1995:                try {
1996:                    getValidator().validate(pStructureDef);
1997:                } catch (ValidationException e) {
1998:                    throw new PSContentConstraintViolationException(
1999:                            "Structure definition validation exception. StructureRef : "
2000:                                    + pStructureDef.getStructureRef(), e);
2001:                } catch (JAXBException e) {
2002:                    throw new PSDataSourceOperationInvocationException(e);
2003:                }
2004:
2005:                if (getStructure(pStructureDef.getStructureRef()) != null)
2006:                    throw new PSException(
2007:                            "Attempt to insert alredy existing Structure into Servicemodule. StructureRef: "
2008:                                    + pStructureDef.getStructureRef());
2009:                // StructureRef always consists of four parts - enterprise name . system name . servicemodule name . structure name
2010:                StringTokenizer lTokenizer = new StringTokenizer(pStructureDef
2011:                        .getStructureRef(), ".", false);
2012:                if (lTokenizer.countTokens() != 4)
2013:                    throw new PSException("Invalid StructureRef: "
2014:                            + pStructureDef.getStructureRef());
2015:                String lEnterpriseName = lTokenizer.nextToken();
2016:                String lSystemName = lTokenizer.nextToken();
2017:                String lServicemoduleName = lTokenizer.nextToken();
2018:                String lStructureName = lTokenizer.nextToken();
2019:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
2020:                        + "." + lSystemName + "." + lServicemoduleName);
2021:                if (lServicemoduleDef == null)
2022:                    throw new PSException(
2023:                            "Attempt to insert Structure into Servicemodule, which does not exists. StructureRef: "
2024:                                    + pStructureDef.getStructureRef());
2025:                lServicemoduleDef.getStructureDefList().getStructureDef().add(
2026:                        pStructureDef);
2027:                updateServicemodule(lServicemoduleDef);
2028:                cDOMObjectsCache.put(pStructureDef.getStructureRef() + ";"
2029:                        + StructureDefType.class.getName(), pStructureDef);
2030:            }
2031:
2032:            /** Inserts new message def */
2033:            public static void insertMessage(MessageDefType pMessageDef)
2034:                    throws PSException {
2035:                try {
2036:                    getValidator().validate(pMessageDef);
2037:                } catch (ValidationException e) {
2038:                    throw new PSContentConstraintViolationException(
2039:                            "Message definition validation exception. MessageRef : "
2040:                                    + pMessageDef.getMessageRef(), e);
2041:                } catch (JAXBException e) {
2042:                    throw new PSDataSourceOperationInvocationException(e);
2043:                }
2044:                if (getMessage(pMessageDef.getMessageRef()) != null)
2045:                    throw new PSException(
2046:                            "Attempt to insert alredy existing Message into Servicemodule. MessageRef: "
2047:                                    + pMessageDef.getMessageRef());
2048:                // MessageRef always consists of four parts - enterprise name . system name . servicemodule name . message name
2049:                StringTokenizer lTokenizer = new StringTokenizer(pMessageDef
2050:                        .getMessageRef(), ".", false);
2051:                if (lTokenizer.countTokens() != 4)
2052:                    throw new PSException("Invalid MessageRef: "
2053:                            + pMessageDef.getMessageRef());
2054:                String lEnterpriseName = lTokenizer.nextToken();
2055:                String lSystemName = lTokenizer.nextToken();
2056:                String lServicemoduleName = lTokenizer.nextToken();
2057:                String lMessageName = lTokenizer.nextToken();
2058:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
2059:                        + "." + lSystemName + "." + lServicemoduleName);
2060:                if (lServicemoduleDef == null)
2061:                    throw new PSException(
2062:                            "Attempt to insert Message into Servicemodule, which does not exists. MessageRef: "
2063:                                    + pMessageDef.getMessageRef());
2064:                lServicemoduleDef.getMessageDefList().getMessageDef().add(
2065:                        pMessageDef);
2066:                updateServicemodule(lServicemoduleDef);
2067:                cDOMObjectsCache.put(pMessageDef.getMessageRef() + ";"
2068:                        + MessageDefType.class.getName(), pMessageDef);
2069:            }
2070:
2071:            /** Updates structure details on storage */
2072:            public static void updateStructure(StructureDefType pStructureDef)
2073:                    throws PSException {
2074:                try {
2075:                    getValidator().validate(pStructureDef);
2076:                } catch (ValidationException e) {
2077:                    throw new PSContentConstraintViolationException(
2078:                            "Structure definition validation exception. StructureRef : "
2079:                                    + pStructureDef.getStructureRef(), e);
2080:                } catch (JAXBException e) {
2081:                    throw new PSDataSourceOperationInvocationException(e);
2082:                }
2083:                StructureDefType lCurrentCopy = getStructure(pStructureDef
2084:                        .getStructureRef());
2085:                if (lCurrentCopy == null)
2086:                    throw new PSException(
2087:                            "Attempt to update Structure, which does not exists. StructureRef: "
2088:                                    + pStructureDef.getStructureRef());
2089:                // StructureRef always consists of four parts - enterprise name . system name . servicemodule name . service name
2090:                StringTokenizer lTokenizer = new StringTokenizer(pStructureDef
2091:                        .getStructureRef(), ".", false);
2092:                if (lTokenizer.countTokens() != 4)
2093:                    throw new PSException("Invalid StructureRef: "
2094:                            + pStructureDef.getStructureRef());
2095:                String lEnterpriseName = lTokenizer.nextToken();
2096:                String lSystemName = lTokenizer.nextToken();
2097:                String lServicemoduleName = lTokenizer.nextToken();
2098:                String lStructureName = lTokenizer.nextToken();
2099:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
2100:                        + "." + lSystemName + "." + lServicemoduleName);
2101:                if (lServicemoduleDef == null)
2102:                    throw new PSException(
2103:                            "Attempt to update Structure into Servicemodule, which does not exists. StructureRef: "
2104:                                    + pStructureDef.getStructureRef());
2105:                cDOMObjectsCache.remove(pStructureDef.getStructureRef() + ";"
2106:                        + StructureDefType.class.getName());
2107:                if (!lServicemoduleDef.getStructureDefList().getStructureDef()
2108:                        .remove(lCurrentCopy))
2109:                    throw new PSUnexpectedProgramConditionException(
2110:                            "Remove of previous version of the structure definition has failed. StructureRef: "
2111:                                    + pStructureDef.getStructureRef());
2112:                lServicemoduleDef.getStructureDefList().getStructureDef().add(
2113:                        pStructureDef);
2114:                updateServicemodule(lServicemoduleDef);
2115:                cDOMObjectsCache.put(pStructureDef.getStructureRef() + ";"
2116:                        + StructureDefType.class.getName(), pStructureDef);
2117:            }
2118:
2119:            /** Updates message details on storage */
2120:            public static void updateMessage(MessageDefType pMessageDef)
2121:                    throws PSException {
2122:                try {
2123:                    getValidator().validate(pMessageDef);
2124:                } catch (ValidationException e) {
2125:                    throw new PSContentConstraintViolationException(
2126:                            "Message definition validation exception. MessageRef : "
2127:                                    + pMessageDef.getMessageRef(), e);
2128:                } catch (JAXBException e) {
2129:                    throw new PSDataSourceOperationInvocationException(e);
2130:                }
2131:
2132:                MessageDefType lCurrentCopy = getMessage(pMessageDef
2133:                        .getMessageRef());
2134:                if (lCurrentCopy == null)
2135:                    throw new PSException(
2136:                            "Attempt to update Message, which does not exists. MessageRef: "
2137:                                    + pMessageDef.getMessageRef());
2138:                // MessageRef always consists of four parts - enterprise name . system name . servicemodule name . message name
2139:                StringTokenizer lTokenizer = new StringTokenizer(pMessageDef
2140:                        .getMessageRef(), ".", false);
2141:                if (lTokenizer.countTokens() != 4)
2142:                    throw new PSException("Invalid MessageRef: "
2143:                            + pMessageDef.getMessageRef());
2144:                String lEnterpriseName = lTokenizer.nextToken();
2145:                String lSystemName = lTokenizer.nextToken();
2146:                String lServicemoduleName = lTokenizer.nextToken();
2147:                String lMessageName = lTokenizer.nextToken();
2148:                ServicemoduleDefType lServicemoduleDef = getServicemodule(lEnterpriseName
2149:                        + "." + lSystemName + "." + lServicemoduleName);
2150:                if (lServicemoduleDef == null)
2151:                    throw new PSException(
2152:                            "Attempt to update Message into Servicemodule, which does not exists. MessageRef: "
2153:                                    + pMessageDef.getMessageRef());
2154:                cDOMObjectsCache.remove(pMessageDef.getMessageRef() + ";"
2155:                        + MessageDefType.class.getName());
2156:                if (!lServicemoduleDef.getMessageDefList().getMessageDef()
2157:                        .remove(lCurrentCopy))
2158:                    throw new PSUnexpectedProgramConditionException(
2159:                            "Remove of previous version of the message definition has failed. MessageRef: "
2160:                                    + pMessageDef.getMessageRef());
2161:                lServicemoduleDef.getMessageDefList().getMessageDef().add(
2162:                        pMessageDef);
2163:                updateServicemodule(lServicemoduleDef);
2164:                cDOMObjectsCache.put(pMessageDef.getMessageRef() + ";"
2165:                        + MessageDefType.class.getName(), pMessageDef);
2166:            }
2167:
2168:            /** Updates entity details on storage */
2169:            public static void updateEntity(EntityDefType pEntityDef)
2170:                    throws PSException {
2171:                try {
2172:                    getValidator().validate(pEntityDef);
2173:                } catch (ValidationException e) {
2174:                    throw new PSContentConstraintViolationException(
2175:                            "Entity definition validation exception. EntityRef: "
2176:                                    + pEntityDef.getEntityRef(), e);
2177:                } catch (JAXBException e) {
2178:                    throw new PSDataSourceOperationInvocationException(e);
2179:                }
2180:                EntityDefType lCurrentCopy = getEntity(pEntityDef
2181:                        .getEntityRef());
2182:                if (lCurrentCopy == null)
2183:                    throw new PSException(
2184:                            "Attempt to update Entity, which does not exists. EntityRef: "
2185:                                    + pEntityDef.getEntityRef());
2186:                // EntityRef always consists of four parts - enterprise name . system name . domain name . entity name
2187:                StringTokenizer lTokenizer = new StringTokenizer(pEntityDef
2188:                        .getEntityRef(), ".", false);
2189:                if (lTokenizer.countTokens() != 4)
2190:                    throw new PSIllegalArgumentException("Invalid EntityRef: "
2191:                            + pEntityDef.getEntityRef());
2192:                String lEnterpriseName = lTokenizer.nextToken();
2193:                String lSystemName = lTokenizer.nextToken();
2194:                String lDomainName = lTokenizer.nextToken();
2195:                String lEntityName = lTokenizer.nextToken();
2196:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2197:                        + lSystemName + "." + lDomainName);
2198:                if (lDomainDef == null)
2199:                    throw new PSException(
2200:                            "Attempt to update Entity into Domain, which does not exists. EntityRef: "
2201:                                    + pEntityDef.getEntityRef());
2202:                cDOMObjectsCache.remove(pEntityDef.getEntityRef() + ";"
2203:                        + EntityDefType.class.getName());
2204:                if (!lDomainDef.getEntityDefList().getEntityDef().remove(
2205:                        lCurrentCopy))
2206:                    throw new PSUnexpectedProgramConditionException(
2207:                            "Remove of previous version of the entity definition has failed. EntityRef: "
2208:                                    + pEntityDef.getEntityRef());
2209:                lDomainDef.getEntityDefList().getEntityDef().add(pEntityDef);
2210:                updateDomain(lDomainDef);
2211:                cDOMObjectsCache.put(pEntityDef.getEntityRef() + ";"
2212:                        + EntityDefType.class.getName(), pEntityDef);
2213:            }
2214:
2215:            /** Updates association details on storage */
2216:            public static void updateAssociation(
2217:                    AssociationDefType pAssociationDef) throws PSException {
2218:                try {
2219:                    getValidator().validate(pAssociationDef);
2220:                } catch (ValidationException e) {
2221:                    throw new PSContentConstraintViolationException(
2222:                            "Association definition validation exception. AssociationRef: "
2223:                                    + pAssociationDef.getAssociationRef(), e);
2224:                } catch (JAXBException e) {
2225:                    throw new PSDataSourceOperationInvocationException(e);
2226:                }
2227:                AssociationDefType lCurrentCopy = getAssociation(pAssociationDef
2228:                        .getAssociationRef());
2229:                if (lCurrentCopy == null)
2230:                    throw new PSException(
2231:                            "Attempt to update Association, which does not exists. AssociationRef: "
2232:                                    + pAssociationDef.getAssociationRef());
2233:                // AssociationRef always consists of four parts - enterprise name . system name . domain name . association name
2234:                StringTokenizer lTokenizer = new StringTokenizer(
2235:                        pAssociationDef.getAssociationRef(), ".", false);
2236:                if (lTokenizer.countTokens() != 4)
2237:                    throw new PSIllegalArgumentException(
2238:                            "Invalid AssociationRef: "
2239:                                    + pAssociationDef.getAssociationRef());
2240:                String lEnterpriseName = lTokenizer.nextToken();
2241:                String lSystemName = lTokenizer.nextToken();
2242:                String lDomainName = lTokenizer.nextToken();
2243:                String lAssociationName = lTokenizer.nextToken();
2244:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2245:                        + lSystemName + "." + lDomainName);
2246:                if (lDomainDef == null)
2247:                    throw new PSException(
2248:                            "Attempt to update Association into Domain, which does not exists. AssociationRef: "
2249:                                    + pAssociationDef.getAssociationRef());
2250:                cDOMObjectsCache.remove(pAssociationDef.getAssociationRef()
2251:                        + ";" + AssociationDefType.class.getName());
2252:                if (!lDomainDef.getAssociationDefList().getAssociationDef()
2253:                        .remove(lCurrentCopy))
2254:                    throw new PSUnexpectedProgramConditionException(
2255:                            "Remove of previous version of the association definition has failed. AssociationRef: "
2256:                                    + pAssociationDef.getAssociationRef());
2257:                lDomainDef.getAssociationDefList().getAssociationDef().add(
2258:                        pAssociationDef);
2259:                updateDomain(lDomainDef);
2260:                cDOMObjectsCache.put(pAssociationDef.getAssociationRef() + ";"
2261:                        + AssociationDefType.class.getName(), pAssociationDef);
2262:            }
2263:
2264:            /** Updates entity details on storage */
2265:            public static void insertEntity(EntityDefType pEntityDef)
2266:                    throws PSException {
2267:                try {
2268:                    getValidator().validate(pEntityDef);
2269:                } catch (ValidationException e) {
2270:                    throw new PSContentConstraintViolationException(
2271:                            "Entity definition validation exception. EntityRef: "
2272:                                    + pEntityDef.getEntityRef(), e);
2273:                } catch (JAXBException e) {
2274:                    throw new PSDataSourceOperationInvocationException(e);
2275:                }
2276:                if (getEntity(pEntityDef.getEntityRef()) != null)
2277:                    throw new PSException(
2278:                            "Attempt to insert alredy existing Entity into Domain. EntityRef: "
2279:                                    + pEntityDef.getEntityRef());
2280:                // EntityRef always consists of four parts - enterprise name . system name . domain name . structure name
2281:                StringTokenizer lTokenizer = new StringTokenizer(pEntityDef
2282:                        .getEntityRef(), ".", false);
2283:                if (lTokenizer.countTokens() != 4)
2284:                    throw new PSException("Invalid EntityRef: "
2285:                            + pEntityDef.getEntityRef());
2286:                String lEnterpriseName = lTokenizer.nextToken();
2287:                String lSystemName = lTokenizer.nextToken();
2288:                String lDomainName = lTokenizer.nextToken();
2289:                String lEntityName = lTokenizer.nextToken();
2290:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2291:                        + lSystemName + "." + lDomainName);
2292:                if (lDomainDef == null)
2293:                    throw new PSException(
2294:                            "Attempt to insert Entity into non-existant Domain. EntityRef: "
2295:                                    + pEntityDef.getEntityRef());
2296:                lDomainDef.getEntityDefList().getEntityDef().add(pEntityDef);
2297:                updateDomain(lDomainDef);
2298:                cDOMObjectsCache.put(pEntityDef.getEntityRef() + ";"
2299:                        + EntityDefType.class.getName(), pEntityDef);
2300:            }
2301:
2302:            /** Updates association details on storage */
2303:            public static void insertAssociation(
2304:                    AssociationDefType pAssociationDef) throws PSException {
2305:                try {
2306:                    getValidator().validate(pAssociationDef);
2307:                } catch (ValidationException e) {
2308:                    throw new PSContentConstraintViolationException(
2309:                            "Association definition validation exception. AssociationRef: "
2310:                                    + pAssociationDef.getAssociationRef(), e);
2311:                } catch (JAXBException e) {
2312:                    throw new PSDataSourceOperationInvocationException(e);
2313:                }
2314:                if (getAssociation(pAssociationDef.getAssociationRef()) != null)
2315:                    throw new PSException(
2316:                            "Attempt to insert alredy existing Association into Domain. AssociationRef: "
2317:                                    + pAssociationDef.getAssociationRef());
2318:                // AssociationRef always consists of four parts - enterprise name . system name . domain name . structure name
2319:                StringTokenizer lTokenizer = new StringTokenizer(
2320:                        pAssociationDef.getAssociationRef(), ".", false);
2321:                if (lTokenizer.countTokens() != 4)
2322:                    throw new PSException("Invalid AssociationRef: "
2323:                            + pAssociationDef.getAssociationRef());
2324:                String lEnterpriseName = lTokenizer.nextToken();
2325:                String lSystemName = lTokenizer.nextToken();
2326:                String lDomainName = lTokenizer.nextToken();
2327:                String lAssociationName = lTokenizer.nextToken();
2328:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2329:                        + lSystemName + "." + lDomainName);
2330:                if (lDomainDef == null)
2331:                    throw new PSException(
2332:                            "Attempt to insert Association into non-existant Domain. AssociationRef: "
2333:                                    + pAssociationDef.getAssociationRef());
2334:                lDomainDef.getAssociationDefList().getAssociationDef().add(
2335:                        pAssociationDef);
2336:                updateDomain(lDomainDef);
2337:                cDOMObjectsCache.put(pAssociationDef.getAssociationRef() + ";"
2338:                        + AssociationDefType.class.getName(), pAssociationDef);
2339:            }
2340:
2341:            /** Deletes entity details from storage */
2342:            public static void deleteEntity(String pEntityRef)
2343:                    throws PSException {
2344:                EntityDefType lEntityDefToDelete = getEntity(pEntityRef);
2345:                if (lEntityDefToDelete == null)
2346:                    throw new PSUnexpectedProgramConditionException(
2347:                            "Attempt to delete entity, which does not exists. EntityRef: "
2348:                                    + pEntityRef);
2349:                // EntityRef always consists of four parts - enterprise name . system name . domain name . entity name
2350:                StringTokenizer lTokenizer = new StringTokenizer(pEntityRef,
2351:                        ".", false);
2352:                if (lTokenizer.countTokens() != 4)
2353:                    throw new PSIllegalArgumentException("Invalid EntityRef: "
2354:                            + pEntityRef);
2355:                String lEnterpriseName = lTokenizer.nextToken();
2356:                String lSystemName = lTokenizer.nextToken();
2357:                String lDomainName = lTokenizer.nextToken();
2358:                String lEntityName = lTokenizer.nextToken();
2359:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2360:                        + lSystemName + "." + lDomainName);
2361:                if (lDomainDef == null)
2362:                    throw new PSException(
2363:                            "Attempt to delete entity from Domain, which does not exists. EntityRef: "
2364:                                    + pEntityRef);
2365:                lDomainDef.getEntityDefList().getEntityDef().remove(
2366:                        lEntityDefToDelete);
2367:                cDOMObjectsCache.remove(pEntityRef + ";"
2368:                        + EntityDefType.class.getName());
2369:                updateDomain(lDomainDef);
2370:            }
2371:
2372:            /** Deletes association details from storage */
2373:            public static void deleteAssociation(String pAssociationRef)
2374:                    throws PSException {
2375:                AssociationDefType lAssociationDefToDelete = getAssociation(pAssociationRef);
2376:                if (lAssociationDefToDelete == null)
2377:                    throw new PSUnexpectedProgramConditionException(
2378:                            "Attempt to delete association, which does not exists. AssociationRef: "
2379:                                    + pAssociationRef);
2380:                // AssociationRef always consists of four parts - enterprise name . system name . domain name . association name
2381:                StringTokenizer lTokenizer = new StringTokenizer(
2382:                        pAssociationRef, ".", false);
2383:                if (lTokenizer.countTokens() != 4)
2384:                    throw new PSIllegalArgumentException("Invalid EntityRef: "
2385:                            + pAssociationRef);
2386:                String lEnterpriseName = lTokenizer.nextToken();
2387:                String lSystemName = lTokenizer.nextToken();
2388:                String lDomainName = lTokenizer.nextToken();
2389:                String lAssociationName = lTokenizer.nextToken();
2390:                DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2391:                        + lSystemName + "." + lDomainName);
2392:                if (lDomainDef == null)
2393:                    throw new PSException(
2394:                            "Attempt to delete association from Domain, which does not exists. AssociationRef: "
2395:                                    + pAssociationRef);
2396:                lDomainDef.getAssociationDefList().getAssociationDef().remove(
2397:                        lAssociationDefToDelete);
2398:                cDOMObjectsCache.remove(pAssociationRef + ";"
2399:                        + AssociationDefType.class.getName());
2400:                updateDomain(lDomainDef);
2401:            }
2402:
2403:            /** Updates servicemodule details on storage */
2404:            public static void updateServicemodule(
2405:                    ServicemoduleDefType pServicemoduleDef) throws PSException {
2406:                try {
2407:                    try {
2408:                        getValidator().validate(pServicemoduleDef);
2409:                    } catch (ValidationException e) {
2410:                        throw new PSContentConstraintViolationException(
2411:                                "Servicemodule definition validation exception. ServicemoduleRef: "
2412:                                        + pServicemoduleDef
2413:                                                .getServicemoduleRef(), e);
2414:                    }
2415:                    // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
2416:                    StringTokenizer lTokenizer = new StringTokenizer(
2417:                            pServicemoduleDef.getServicemoduleRef(), ".", false);
2418:                    if (lTokenizer.countTokens() != 3)
2419:                        throw new PSException("Invalid ServicemoduleRef: "
2420:                                + pServicemoduleDef.getServicemoduleRef());
2421:                    String lEnterpriseName = lTokenizer.nextToken();
2422:                    String lSystemName = lTokenizer.nextToken();
2423:                    String lServicemoduleName = lTokenizer.nextToken();
2424:                    String lServicemoduleFileName = cEnterpriseRootDir
2425:                            + File.separator + lEnterpriseName + File.separator
2426:                            + cEnterpriseSystemsSubDir + File.separator
2427:                            + lSystemName + File.separator
2428:                            + cEnterpriseServicemodulesSubDir + File.separator
2429:                            + lServicemoduleName
2430:                            + "ServicemoduleDescriptor.xml";
2431:                    File lServicemoduleFile = new File(lServicemoduleFileName);
2432:                    if (lServicemoduleFile.exists() == false)
2433:                        throw new PSException(
2434:                                "File "
2435:                                        + lServicemoduleFileName
2436:                                        + " does not exist. Unable to update servicemodule. ServicemoduleRef: "
2437:                                        + pServicemoduleDef
2438:                                                .getServicemoduleRef());
2439:                    if (lServicemoduleFile.canWrite() == false)
2440:                        throw new PSException(
2441:                                "File "
2442:                                        + lServicemoduleFileName
2443:                                        + " is read-only. Unable to update servicemodule. ServicemoduleRef: "
2444:                                        + pServicemoduleDef
2445:                                                .getServicemoduleRef());
2446:                    // Clean up the cache prior to saving the new file
2447:                    cDOMObjectsCache.remove(pServicemoduleDef
2448:                            .getServicemoduleRef()
2449:                            + ";" + ServicemoduleDefType.class.getName());
2450:                    FileOutputStream lFileOutputStream = null;
2451:                    try {
2452:                        lFileOutputStream = new FileOutputStream(
2453:                                lServicemoduleFile);
2454:                        getMarshaller().marshal(pServicemoduleDef,
2455:                                lFileOutputStream);
2456:                        lFileOutputStream.flush();
2457:                        lFileOutputStream.close();
2458:                        lFileOutputStream = null;
2459:                        cDOMObjectsCache.put(pServicemoduleDef
2460:                                .getServicemoduleRef()
2461:                                + ";" + ServicemoduleDefType.class.getName(),
2462:                                pServicemoduleDef);
2463:                    } catch (IOException e) {
2464:                        throw new PSException(
2465:                                "Caught exception while writing file : "
2466:                                        + lServicemoduleFileName, e);
2467:                    } finally {
2468:                        try {
2469:                            if (lFileOutputStream != null)
2470:                                lFileOutputStream.close();
2471:                        } catch (IOException e) {
2472:                        }
2473:                    }
2474:                } catch (JAXBException e) {
2475:                    throw new PSDataSourceOperationInvocationException(e);
2476:                }
2477:            }
2478:
2479:            /** Updates enterprise details on storage */
2480:            public static void updateEnterprise(EnterpriseDefType pEnterpriseDef)
2481:                    throws PSException {
2482:                try {
2483:                    try {
2484:                        getValidator().validate(pEnterpriseDef);
2485:                    } catch (ValidationException e) {
2486:                        throw new PSContentConstraintViolationException(
2487:                                "Enterprise definition validation exception. EnterpriseRef: "
2488:                                        + pEnterpriseDef.getEnterpriseRef(), e);
2489:                    }
2490:                    // ServciemoduleRef always consists of three parts - enterprise name . system name . serviemodule name
2491:                    StringTokenizer lTokenizer = new StringTokenizer(
2492:                            pEnterpriseDef.getEnterpriseRef(), ".", false);
2493:                    if (lTokenizer.countTokens() != 1)
2494:                        throw new PSException("Invalid EnterpriseRef: "
2495:                                + pEnterpriseDef.getEnterpriseRef());
2496:                    String lEnterpriseName = lTokenizer.nextToken();
2497:                    String lEnterpriseFileName = cEnterpriseRootDir
2498:                            + File.separator + lEnterpriseName + File.separator
2499:                            + "Descriptor.xml";
2500:                    File lEnterpriseFile = new File(lEnterpriseFileName);
2501:                    if (lEnterpriseFile.exists() == false)
2502:                        throw new PSException(
2503:                                "File "
2504:                                        + lEnterpriseFileName
2505:                                        + " does not exist. Unable to update enterprise. EnterpriseRef: "
2506:                                        + pEnterpriseDef.getEnterpriseRef());
2507:                    if (lEnterpriseFile.canWrite() == false)
2508:                        throw new PSException(
2509:                                "File "
2510:                                        + lEnterpriseFileName
2511:                                        + " is read-only. Unable to update enterprise. EnterpriseRef: "
2512:                                        + pEnterpriseDef.getEnterpriseRef());
2513:                    // Clean up the cache prior to saving the new file
2514:                    cDOMObjectsCache.remove(pEnterpriseDef.getEnterpriseRef()
2515:                            + ";" + EnterpriseDefType.class.getName());
2516:                    FileOutputStream lFileOutputStream = null;
2517:                    try {
2518:                        lFileOutputStream = new FileOutputStream(
2519:                                lEnterpriseFile);
2520:                        getMarshaller().marshal(pEnterpriseDef,
2521:                                lFileOutputStream);
2522:                        lFileOutputStream.flush();
2523:                        lFileOutputStream.close();
2524:                        lFileOutputStream = null;
2525:                        cDOMObjectsCache.put(pEnterpriseDef.getEnterpriseRef()
2526:                                + ";" + EnterpriseDefType.class.getName(),
2527:                                pEnterpriseDef);
2528:                    } catch (IOException e) {
2529:                        throw new PSException(
2530:                                "Caught exception while writing file : "
2531:                                        + lEnterpriseFileName, e);
2532:                    } finally {
2533:                        try {
2534:                            if (lFileOutputStream != null)
2535:                                lFileOutputStream.close();
2536:                        } catch (IOException e) {
2537:                        }
2538:                    }
2539:                } catch (JAXBException e) {
2540:                    throw new PSDataSourceOperationInvocationException(e);
2541:                }
2542:            }
2543:
2544:            /** Updates domain details on storage */
2545:            public static void updateDomain(DomainDefType pDomainDef)
2546:                    throws PSException {
2547:                try {
2548:                    try {
2549:                        getValidator().validate(pDomainDef);
2550:                    } catch (ValidationException e) {
2551:                        throw new PSContentConstraintViolationException(
2552:                                "Domain definition validation exception. DomainRef: "
2553:                                        + pDomainDef.getDomainRef(), e);
2554:                    }
2555:                    // DomainRef always consists of three parts - enterprise name . system name . domain name
2556:                    StringTokenizer lTokenizer = new StringTokenizer(pDomainDef
2557:                            .getDomainRef(), ".", false);
2558:                    if (lTokenizer.countTokens() != 3)
2559:                        throw new PSException("Invalid DomainRef: "
2560:                                + pDomainDef.getDomainRef());
2561:                    String lEnterpriseName = lTokenizer.nextToken();
2562:                    String lSystemName = lTokenizer.nextToken();
2563:                    String lDomainName = lTokenizer.nextToken();
2564:                    String lDomainFileName = cEnterpriseRootDir
2565:                            + File.separator + lEnterpriseName + File.separator
2566:                            + cEnterpriseSystemsSubDir + File.separator
2567:                            + lSystemName + File.separator
2568:                            + cEnterpriseDomainsSubDir + File.separator
2569:                            + lDomainName + "DomainDescriptor.xml";
2570:                    File lDomainFile = new File(lDomainFileName);
2571:                    if (lDomainFile.exists() == false)
2572:                        throw new PSException(
2573:                                "File "
2574:                                        + lDomainFileName
2575:                                        + " does not exist. Unable to update domain. DomainRef: "
2576:                                        + pDomainDef.getDomainRef());
2577:                    if (lDomainFile.canWrite() == false)
2578:                        throw new PSException(
2579:                                "File "
2580:                                        + lDomainFileName
2581:                                        + " is read-only. Unable to update domain. DomainRef: "
2582:                                        + pDomainDef.getDomainRef());
2583:                    // Clean up the cache prior to saving the new file
2584:                    cDOMObjectsCache.remove(pDomainDef.getDomainRef() + ";"
2585:                            + DomainDefType.class.getName());
2586:                    FileOutputStream lFileOutputStream = null;
2587:                    try {
2588:                        lFileOutputStream = new FileOutputStream(lDomainFile);
2589:                        getMarshaller().marshal(pDomainDef, lFileOutputStream);
2590:                        lFileOutputStream.flush();
2591:                        lFileOutputStream.close();
2592:                        lFileOutputStream = null;
2593:                        cDOMObjectsCache.put(pDomainDef.getDomainRef() + ";"
2594:                                + DomainDefType.class.getName(), pDomainDef);
2595:                    } catch (IOException e) {
2596:                        throw new PSException(
2597:                                "Caught exception while writing file : "
2598:                                        + lDomainFileName, e);
2599:                    } finally {
2600:                        try {
2601:                            if (lFileOutputStream != null)
2602:                                lFileOutputStream.close();
2603:                        } catch (IOException e) {
2604:                        }
2605:                    }
2606:                } catch (JAXBException e) {
2607:                    throw new PSDataSourceOperationInvocationException(e);
2608:                }
2609:            }
2610:
2611:            /** Deletes system details on storage */
2612:            public static void deleteSystem(String pSystemRef)
2613:                    throws PSException {
2614:                try {
2615:                    String lSystemDirectoryName = getSystemDirectory(pSystemRef);
2616:                    File lSystemDirectory = new File(lSystemDirectoryName);
2617:                    if (!lSystemDirectory.exists())
2618:                        throw new PSException(
2619:                                "Directory "
2620:                                        + lSystemDirectoryName
2621:                                        + " does not exist. Unable to delete system. SystemRef: "
2622:                                        + pSystemRef);
2623:                    if (!DirectoryUtils.canDelete(lSystemDirectory))
2624:                        throw new PSException(
2625:                                "Directory "
2626:                                        + lSystemDirectoryName
2627:                                        + " is not writeable. Unable to delete system. SystemRef: "
2628:                                        + pSystemRef);
2629:                    cDOMObjectsCache.remove(pSystemRef + ";"
2630:                            + SystemDefType.class.getName());
2631:                    DirectoryUtils.deleteDirectory(lSystemDirectory);
2632:                } catch (IOException e) {
2633:                    throw new PSException(
2634:                            "Caught exception while deleting System. SystemRef: "
2635:                                    + pSystemRef, e);
2636:                }
2637:            }
2638:
2639:            /** Updates system details on storage */
2640:            public static void updateSystem(SystemDefType pSystemDef)
2641:                    throws PSException {
2642:                try {
2643:                    try {
2644:                        getValidator().validate(pSystemDef);
2645:                    } catch (ValidationException e) {
2646:                        throw new PSContentConstraintViolationException(
2647:                                "System definition validation exception. SystemRef: "
2648:                                        + pSystemDef.getSystemRef(), e);
2649:                    }
2650:                    String lSystemDirectoryName = getSystemDirectory(pSystemDef
2651:                            .getSystemRef());
2652:                    String lSystemFileName = lSystemDirectoryName
2653:                            + File.separator + "Descriptor.xml";
2654:                    File lSystemFile = new File(lSystemFileName);
2655:                    if (lSystemFile.exists() == false)
2656:                        throw new PSException(
2657:                                "File "
2658:                                        + lSystemFileName
2659:                                        + " does not exist. Unable to update system. SystemRef: "
2660:                                        + pSystemDef.getSystemRef());
2661:                    if (lSystemFile.canWrite() == false)
2662:                        throw new PSException(
2663:                                "File "
2664:                                        + lSystemFileName
2665:                                        + " is read-only. Unable to update system. SystemRef: "
2666:                                        + pSystemDef.getSystemRef());
2667:                    // Clean up the cache prior to saving the new file
2668:                    cDOMObjectsCache.remove(pSystemDef.getSystemRef() + ";"
2669:                            + SystemDefType.class.getName());
2670:                    FileOutputStream lFileOutputStream = null;
2671:                    try {
2672:                        lFileOutputStream = new FileOutputStream(lSystemFile);
2673:                        getMarshaller().marshal(pSystemDef, lFileOutputStream);
2674:                        lFileOutputStream.flush();
2675:                        lFileOutputStream.close();
2676:                        lFileOutputStream = null;
2677:                        cDOMObjectsCache.put(pSystemDef.getSystemRef() + ";"
2678:                                + SystemDefType.class.getName(), pSystemDef);
2679:                    } catch (IOException e) {
2680:                        throw new PSException(
2681:                                "Caught exception while writing file : "
2682:                                        + lSystemFileName, e);
2683:                    } finally {
2684:                        try {
2685:                            if (lFileOutputStream != null)
2686:                                lFileOutputStream.close();
2687:                        } catch (IOException e) {
2688:                        }
2689:                    }
2690:                } catch (JAXBException e) {
2691:                    throw new PSDataSourceOperationInvocationException(e);
2692:                }
2693:            }
2694:
2695:            /** Returns Association def or null if none found */
2696:            public static AssociationDefType getAssociation(
2697:                    String pAssociationRef) throws PSException {
2698:                // First see if we have this object already
2699:                AssociationDefType lRet = (AssociationDefType) cDOMObjectsCache
2700:                        .get(pAssociationRef + ";"
2701:                                + AssociationDefType.class.getName());
2702:                if (lRet == null) {
2703:                    // AssociationRef always consists of four parts - enterprise name . system name . domain name . association name
2704:                    StringTokenizer lTokenizer = new StringTokenizer(
2705:                            pAssociationRef, ".", false);
2706:                    if (lTokenizer.countTokens() != 4)
2707:                        throw new PSException("Invalid AssociationRef: "
2708:                                + pAssociationRef);
2709:                    String lEnterpriseName = lTokenizer.nextToken();
2710:                    String lSystemName = lTokenizer.nextToken();
2711:                    String lDomainName = lTokenizer.nextToken();
2712:                    String lAssociationName = lTokenizer.nextToken();
2713:                    DomainDefType lDomainDef = getDomain(lEnterpriseName + "."
2714:                            + lSystemName + "." + lDomainName);
2715:                    List lAssociations = lDomainDef.getAssociationDefList()
2716:                            .getAssociationDef();
2717:                    Iterator lIter = lAssociations.iterator();
2718:                    while (lIter.hasNext()) {
2719:                        AssociationDefType lAssociationDef = (AssociationDefType) lIter
2720:                                .next();
2721:                        if (lAssociationDef.getAssociationRef().equals(
2722:                                pAssociationRef)) {
2723:                            cDOMObjectsCache.put(pAssociationRef + ";"
2724:                                    + AssociationDefType.class.getName(),
2725:                                    lRet = lAssociationDef);
2726:                            break;
2727:                        }
2728:                    }
2729:                }
2730:                return lRet;
2731:            }
2732:
2733:            //    /** Returns Association Role Def or null if none found */
2734:            //    public static AssociationRoleDefType getAssociationRole(String pAssociationRoleRef) throws PSException
2735:            //    {
2736:            //		// First see if we have this object already
2737:            //		AssociationRoleDefType lRet = (AssociationRoleDefType)cDOMObjectsCache.get(pAssociationRoleRef + ";" + AssociationRoleDefType.class.getName());
2738:            //		if (lRet == null)
2739:            //		{
2740:            //			// AssociationRoleRef always consists of five parts - enterprise name . system name . domain name . association name . role name
2741:            //	        StringTokenizer lTokenizer = new StringTokenizer(pAssociationRoleRef,".",false);
2742:            //	        if (lTokenizer.countTokens() != 5)
2743:            //				throw new PSException("Invalid AssociationRoleRef: " + pAssociationRoleRef);
2744:            //	        String lEnterpriseName = lTokenizer.nextToken();
2745:            //	        String lSystemName = lTokenizer.nextToken();
2746:            //	        String lDomainName = lTokenizer.nextToken();
2747:            //	        String lAssociationName = lTokenizer.nextToken();
2748:            //			String lAssociationRoleName = lTokenizer.nextToken();
2749:            //			AssociationDefType lAssociationDef = getAssociation(lEnterpriseName + "." + lSystemName + "." + lDomainName + "." + lAssociationName);
2750:            //			if (lAssociationDef != null)
2751:            //			{
2752:            //				// Try role A first
2753:            //				AssociationRoleDefType lRoleA = (AssociationRoleDefType)lAssociationDef.getAssociationRoleDef().get(0);
2754:            //				AssociationRoleDefType lRoleB = (AssociationRoleDefType)lAssociationDef.getAssociationRoleDef().get(1);
2755:            //				if (lRoleA.getName().equals(lAssociationRoleName))
2756:            //					lRet = lRoleA;
2757:            //				else
2758:            //				if (lRoleB.getName().equals(lAssociationRoleName))
2759:            //					lRet = lRoleB;
2760:            //			}
2761:            //			if (lRet != null)	
2762:            //            	cDOMObjectsCache.put(pAssociationRoleRef + ";" + AssociationRoleDefType.class.getName(),lRet);
2763:            //		}
2764:            //		return lRet;
2765:            //    }
2766:
2767:            /** Returns Application def or null if none found */
2768:            public static ApplicationDefType getApplication(
2769:                    String pApplicationRef) throws PSException {
2770:                // First see if we have this object already
2771:                ApplicationDefType lRet = (ApplicationDefType) cDOMObjectsCache
2772:                        .get(pApplicationRef + ";"
2773:                                + ApplicationDefType.class.getName());
2774:                if (lRet == null) {
2775:                    // ApplicationRef always consists of three parts - enterprise name . system name . application name
2776:                    StringTokenizer lTokenizer = new StringTokenizer(
2777:                            pApplicationRef, ".", false);
2778:                    if (lTokenizer.countTokens() != 3)
2779:                        throw new PSException("Invalid ApplicationRef: "
2780:                                + pApplicationRef);
2781:                    String lEnterpriseName = lTokenizer.nextToken();
2782:                    String lSystemName = lTokenizer.nextToken();
2783:                    String lApplicationName = lTokenizer.nextToken();
2784:                    String lApplicationFileName = cEnterpriseRootDir
2785:                            + File.separator + lEnterpriseName + File.separator
2786:                            + cEnterpriseSystemsSubDir + File.separator
2787:                            + lSystemName + File.separator
2788:                            + cEnterpriseApplicationsSubDir + File.separator
2789:                            + lApplicationName + File.separator
2790:                            + "Descriptor.xml";
2791:
2792:                    InputStream lInputStream = null;
2793:                    try {
2794:                        lInputStream = openFileStream(lApplicationFileName);
2795:                        if (lInputStream != null) {
2796:                            if ((lRet = (ApplicationDefType) getUnmarshaller()
2797:                                    .unmarshal(lInputStream)) != null) {
2798:                                if (!lRet.getApplicationRef().equals(
2799:                                        pApplicationRef))
2800:                                    throw new PSReadDataIntegrityViolationException(
2801:                                            "Mismatch between ApplicationRef stored in file and the one implied by its location. ApplicationRef : "
2802:                                                    + lRet.getApplicationRef()
2803:                                                    + ", Location : "
2804:                                                    + lApplicationFileName);
2805:                                cDOMObjectsCache.put(pApplicationRef + ";"
2806:                                        + ApplicationDefType.class.getName(),
2807:                                        lRet);
2808:                            }
2809:                        }
2810:                    } catch (JAXBException e) {
2811:                        throw new PSDataSourceOperationInvocationException(e);
2812:                    } finally {
2813:                        try {
2814:                            if (lInputStream != null)
2815:                                lInputStream.close();
2816:                        } catch (IOException e) {
2817:                        }
2818:                    }
2819:                }
2820:                return lRet;
2821:            }
2822:
2823:            /** All parts found in the application */
2824:            public static String[] getApplicationPartsURLs(
2825:                    String pApplicationRef) throws PSException {
2826:                try {
2827:                    // ApplicationRef always consists of three parts - enterprise name . system name . application name
2828:                    StringTokenizer lTokenizer = new StringTokenizer(
2829:                            pApplicationRef, ".", false);
2830:                    if (lTokenizer.countTokens() != 3)
2831:                        throw new PSException("Invalid ApplicationRef: "
2832:                                + pApplicationRef);
2833:                    String lEnterpriseName = lTokenizer.nextToken();
2834:                    String lSystemName = lTokenizer.nextToken();
2835:                    String lApplicationName = lTokenizer.nextToken();
2836:                    String lApplicationWWWRoot = cEnterpriseRootDir
2837:                            + File.separator + lEnterpriseName + File.separator
2838:                            + cEnterpriseSystemsSubDir + File.separator
2839:                            + lSystemName + File.separator
2840:                            + cEnterpriseApplicationsSubDir + File.separator
2841:                            + lApplicationName + File.separator + "wwwroot";
2842:                    int lApplicationWWWRootNameLength = lApplicationWWWRoot
2843:                            .length();
2844:
2845:                    String[] lAllFileNames = DirectoryUtils
2846:                            .listAllFilesInDirectory(lApplicationWWWRoot);
2847:                    // Chop off the root directory part
2848:                    for (int i = 0; i < lAllFileNames.length; i++)
2849:                        lAllFileNames[i] = lAllFileNames[i]
2850:                                .substring(lApplicationWWWRootNameLength);
2851:                    return lAllFileNames;
2852:                } catch (IOException e) {
2853:                    throw new PSException(
2854:                            "Caught exception while getting application urls.",
2855:                            e);
2856:                }
2857:
2858:            }
2859:
2860:            private static InputStream openFileStream(String pFilePath) {
2861:                File lFile = new File(pFilePath);
2862:                try {
2863:                    if (lFile.exists() && lFile.isFile() && lFile.canRead())
2864:                        return new FileInputStream(lFile);
2865:                    return null;
2866:                } catch (FileNotFoundException e) {
2867:                    return null;
2868:                }
2869:            }
2870:
2871:            // Helper. Returns path for the metamodel path or null if basic one will do
2872:            private static final String sMetaBossHome = System
2873:                    .getProperty("MetaBoss.Home");
2874:            private static String[] sPublicMetaModelPath = null;
2875:
2876:            private static String[] getPublicMetaModelPath() throws PSException {
2877:                if (sPublicMetaModelPath == null) {
2878:                    if (sMetaBossHome == null || sMetaBossHome.length() == 0)
2879:                        throw new PSUndefinedSystemPropertyException(
2880:                                "MetaBoss.Home");
2881:                    sPublicMetaModelPath = new String[] { sMetaBossHome
2882:                            + File.separator + "metalib" };
2883:                }
2884:                return sPublicMetaModelPath;
2885:            }
2886:        }
ww_w_.__j__a_va_2___s__.___c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.