Source Code Cross Referenced for PackageAdmin.java in  » Workflow-Engines » shark » org » enhydra » shark » 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 » Workflow Engines » shark » org.enhydra.shark 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.enhydra.shark;
0002:
0003:        import java.io.ByteArrayOutputStream;
0004:        import java.util.ArrayList;
0005:        import java.util.Collection;
0006:        import java.util.Collections;
0007:        import java.util.HashMap;
0008:        import java.util.HashSet;
0009:        import java.util.Iterator;
0010:        import java.util.List;
0011:        import java.util.Map;
0012:        import java.util.Set;
0013:
0014:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
0015:        import org.enhydra.shark.api.client.wfservice.ExternalPackageInvalid;
0016:        import org.enhydra.shark.api.client.wfservice.NotConnected;
0017:        import org.enhydra.shark.api.client.wfservice.PackageAdministration;
0018:        import org.enhydra.shark.api.client.wfservice.PackageHasActiveProcesses;
0019:        import org.enhydra.shark.api.client.wfservice.PackageInUse;
0020:        import org.enhydra.shark.api.client.wfservice.PackageInvalid;
0021:        import org.enhydra.shark.api.client.wfservice.WMEntity;
0022:        import org.enhydra.shark.api.client.wfservice.WMEntityIterator;
0023:        import org.enhydra.shark.api.common.SharkConstants;
0024:        import org.enhydra.shark.api.internal.repositorypersistence.RepositoryPersistenceManager;
0025:        import org.enhydra.shark.api.internal.security.SecurityManager;
0026:        import org.enhydra.shark.api.internal.working.CallbackUtilities;
0027:        import org.enhydra.shark.api.internal.working.WfProcessMgrInternal;
0028:        import org.enhydra.shark.util.ResourceManager;
0029:        import org.enhydra.shark.utilities.MiscUtilities;
0030:        import org.enhydra.shark.xpdl.Version;
0031:        import org.enhydra.shark.xpdl.XMLComplexElement;
0032:        import org.enhydra.shark.xpdl.XMLElement;
0033:        import org.enhydra.shark.xpdl.XMLInterface;
0034:        import org.enhydra.shark.xpdl.XMLInterfaceForJDK13;
0035:        import org.enhydra.shark.xpdl.XMLUtil;
0036:        import org.enhydra.shark.xpdl.XMLValidationError;
0037:        import org.enhydra.shark.xpdl.elements.*;
0038:        import org.enhydra.shark.xpdl.elements.Package;
0039:
0040:        /**
0041:         * @author Nenad Stefanovic, Sasa Bojanic
0042:         */
0043:        public class PackageAdmin implements  PackageAdministration {
0044:
0045:            private static PackageAdministration anInstance;
0046:
0047:            private PackageAdmin() {
0048:            }
0049:
0050:            public static PackageAdministration getInstance() {
0051:                if (null == anInstance) {
0052:                    synchronized (PackageAdmin.class) {
0053:                        if (null == anInstance) {
0054:                            anInstance = new PackageAdmin();
0055:                        }
0056:                    }
0057:                }
0058:                return anInstance;
0059:            }
0060:
0061:            private XMLInterface getXMLInterface() {
0062:                return SharkEngineManager.getInstance().getXMLInterface();
0063:            }
0064:
0065:            private RepositoryPersistenceManager getRepositoryPersistenceManager() {
0066:                return SharkEngineManager.getInstance()
0067:                        .getRepositoryPersistenceManager();
0068:            }
0069:
0070:            public String[] getOpenedPackageIds(WMSessionHandle shandle)
0071:                    throws Exception {
0072:                long tStamp = SharkEngineManager.getInstance()
0073:                        .getCallbackUtilities().methodStart(shandle,
0074:                                "PackageAdmin.getOpenedPackageIds");
0075:
0076:                try {
0077:                    if (!SharkUtilities.checkSession(shandle)) {
0078:                        throw new NotConnected(
0079:                                "The session handle is not valid!");
0080:                    }
0081:                    checkSecurity(shandle, "getOpenedPackageIds", null);
0082:
0083:                    String[] ret = null;
0084:
0085:                    List pkgIds = getRepositoryPersistenceManager()
0086:                            .getExistingXPDLIds(shandle);
0087:                    Collections.sort(pkgIds);
0088:                    ret = new String[pkgIds.size()];
0089:                    pkgIds.toArray(ret);
0090:
0091:                    return ret;
0092:                } finally {
0093:                    SharkEngineManager.getInstance().getCallbackUtilities()
0094:                            .methodEnd(shandle, tStamp,
0095:                                    "PackageAdmin.getOpenedPackageIds", "");
0096:                }
0097:            }
0098:
0099:            public String[] getPackageVersions(WMSessionHandle shandle,
0100:                    String pkgId) throws Exception {
0101:                long tStamp = SharkEngineManager.getInstance()
0102:                        .getCallbackUtilities().methodStart(shandle,
0103:                                "PackageAdmin.getPackageVersions");
0104:
0105:                try {
0106:                    if (!SharkUtilities.checkSession(shandle)) {
0107:                        throw new NotConnected(
0108:                                "The session handle is not valid!");
0109:                    }
0110:                    checkSecurity(shandle, "getPackageVersions", null);
0111:
0112:                    String[] ret = null;
0113:
0114:                    List pkgVers = getRepositoryPersistenceManager()
0115:                            .getXPDLVersions(shandle, pkgId);
0116:                    Collections.sort(pkgVers);
0117:                    ret = new String[pkgVers.size()];
0118:                    pkgVers.toArray(ret);
0119:
0120:                    return ret;
0121:                } finally {
0122:                    SharkEngineManager.getInstance().getCallbackUtilities()
0123:                            .methodEnd(shandle, tStamp,
0124:                                    "PackageAdmin.getPackageVersions",
0125:                                    "pkgId=" + pkgId);
0126:                }
0127:            }
0128:
0129:            public boolean isPackageOpened(WMSessionHandle shandle, String pkgId)
0130:                    throws Exception {
0131:                long tStamp = SharkEngineManager.getInstance()
0132:                        .getCallbackUtilities().methodStart(shandle,
0133:                                "PackageAdmin.isPackageOpened");
0134:
0135:                try {
0136:                    if (!SharkUtilities.checkSession(shandle)) {
0137:                        throw new NotConnected(
0138:                                "The session handle is not valid!");
0139:                    }
0140:                    checkSecurity(shandle, "isPackageOpened", null);
0141:
0142:                    return getRepositoryPersistenceManager().doesXPDLExist(
0143:                            shandle, pkgId);
0144:                } finally {
0145:                    SharkEngineManager.getInstance().getCallbackUtilities()
0146:                            .methodEnd(shandle, tStamp,
0147:                                    "PackageAdmin.isPackageOpened",
0148:                                    "pkgId=" + pkgId);
0149:                }
0150:            }
0151:
0152:            public byte[] getPackageContent(WMSessionHandle shandle,
0153:                    String pkgId, String pkgVer) throws Exception {
0154:                long tStamp = SharkEngineManager.getInstance()
0155:                        .getCallbackUtilities().methodStart(shandle,
0156:                                "PackageAdmin.getPackageContent");
0157:                try {
0158:                    if (!SharkUtilities.checkSession(shandle)) {
0159:                        throw new NotConnected(
0160:                                "The session handle is not valid!");
0161:                    }
0162:                    checkSecurity(shandle, "getPackageContent", null);
0163:
0164:                    if (pkgVer == null || pkgVer.equals("")) {
0165:                        return convertSharkPackageContentXPDLByteArray(getRepositoryPersistenceManager()
0166:                                .getSerializedXPDLObject(shandle, pkgId));
0167:                    }
0168:                    return convertSharkPackageContentXPDLByteArray(getRepositoryPersistenceManager()
0169:                            .getSerializedXPDLObject(shandle, pkgId, pkgVer));
0170:                } finally {
0171:                    SharkEngineManager.getInstance().getCallbackUtilities()
0172:                            .methodEnd(shandle, tStamp,
0173:                                    "PackageAdmin.getPackageContent",
0174:                                    "pkgId=" + pkgId + ",pkgVer=" + pkgVer);
0175:                }
0176:            }
0177:
0178:            public WMEntity getPackageEntity(WMSessionHandle shandle,
0179:                    String pkgId, String pkgVer) throws Exception {
0180:                long tStamp = SharkEngineManager.getInstance()
0181:                        .getCallbackUtilities().methodStart(shandle,
0182:                                "PackageAdmin.getPackageEntity");
0183:                try {
0184:                    if (!SharkUtilities.checkSession(shandle)) {
0185:                        throw new NotConnected(
0186:                                "The session handle is not valid!");
0187:                    }
0188:                    checkSecurity(shandle, "getPackageEntity", null);
0189:
0190:                    if ("".equals(pkgVer)) {
0191:                        pkgVer = null;
0192:                    }
0193:                    Package pkg = SharkUtilities.getPackage(shandle, pkgId,
0194:                            pkgVer);
0195:                    if (pkg == null) {
0196:                        throw new Exception("There is no package with Id="
0197:                                + pkgId + " and version " + pkgVer);
0198:                    }
0199:
0200:                    return SharkUtilities.createBasicEntity(pkg);
0201:                } finally {
0202:                    SharkEngineManager.getInstance().getCallbackUtilities()
0203:                            .methodEnd(shandle, tStamp,
0204:                                    "PackageAdmin.getPackageEntity",
0205:                                    "pkgId=" + pkgId + ",pkgVer=" + pkgVer);
0206:                }
0207:            }
0208:
0209:            public String getCurrentPackageVersion(WMSessionHandle shandle,
0210:                    String pkgId) throws Exception {
0211:                long tStamp = SharkEngineManager.getInstance()
0212:                        .getCallbackUtilities().methodStart(shandle,
0213:                                "PackageAdmin.getCurrentPackageVersion");
0214:
0215:                try {
0216:                    if (!SharkUtilities.checkSession(shandle)) {
0217:                        throw new NotConnected(
0218:                                "The session handle is not valid!");
0219:                    }
0220:                    checkSecurity(shandle, "getCurrentPackageVersion", null);
0221:
0222:                    return getRepositoryPersistenceManager().getCurrentVersion(
0223:                            shandle, pkgId);
0224:                } finally {
0225:                    SharkEngineManager.getInstance().getCallbackUtilities()
0226:                            .methodEnd(shandle, tStamp,
0227:                                    "PackageAdmin.getCurrentPackageVersion",
0228:                                    "pkgId=" + pkgId);
0229:                }
0230:            }
0231:
0232:            public WMEntity uploadPackage(WMSessionHandle shandle,
0233:                    byte[] schemaContent) throws Exception {
0234:                long tStamp = SharkEngineManager.getInstance()
0235:                        .getCallbackUtilities().methodStart(shandle,
0236:                                "PackageAdmin.uploadPackage");
0237:
0238:                try {
0239:                    if (!SharkUtilities.checkSession(shandle)) {
0240:                        throw new NotConnected(
0241:                                "The session handle is not valid!");
0242:                    }
0243:                    checkSecurity(shandle, "uploadPackage", null);
0244:
0245:                    return openPackage(shandle, null, schemaContent);
0246:                } finally {
0247:                    SharkEngineManager.getInstance().getCallbackUtilities()
0248:                            .methodEnd(shandle, tStamp,
0249:                                    "PackageAdmin.uploadPackage", "");
0250:                }
0251:            }
0252:
0253:            public WMEntity uploadPackages(WMSessionHandle shandle,
0254:                    byte[][] schemaContents) throws Exception {
0255:                long tStamp = SharkEngineManager.getInstance()
0256:                        .getCallbackUtilities().methodStart(shandle,
0257:                                "PackageAdmin.uploadPackages");
0258:
0259:                try {
0260:                    if (!SharkUtilities.checkSession(shandle)) {
0261:                        throw new NotConnected(
0262:                                "The session handle is not valid!");
0263:                    }
0264:                    checkSecurity(shandle, "uploadPackages", null);
0265:
0266:                    List l = new ArrayList();
0267:                    for (int i = 0; i < schemaContents.length; i++) {
0268:                        l.add(schemaContents[i]);
0269:                    }
0270:                    return openPackage(shandle, null, schemaContents);
0271:                } finally {
0272:                    SharkEngineManager.getInstance().getCallbackUtilities()
0273:                            .methodEnd(shandle, tStamp,
0274:                                    "PackageAdmin.uploadPackages", "");
0275:                }
0276:            }
0277:
0278:            public WMEntity openPackage(WMSessionHandle shandle,
0279:                    String absolutePath) throws Exception {
0280:                long tStamp = SharkEngineManager.getInstance()
0281:                        .getCallbackUtilities().methodStart(shandle,
0282:                                "PackageAdmin.openPackage");
0283:
0284:                try {
0285:                    if (!SharkUtilities.checkSession(shandle)) {
0286:                        throw new NotConnected(
0287:                                "The session handle is not valid!");
0288:                    }
0289:                    checkSecurity(shandle, "openPackage", null);
0290:
0291:                    return openPackage(shandle, null, absolutePath);
0292:                } finally {
0293:                    SharkEngineManager.getInstance().getCallbackUtilities()
0294:                            .methodEnd(shandle, tStamp,
0295:                                    "PackageAdmin.openPackage",
0296:                                    "file=" + absolutePath);
0297:                }
0298:            }
0299:
0300:            public WMEntity updatePackage(WMSessionHandle shandle, String id,
0301:                    byte[] schemaContent) throws Exception {
0302:                long tStamp = SharkEngineManager.getInstance()
0303:                        .getCallbackUtilities().methodStart(shandle,
0304:                                "PackageAdmin.updatePackage");
0305:
0306:                try {
0307:                    if (!SharkUtilities.checkSession(shandle)) {
0308:                        throw new NotConnected(
0309:                                "The session handle is not valid!");
0310:                    }
0311:                    checkSecurity(shandle, "updatePackage", null);
0312:
0313:                    if (id == null)
0314:                        throw new Exception("Invalid package Id");
0315:                    return openPackage(shandle, id, schemaContent);
0316:                } finally {
0317:                    SharkEngineManager
0318:                            .getInstance()
0319:                            .getCallbackUtilities()
0320:                            .methodEnd(shandle, tStamp,
0321:                                    "PackageAdmin.updatePackage", "pkgId=" + id);
0322:                }
0323:            }
0324:
0325:            public WMEntity updatePackageFromFile(WMSessionHandle shandle,
0326:                    String id, String absolutePathToNewPackage)
0327:                    throws Exception {
0328:                long tStamp = SharkEngineManager.getInstance()
0329:                        .getCallbackUtilities().methodStart(shandle,
0330:                                "PackageAdmin.updatePackageFromFile");
0331:
0332:                try {
0333:                    if (!SharkUtilities.checkSession(shandle)) {
0334:                        throw new NotConnected(
0335:                                "The session handle is not valid!");
0336:                    }
0337:                    checkSecurity(shandle, "updatePackageFromFile", null);
0338:
0339:                    if (id == null)
0340:                        throw new Exception("Invalid package Id");
0341:                    return openPackage(shandle, id, absolutePathToNewPackage);
0342:                } finally {
0343:                    SharkEngineManager.getInstance().getCallbackUtilities()
0344:                            .methodEnd(
0345:                                    shandle,
0346:                                    tStamp,
0347:                                    "PackageAdmin.updatePackageFromFile",
0348:                                    "pkgId=" + id + ",file="
0349:                                            + absolutePathToNewPackage);
0350:                }
0351:            }
0352:
0353:            public WMEntityIterator closeAllPackagesForId(
0354:                    WMSessionHandle shandle, String pkgId) throws Exception {
0355:                long tStamp = SharkEngineManager.getInstance()
0356:                        .getCallbackUtilities().methodStart(shandle,
0357:                                "PackageAdmin.closeAllPackagesForId");
0358:
0359:                try {
0360:                    if (!SharkUtilities.checkSession(shandle)) {
0361:                        throw new NotConnected(
0362:                                "The session handle is not valid!");
0363:                    }
0364:                    checkSecurity(shandle, "closeAllPackagesForId", null);
0365:
0366:                    CallbackUtilities cus = SharkEngineManager.getInstance()
0367:                            .getCallbackUtilities();
0368:
0369:                    cus
0370:                            .info(
0371:                                    shandle,
0372:                                    "PackageAdmin -> User "
0373:                                            + cus.getUserId(shandle)
0374:                                            + " is trying to close all package versions of Package with id "
0375:                                            + pkgId);
0376:
0377:                    SharkUtilities.synchronizeXPDLCache(shandle);
0378:
0379:                    if (!getRepositoryPersistenceManager().doesXPDLExist(
0380:                            shandle, pkgId)) {
0381:                        throw new Exception("Package with Id=" + pkgId
0382:                                + " does not exist");
0383:                    }
0384:                    // check if there are any packages that uses this package as it's
0385:                    // external package
0386:                    if (getRepositoryPersistenceManager().getReferringXPDLIds(
0387:                            shandle, pkgId).size() > 0) {
0388:                        throw new PackageInUse(
0389:                                "The package can't be unloaded because it is referenced");
0390:                    }
0391:
0392:                    List pkgVers = getRepositoryPersistenceManager()
0393:                            .getXPDLVersions(shandle, pkgId);
0394:
0395:                    List pkgs = new ArrayList();
0396:                    for (int i = 0; i < pkgVers.size(); i++) {
0397:                        String pkgVer = (String) pkgVers.get(i);
0398:                        Package pkg = SharkUtilities.getPackage(shandle, pkgId,
0399:                                pkgVer);
0400:                        if (pkg == null) {
0401:                            throw new Exception(
0402:                                    "Package with Id="
0403:                                            + pkgId
0404:                                            + " - something went wrong while getting XPDL object");
0405:                        }
0406:                        pkgs.add(pkg);
0407:                    }
0408:
0409:                    Iterator it = pkgs.iterator();
0410:                    while (it.hasNext()) {
0411:                        Package pkg = (Package) it.next();
0412:
0413:                        // check if there are any processes that were created from this
0414:                        // packages process definition, and if so, throw an exception
0415:                        if (checkDBProcesses(shandle, pkg)) {
0416:                            throw new PackageHasActiveProcesses(
0417:                                    "Can't remove package [Id="
0418:                                            + pkgId
0419:                                            + ",Ver="
0420:                                            + pkg.getInternalVersion()
0421:                                            + "] because there is process instance that relates to this package");// can't
0422:                            // remove
0423:                            // package
0424:                            // with
0425:                            // active
0426:                            // processes
0427:                        }
0428:                    }
0429:
0430:                    List ents = new ArrayList();
0431:                    it = pkgs.iterator();
0432:                    while (it.hasNext()) {
0433:                        Package pkg = (Package) it.next();
0434:                        getRepositoryPersistenceManager().moveToHistory(
0435:                                shandle, pkgId, pkg.getInternalVersion());
0436:
0437:                        new WfPackageEventAuditImpl(shandle, pkg,
0438:                                SharkConstants.EVENT_PACKAGE_UNLOADED);
0439:                        ents.add(SharkUtilities.createBasicEntity(pkg));
0440:                        // remove all engine objects
0441:                        getXMLInterface().closePackageVersion(pkgId,
0442:                                pkg.getInternalVersion());
0443:                    }
0444:
0445:                    removeManagersForPackages(shandle, pkgs);
0446:
0447:                    SharkEngineManager.getInstance().getCallbackUtilities()
0448:                            .info(
0449:                                    shandle,
0450:                                    "PackageAdmin -> User "
0451:                                            + cus.getUserId(shandle)
0452:                                            + " has closed Package with id "
0453:                                            + pkgId);
0454:                    WMEntity[] enta = new WMEntity[ents.size()];
0455:                    ents.toArray(enta);
0456:                    WMEntityIterator wmei = new WMEntityIterator();
0457:                    wmei.setCount(ents.size());
0458:                    wmei.setArray(enta);
0459:                    return wmei;
0460:                } finally {
0461:                    SharkEngineManager.getInstance().getCallbackUtilities()
0462:                            .methodEnd(shandle, tStamp,
0463:                                    "PackageAdmin.closeAllPackagesForId",
0464:                                    "pkgId=" + pkgId);
0465:                }
0466:
0467:            }
0468:
0469:            public WMEntity closePackage(WMSessionHandle shandle, String pkgId,
0470:                    String pkgVer) throws Exception {
0471:                long tStamp = SharkEngineManager.getInstance()
0472:                        .getCallbackUtilities().methodStart(shandle,
0473:                                "PackageAdmin.closePackage");
0474:
0475:                try {
0476:                    if (!SharkUtilities.checkSession(shandle)) {
0477:                        throw new NotConnected(
0478:                                "The session handle is not valid!");
0479:                    }
0480:                    checkSecurity(shandle, "closePackage", null);
0481:
0482:                    CallbackUtilities cus = SharkEngineManager.getInstance()
0483:                            .getCallbackUtilities();
0484:                    cus.info(shandle, "PackageAdmin -> User "
0485:                            + cus.getUserId(shandle)
0486:                            + " is trying to close Package with id " + pkgId
0487:                            + ", and version " + pkgVer);
0488:
0489:                    SharkUtilities.synchronizeXPDLCache(shandle);
0490:
0491:                    if (!getRepositoryPersistenceManager().doesXPDLExist(
0492:                            shandle, pkgId, pkgVer)) {
0493:                        throw new Exception("Package with Id=" + pkgId
0494:                                + " and version=" + pkgVer + " does not exist");
0495:                    }
0496:
0497:                    Package pkg = SharkUtilities.getPackage(shandle, pkgId,
0498:                            pkgVer);
0499:                    if (pkg == null) {
0500:                        throw new Exception(
0501:                                "Package with Id="
0502:                                        + pkgId
0503:                                        + " - something went wrong while getting XPDL object");
0504:                    }
0505:
0506:                    String curVer = getRepositoryPersistenceManager()
0507:                            .getCurrentVersion(shandle, pkgId);
0508:                    // check if there are any packages that uses this package as it's
0509:                    // external package
0510:                    if (getRepositoryPersistenceManager().getReferringXPDLIds(
0511:                            shandle, pkgId).size() > 0
0512:                            && pkgVer.equals(curVer)) {
0513:                        throw new PackageInUse(
0514:                                "The package can't be unloaded because it is referenced");
0515:                    }
0516:
0517:                    boolean dpe;
0518:
0519:                    // check if there are any processes that were created from this
0520:                    // packages process definition, and if so, throw an exception
0521:                    dpe = checkDBProcesses(shandle, pkg);
0522:
0523:                    if (dpe) {
0524:                        throw new PackageHasActiveProcesses(
0525:                                "Can't remove package with processes instances in DB");// can't
0526:                        // remove
0527:                        // package
0528:                        // with
0529:                        // active
0530:                        // processes
0531:                    }
0532:
0533:                    getRepositoryPersistenceManager().moveToHistory(shandle,
0534:                            pkgId, pkgVer);
0535:
0536:                    new WfPackageEventAuditImpl(shandle, pkg,
0537:                            SharkConstants.EVENT_PACKAGE_UNLOADED);
0538:                    // remove all engine objects
0539:                    getXMLInterface().closePackageVersion(pkgId, pkgVer);
0540:
0541:                    removeManagersForPackage(shandle, pkg);
0542:
0543:                    SharkEngineManager.getInstance().getCallbackUtilities()
0544:                            .info(
0545:                                    shandle,
0546:                                    "PackageAdmin -> User "
0547:                                            + cus.getUserId(shandle)
0548:                                            + " has closed Package with id "
0549:                                            + pkgId + " and version " + pkgVer);
0550:                    return SharkUtilities.createBasicEntity(pkg);
0551:                } finally {
0552:                    SharkEngineManager.getInstance().getCallbackUtilities()
0553:                            .methodEnd(shandle, tStamp,
0554:                                    "PackageAdmin.closePackage",
0555:                                    "pkgId=" + pkgId + ",pkgVer=" + pkgVer);
0556:                }
0557:            }
0558:
0559:            // returns true if there are processes in DB
0560:            private boolean checkDBProcesses(WMSessionHandle shandle,
0561:                    Package pkg) throws Exception {
0562:                // check if there are any processes that were created from this
0563:                // packages process definition, and if so, throw an exception
0564:                Iterator processes = ((WorkflowProcesses) pkg
0565:                        .get("WorkflowProcesses")).toElements().iterator();
0566:                while (processes.hasNext()) {
0567:                    WorkflowProcess wp = (WorkflowProcess) processes.next();
0568:                    String mgrName = MiscUtilities.createProcessMgrKey(pkg
0569:                            .getId(), pkg.getInternalVersion(), wp.getId());
0570:                    List procs = SharkEngineManager.getInstance()
0571:                            .getInstancePersistenceManager()
0572:                            .getAllProcessesForMgr(shandle, mgrName);
0573:                    if (procs != null && procs.size() > 0) {
0574:                        return true;
0575:                    }
0576:                }
0577:                return false;
0578:            }
0579:
0580:            public boolean isPackageReferenced(WMSessionHandle shandle,
0581:                    String pkgId) throws Exception {
0582:                long tStamp = SharkEngineManager.getInstance()
0583:                        .getCallbackUtilities().methodStart(shandle,
0584:                                "PackageAdmin.isPackageReferenced");
0585:
0586:                try {
0587:                    if (!SharkUtilities.checkSession(shandle)) {
0588:                        throw new NotConnected(
0589:                                "The session handle is not valid!");
0590:                    }
0591:                    checkSecurity(shandle, "isPackageReferenced", null);
0592:
0593:                    return getRepositoryPersistenceManager()
0594:                            .getReferringXPDLIds(shandle, pkgId).size() > 0;
0595:                } finally {
0596:                    SharkEngineManager.getInstance().getCallbackUtilities()
0597:                            .methodEnd(shandle, tStamp,
0598:                                    "PackageAdmin.isPackageReferenced",
0599:                                    "pkgId=" + pkgId);
0600:                }
0601:            }
0602:
0603:            public void synchronizeXPDLCache(WMSessionHandle shandle)
0604:                    throws Exception {
0605:                long tStamp = SharkEngineManager.getInstance()
0606:                        .getCallbackUtilities().methodStart(shandle,
0607:                                "PackageAdmin.synchronizeXPDLCache");
0608:
0609:                try {
0610:                    if (!SharkUtilities.checkSession(shandle)) {
0611:                        throw new NotConnected(
0612:                                "The session handle is not valid!");
0613:                    }
0614:                    checkSecurity(shandle, "synchronizeXPDLCache", null);
0615:
0616:                    SharkUtilities.synchronizeXPDLCache(shandle);
0617:                } finally {
0618:                    SharkEngineManager.getInstance().getCallbackUtilities()
0619:                            .methodEnd(shandle, tStamp,
0620:                                    "PackageAdmin.synchronizeXPDLCache", "");
0621:                }
0622:            }
0623:
0624:            public void clearXPDLCache(WMSessionHandle shandle)
0625:                    throws Exception {
0626:                long tStamp = SharkEngineManager.getInstance()
0627:                        .getCallbackUtilities().methodStart(shandle,
0628:                                "PackageAdmin.clearXPDLCache");
0629:
0630:                try {
0631:                    if (!SharkUtilities.checkSession(shandle)) {
0632:                        throw new NotConnected(
0633:                                "The session handle is not valid!");
0634:                    }
0635:                    checkSecurity(shandle, "clearXPDLCache", null);
0636:
0637:                    SharkUtilities.clearProcessCache();
0638:                    getXMLInterface().closeAllPackages();
0639:                } finally {
0640:                    SharkEngineManager.getInstance().getCallbackUtilities()
0641:                            .methodEnd(shandle, tStamp,
0642:                                    "PackageAdmin.clearXPDLCache", "");
0643:                }
0644:            }
0645:
0646:            public void refreshXPDLCache(WMSessionHandle shandle)
0647:                    throws Exception {
0648:                long tStamp = SharkEngineManager.getInstance()
0649:                        .getCallbackUtilities().methodStart(shandle,
0650:                                "PackageAdmin.refreshXPDLCache");
0651:
0652:                try {
0653:                    if (!SharkUtilities.checkSession(shandle)) {
0654:                        throw new NotConnected(
0655:                                "The session handle is not valid!");
0656:                    }
0657:                    checkSecurity(shandle, "refreshXPDLCache", null);
0658:
0659:                    SharkUtilities.clearProcessCache();
0660:                    getXMLInterface().closeAllPackages();
0661:                    SharkUtilities.synchronizeXPDLCache(shandle);
0662:                } finally {
0663:                    SharkEngineManager.getInstance().getCallbackUtilities()
0664:                            .methodEnd(shandle, tStamp,
0665:                                    "PackageAdmin.refreshXPDLCache", "");
0666:                }
0667:            }
0668:
0669:            private synchronized WMEntity openPackage(WMSessionHandle shandle,
0670:                    String id, Object absolutePathOrBA) throws Exception {
0671:                String absolutePath = null;
0672:                byte[] schemaContent = null;
0673:                List schContents = null;
0674:
0675:                if (absolutePathOrBA instanceof  String) {
0676:                    absolutePath = (String) absolutePathOrBA;
0677:                } else if (absolutePathOrBA instanceof  byte[]) {
0678:                    schemaContent = (byte[]) absolutePathOrBA;
0679:                } else {
0680:                    schContents = (List) absolutePathOrBA;
0681:                }
0682:
0683:                boolean update = (id != null);
0684:                String msgI = "";
0685:                if (update) {
0686:                    msgI = "PackageAdmin -> Trying to update Package with id="
0687:                            + id + " with ";
0688:                    if (absolutePath == null) {
0689:                        msgI += "given byte[] content";
0690:                    } else {
0691:                        msgI += "content of file at " + absolutePath;
0692:                    }
0693:                } else {
0694:                    msgI = "PackageAdmin -> Trying to open Package ";
0695:                    if (absolutePath == null) {
0696:                        msgI += "from provided byte[] content";
0697:                    } else {
0698:                        msgI += "file " + absolutePath;
0699:                    }
0700:                }
0701:
0702:                SharkEngineManager.getInstance().getCallbackUtilities().info(
0703:                        shandle, msgI);
0704:                // now really import the package(s) into engine
0705:                int exceptionHappened = 0;
0706:                XMLInterface xpdlManager = new XMLInterfaceForJDK13();
0707:                Package pkg = null;
0708:                String pkgId = null;
0709:                WMEntity ent = null;
0710:                Map pkgInfo = new HashMap();
0711:
0712:                if (absolutePath != null) {
0713:                    absolutePath = XMLUtil.convertToSystemPath(absolutePath);
0714:                }
0715:
0716:                try {
0717:                    if (absolutePath != null) {
0718:                        // NOTE: getIdFromFile will be moved to XMLUtil class
0719:                        pkgId = XMLUtil.getIdFromFile(absolutePath);
0720:                    } else {
0721:                        if (schemaContent != null) {
0722:                            pkg = xpdlManager.openPackageFromStream(
0723:                                    schemaContent, true);
0724:                        } else {
0725:                            pkg = xpdlManager.openPackagesFromStreams(
0726:                                    schContents, true);
0727:                        }
0728:                        if (pkg == null) {
0729:                            String msg = "The package byte[] representation can't be parsed";
0730:                            SharkEngineManager.getInstance()
0731:                                    .getCallbackUtilities().warn(shandle,
0732:                                            "PackageAdmin -> " + msg);
0733:                            Exception bex = new Exception(msg);
0734:                            throw bex;
0735:
0736:                        }
0737:                        pkgId = pkg.getId();
0738:                        // search external packages, and if any, search for them in the currently
0739:                        // uploaded packages and put it in xpdlManager
0740:                        Set extPkgIds = new HashSet();
0741:                        Iterator it = xpdlManager.getAllPackages().iterator();
0742:                        while (it.hasNext()) {
0743:                            Package p = (Package) it.next();
0744:                            extPkgIds.addAll(p.getExternalPackageIds());
0745:                        }
0746:                        it = extPkgIds.iterator();
0747:                        Set missingPkgs = new HashSet();
0748:                        while (it.hasNext()) {
0749:                            String pid = (String) it.next();
0750:                            if (!xpdlManager.isPackageOpened(pid)
0751:                                    && getXMLInterface().isPackageOpened(pid)) {
0752:                                missingPkgs.add(pid);
0753:                            }
0754:                        }
0755:                        if (missingPkgs.size() > 0) {
0756:                            it = missingPkgs.iterator();
0757:                            List pkgContents = new ArrayList();
0758:                            while (it.hasNext()) {
0759:                                String pid = (String) it.next();
0760:                                pkgContents
0761:                                        .add(getRepositoryPersistenceManager()
0762:                                                .getSerializedXPDLObject(
0763:                                                        shandle,
0764:                                                        pid,
0765:                                                        getRepositoryPersistenceManager()
0766:                                                                .getCurrentVersion(
0767:                                                                        shandle,
0768:                                                                        pid)));
0769:                            }
0770:                            xpdlManager.setValidation(false);
0771:                            xpdlManager.openPackagesFromStreams(pkgContents,
0772:                                    false);
0773:                            xpdlManager.setValidation(true);
0774:                        }
0775:                    }
0776:
0777:                    if (id != null && !id.equals(pkgId)) {
0778:                        String msg = "";
0779:                        if (absolutePath != null) {
0780:                            msg = "The package at path=" + absolutePath
0781:                                    + " does not have the id=" + id;
0782:                        } else {
0783:                            msg = "The package's byte[] representation does not have the id="
0784:                                    + id;
0785:                        }
0786:
0787:                        SharkEngineManager.getInstance().getCallbackUtilities()
0788:                                .warn(shandle, "PackageAdmin -> " + msg);
0789:                        Exception bex = new Exception(msg);
0790:                        throw bex;
0791:
0792:                    }
0793:
0794:                    // the list of already opened package Ids
0795:                    Set currentPkgIds = new HashSet(
0796:                            getRepositoryPersistenceManager()
0797:                                    .getExistingXPDLIds(shandle));
0798:
0799:                    // if package user wants to open has the same Id as the one already opened - do
0800:                    // not proceed
0801:                    if (id != null && !currentPkgIds.contains(pkgId)) {
0802:                        String msg = "The package with id " + pkgId
0803:                                + " is not open";
0804:                        SharkEngineManager.getInstance().getCallbackUtilities()
0805:                                .warn(shandle, "PackageAdmin -> " + msg);
0806:                        Exception bex = new Exception(msg);
0807:                        throw bex;
0808:                    }
0809:
0810:                    // if package user wants to open has the same Id as the one already opened - do
0811:                    // not proceed
0812:                    if (id == null && currentPkgIds.contains(pkgId)) {
0813:                        String msg = "The package with id " + pkgId
0814:                                + " is already open";
0815:                        SharkEngineManager.getInstance().getCallbackUtilities()
0816:                                .warn(shandle, "PackageAdmin -> " + msg);
0817:                        Exception bex = new Exception(msg);
0818:                        throw bex;
0819:                    }
0820:
0821:                    String pkgVersion = getRepositoryPersistenceManager()
0822:                            .getNextVersion(shandle, pkgId);
0823:
0824:                    boolean ignoreValidationWarnings = SharkEngineManager
0825:                            .getInstance().getCallbackUtilities().getProperty(
0826:                                    "SharkKernel.IgnoreXPDLValidationWarnings",
0827:                                    "false").equals("true");
0828:
0829:                    if (absolutePath != null) {
0830:                        pkg = xpdlManager.openPackage(absolutePath, true);
0831:                    }
0832:                    pkg.setInternalVersion(pkgVersion);
0833:                    // if there are any errors - do not proceed
0834:                    SharkPackageValidator pv = new SharkPackageValidator();
0835:                    pv.init(MiscUtilities
0836:                            .convertNameValueArrayToProperties(Shark
0837:                                    .getInstance().getProperties()),
0838:                            xpdlManager);
0839:                    List errors = new ArrayList();
0840:                    if (pkg != null) {
0841:                        pv.validateElement(pkg, errors, true);
0842:                    }
0843:                    String xpdlValidationErrors = "";
0844:                    if (pkg == null
0845:                            || (errors.size() > 0 && (!ignoreValidationWarnings || pv
0846:                                    .hasErrors(errors)))) {
0847:                        SharkEngineManager.getInstance().getCallbackUtilities()
0848:                                .info(
0849:                                        shandle,
0850:                                        "PackageAdmin -> Package file "
0851:                                                + absolutePath
0852:                                                + " failed to open");
0853:                        if (pkg != null) {
0854:                            xpdlValidationErrors = createXPDLValidationErrorsString(errors);
0855:                        } else {
0856:                            xpdlValidationErrors = "Fatal error while opening package from ext. rep.";
0857:                        }
0858:                        if (pkg == null) {
0859:                            exceptionHappened = 1;
0860:                            throw new PackageInvalid(xpdlValidationErrors,
0861:                                    "No package");
0862:                        } else if (isExternalPackageError(pkg, errors)) {
0863:                            exceptionHappened = 2;
0864:                            // pv.printDebug();
0865:                            throw new ExternalPackageInvalid(
0866:                                    xpdlValidationErrors,
0867:                                    "Error in external package");
0868:                        } else {
0869:                            exceptionHappened = 1;
0870:                            // pv.printDebug();
0871:                            throw new PackageInvalid(xpdlValidationErrors,
0872:                                    "Error in package");
0873:                        }
0874:                    }
0875:
0876:                    // System.out.println("SXPDLC1");
0877:                    SharkUtilities.synchronizeXPDLCache(shandle);
0878:
0879:                    ent = SharkUtilities.createBasicEntity(pkg);
0880:
0881:                    // adjusts pkg version, and fills the info for the packages that need to
0882:                    // be uploaded to the internal repository
0883:                    boolean chckExt = adjustPkgsForInternalRep(shandle,
0884:                            xpdlManager, pkgInfo, pkgId, update);
0885:
0886:                    /*
0887:                     * Set pkgIdsToUpload=new HashSet(); Iterator it=pkgInfo.values().iterator();
0888:                     * while (it.hasNext()) { PkgInfo pi=(PkgInfo)it.next(); if (pi.isForUpload()) {
0889:                     * pkgIdsToUpload.add(pi.getId()); } }
0890:                     */
0891:
0892:                    // if some of ext. pkgs are already opened - recheck
0893:                    if (chckExt) {
0894:                        // close all temporary packages
0895:                        xpdlManager.closeAllPackages();
0896:
0897:                        // add all packages from remembered context map
0898:                        List pkgContents = new ArrayList();
0899:                        Iterator info = pkgInfo.values().iterator();
0900:                        while (info.hasNext()) {
0901:                            PkgInfo pi = (PkgInfo) info.next();
0902:                            if (pi.isForUpload()) {
0903:                                pkgContents.add(pi.getByteContent());
0904:                            } else {
0905:                                pkgContents
0906:                                        .add(getRepositoryPersistenceManager()
0907:                                                .getSerializedXPDLObject(
0908:                                                        shandle, pi.getId(),
0909:                                                        pi.getVersion()));
0910:                            }
0911:                        }
0912:
0913:                        xpdlManager.setValidation(false);
0914:                        pkg = xpdlManager.openPackagesFromStreams(pkgContents,
0915:                                false);
0916:                        xpdlManager.setValidation(true);
0917:                        // if there are any errors - do not proceed
0918:                        pv = new SharkPackageValidator();
0919:                        pv.init(MiscUtilities
0920:                                .convertNameValueArrayToProperties(Shark
0921:                                        .getInstance().getProperties()),
0922:                                xpdlManager);
0923:                        errors = new ArrayList();
0924:                        if (pkg != null) {
0925:                            pv.validateElement(pkg, errors, true);
0926:                        }
0927:                        xpdlValidationErrors = "";
0928:                        if (pkg == null
0929:                                || (errors.size() > 0 && (!ignoreValidationWarnings || pv
0930:                                        .hasErrors(errors)))) {
0931:                            SharkEngineManager.getInstance()
0932:                                    .getCallbackUtilities().info(
0933:                                            shandle,
0934:                                            "PackageAdmin -> Package file "
0935:                                                    + absolutePath
0936:                                                    + " failed to open");
0937:                            if (pkg != null) {
0938:                                xpdlValidationErrors = createXPDLValidationErrorsString(errors);
0939:                            } else {
0940:                                xpdlValidationErrors = "Fatal error while opening package";
0941:                            }
0942:                            if (pkg == null) {
0943:                                exceptionHappened = 1;
0944:                                throw new PackageInvalid(xpdlValidationErrors,
0945:                                        "No package");
0946:                            } else if (isExternalPackageError(pkg, errors)) {
0947:                                SharkEngineManager
0948:                                        .getInstance()
0949:                                        .getCallbackUtilities()
0950:                                        .warn(
0951:                                                shandle,
0952:                                                "PackageAdmin -> there is some external package with the same Id and different content as the one of already opened packages - failed to open");
0953:                                exceptionHappened = 2;
0954:                                throw new ExternalPackageInvalid(
0955:                                        "There is some external package with the same Id and different content as the one of already opened packages - failed to open",
0956:                                        "Error with ext. package");
0957:                            } else {
0958:                                exceptionHappened = 1;
0959:                                // pv.printDebug();
0960:                                throw new PackageInvalid(xpdlValidationErrors,
0961:                                        "Error in package");
0962:                            }
0963:                        }
0964:
0965:                    }
0966:
0967:                    xpdlManager.closeAllPackages();
0968:
0969:                    exceptionHappened = 3;
0970:
0971:                    copyPackagesToInternalPackagesRepository(shandle, pkgInfo
0972:                            .values());
0973:
0974:                    // System.out.println("SXPDLC2");
0975:                    SharkUtilities.synchronizeXPDLCache(shandle);
0976:
0977:                    Iterator it = pkgInfo.values().iterator();
0978:                    Set pkgsToUpload = new HashSet();
0979:                    while (it.hasNext()) {
0980:                        PkgInfo pinf = (PkgInfo) it.next();
0981:                        if (pinf.isForUpload()) {
0982:                            Package p = getXMLInterface()
0983:                                    .getPackageByIdAndVersion(pinf.getId(),
0984:                                            pinf.getVersion());
0985:                            String evType = SharkConstants.EVENT_PACKAGE_LOADED;
0986:                            if (update && pinf.getId().equals(id)) {
0987:                                evType = SharkConstants.EVENT_PACKAGE_UPDATED;
0988:                            }
0989:                            new WfPackageEventAuditImpl(shandle, p, evType);
0990:                            pkgsToUpload.add(p);
0991:                        }
0992:                    }
0993:
0994:                    // clearing process caches
0995:                    // THIS SHOULD BE LAST METHOD TO CALL - BECAUSE OF ROLLBACK
0996:                    addManagersForPackages(shandle, pkgsToUpload);
0997:
0998:                } catch (Exception ex) {
0999:                    // System.err.println("Exc during opening of package "+urlToPackage);
1000:                    ex.printStackTrace();
1001:                    String msg = "";
1002:                    if (absolutePath != null) {
1003:                        msg = "PackageAdmin -> Package file " + absolutePath
1004:                                + " failed to open";
1005:                    } else {
1006:                        msg = "PackageAdmin -> Package byte[] representation failed to open";
1007:                    }
1008:                    SharkEngineManager.getInstance().getCallbackUtilities()
1009:                            .error(shandle, msg);
1010:                    if (exceptionHappened == 0) {
1011:                        throw ex;
1012:                    } else if (exceptionHappened == 1) {
1013:                        throw (PackageInvalid) ex;
1014:                    } else if (exceptionHappened == 2) {
1015:                        throw (ExternalPackageInvalid) ex;
1016:                    } else {
1017:                        if (pkgInfo != null) {
1018:                            Iterator it = pkgInfo.values().iterator();
1019:                            while (it.hasNext()) {
1020:                                PkgInfo pi = (PkgInfo) it.next();
1021:                                try {
1022:                                    getXMLInterface().closePackageVersion(
1023:                                            pi.getId(), pi.getVersion());
1024:                                } catch (Exception exc2) {
1025:                                }
1026:                            }
1027:                        }
1028:
1029:                        throw ex;
1030:                    }
1031:                } finally {
1032:                    xpdlManager.closeAllPackages();
1033:                }
1034:                String msg = "PackageAdmin -> Package with id=" + pkgId
1035:                        + " is " + ((update) ? "updated" : "opened");
1036:                if (absolutePath == null) {
1037:                    msg += " from provided byte[] content";
1038:                } else {
1039:                    msg += " from a file " + absolutePath;
1040:                }
1041:                SharkEngineManager.getInstance().getCallbackUtilities().info(
1042:                        shandle, msg);
1043:                return ent;
1044:
1045:            }
1046:
1047:            /**
1048:             * Add a workflow package to the engine.
1049:             * 
1050:             * @param packages - collection of workflow packages
1051:             * @throws Exception
1052:             */
1053:            private void addManagersForPackages(WMSessionHandle shandle,
1054:                    Collection pkgInfo) throws Exception {
1055:                Iterator mdls = pkgInfo.iterator();
1056:                while (mdls.hasNext()) {
1057:                    Package p = (Package) mdls.next();
1058:                    String pkgId = p.getId();
1059:                    String pkgVer = p.getInternalVersion();
1060:                    // System.out.println("Adding mgrs for pinfo="+pi);
1061:                    // creating process managers for all definitions within inserted package
1062:                    WorkflowProcesses wps = p.getWorkflowProcesses();
1063:                    Iterator it = wps.toElements().iterator();
1064:                    while (it.hasNext()) {
1065:                        WorkflowProcess wp = (WorkflowProcess) it.next();
1066:                        SharkEngineManager.getInstance().getObjectFactory()
1067:                                .createProcessMgr(shandle, pkgId, pkgVer,
1068:                                        wp.getId());
1069:                        SharkEngineManager.getInstance().getCallbackUtilities()
1070:                                .info(
1071:                                        shandle,
1072:                                        "PackageAdmin -> ProcessDefinition "
1073:                                                + wp.getId() + " for package "
1074:                                                + p.getId() + " and version "
1075:                                                + pkgVer + " is added");
1076:                    }
1077:                }
1078:            }
1079:
1080:            private void copyPackagesToInternalPackagesRepository(
1081:                    WMSessionHandle shandle, Collection pkgInfo)
1082:                    throws Exception {
1083:                // uploading packages
1084:                Iterator ptc = pkgInfo.iterator();
1085:                while (ptc.hasNext()) {
1086:                    PkgInfo pi = (PkgInfo) ptc.next();
1087:                    if (pi.isForUpload()) {
1088:                        // System.out.println("Uploading pkg "+pi.getId()+"V="+Version.getVersion());
1089:                        getRepositoryPersistenceManager().uploadXPDL(shandle,
1090:                                pi.getId(), pi.getXPDLContent(),
1091:                                pi.getByteContent(), Version.getVersion());
1092:                    }
1093:                }
1094:
1095:                // adding references
1096:                ptc = pkgInfo.iterator();
1097:                while (ptc.hasNext()) {
1098:                    PkgInfo pi = (PkgInfo) ptc.next();
1099:                    if (pi.isForUpload()) {
1100:                        Iterator it = pi.getExtRefIds().iterator();
1101:                        int i = 0;
1102:                        while (it.hasNext()) {
1103:                            getRepositoryPersistenceManager().addXPDLReference(
1104:                                    shandle, (String) it.next(), pi.getId(),
1105:                                    pi.getVersion(), i++);
1106:                        }
1107:                    }
1108:                }
1109:            }
1110:
1111:            private void removeManagersForPackage(WMSessionHandle shandle,
1112:                    Package pkg) throws Exception {
1113:                if (pkg != null) {
1114:                    WorkflowProcesses wps = pkg.getWorkflowProcesses();
1115:                    Iterator it = wps.toElements().iterator();
1116:                    while (it.hasNext()) {
1117:                        WorkflowProcess wp = (WorkflowProcess) it.next();
1118:                        WfProcessMgrInternal toRem = SharkUtilities
1119:                                .getProcessMgr(shandle, MiscUtilities
1120:                                        .createProcessMgrKey(pkg.getId(), pkg
1121:                                                .getInternalVersion(), wp
1122:                                                .getId()));
1123:                        // deleting database entry for this process manager
1124:                        if (toRem != null) {
1125:                            toRem.delete(shandle);
1126:                            SharkEngineManager.getInstance()
1127:                                    .getCallbackUtilities().info(
1128:                                            shandle,
1129:                                            "PackageAdmin -> ProcessDefinition "
1130:                                                    + wp.getId()
1131:                                                    + " for package "
1132:                                                    + pkg.getId()
1133:                                                    + " and version "
1134:                                                    + pkg.getInternalVersion()
1135:                                                    + " is removed");
1136:                        }
1137:                    }
1138:                }
1139:            }
1140:
1141:            private void removeManagersForPackages(WMSessionHandle shandle,
1142:                    Collection pkgs) throws Exception {
1143:                if (pkgs != null) {
1144:                    Iterator itPkgs = pkgs.iterator();
1145:                    while (itPkgs.hasNext()) {
1146:                        Package pkg = (Package) itPkgs.next();
1147:                        WorkflowProcesses wps = (WorkflowProcesses) pkg
1148:                                .get("WorkflowProcesses");
1149:                        Iterator it = wps.toElements().iterator();
1150:                        while (it.hasNext()) {
1151:                            WorkflowProcess wp = (WorkflowProcess) it.next();
1152:                            WfProcessMgrInternal toRem = SharkUtilities
1153:                                    .getProcessMgr(shandle, MiscUtilities
1154:                                            .createProcessMgrKey(pkg.getId(),
1155:                                                    pkg.getInternalVersion(),
1156:                                                    wp.getId()));
1157:                            // deleting database entry for this process manager
1158:                            if (toRem != null) {
1159:                                toRem.delete(shandle);
1160:                                SharkEngineManager
1161:                                        .getInstance()
1162:                                        .getCallbackUtilities()
1163:                                        .info(
1164:                                                shandle,
1165:                                                "PackageAdmin -> ProcessDefinition "
1166:                                                        + wp.getId()
1167:                                                        + " for package "
1168:                                                        + pkg.getId()
1169:                                                        + " and version "
1170:                                                        + pkg
1171:                                                                .getInternalVersion()
1172:                                                        + " is removed");
1173:                            }
1174:                        }
1175:                    }
1176:                }
1177:            }
1178:
1179:            private boolean adjustPkgsForInternalRep(WMSessionHandle shandle,
1180:                    XMLInterface xpdlMgr, Map pkgInfo, String mainPkgId,
1181:                    boolean update) throws Exception {
1182:                boolean chckExt = false;
1183:                Collection pkgsToAdjust = new HashSet(xpdlMgr.getAllPackages());
1184:                Iterator packages = pkgsToAdjust.iterator();
1185:                while (packages.hasNext()) {
1186:                    Package p = (Package) packages.next();
1187:                    String pkgId = p.getId();
1188:                    String version = null;
1189:                    boolean forUpl = false;
1190:                    if (!getRepositoryPersistenceManager().doesXPDLExist(
1191:                            shandle, pkgId)
1192:                            || (update && pkgId.equals(mainPkgId))) {
1193:                        version = getRepositoryPersistenceManager()
1194:                                .getNextVersion(shandle, pkgId);
1195:                        forUpl = true;
1196:                    } else {
1197:                        version = getRepositoryPersistenceManager()
1198:                                .getCurrentVersion(shandle, pkgId);
1199:                        chckExt = true;
1200:                    }
1201:                    p.setInternalVersion(version);
1202:
1203:                    PkgInfo pInfo = new PkgInfo(p, version, forUpl);
1204:                    // System.out.println("Added pkgInfo "+pInfo.toString());
1205:                    pkgInfo.put(pkgId, pInfo);
1206:                }
1207:                return chckExt;
1208:            }
1209:
1210:            static class PkgInfo {
1211:                private Package pkg;
1212:
1213:                private String version;
1214:
1215:                private boolean isForUpload;
1216:
1217:                private byte[] content;
1218:
1219:                private byte[] xpdlContent;
1220:
1221:                public PkgInfo(Package pkg, String version, boolean isForUpload)
1222:                        throws Exception {
1223:                    this .pkg = pkg;
1224:                    this .version = version;
1225:                    this .isForUpload = isForUpload;
1226:                    if (isForUpload) {
1227:                        pkg.setReadOnly(true);
1228:                        ByteArrayOutputStream os = new ByteArrayOutputStream();
1229:                        XMLUtil.packageToStream(pkg, os);
1230:                        xpdlContent = os.toByteArray();
1231:                        os.close();
1232:                    }
1233:                    this .content = XMLUtil.serialize(pkg);
1234:
1235:                }
1236:
1237:                public Package getPackage() {
1238:                    return pkg;
1239:                }
1240:
1241:                public void setPackage(Package pkg) {
1242:                    this .pkg = pkg;
1243:                }
1244:
1245:                public String getId() {
1246:                    return pkg.getId();
1247:                }
1248:
1249:                public String getVersion() {
1250:                    return version;
1251:                }
1252:
1253:                public Collection getExtRefIds() {
1254:                    return pkg.getExternalPackageIds();
1255:                }
1256:
1257:                public byte[] getXPDLContent() {
1258:                    return xpdlContent;
1259:                }
1260:
1261:                public byte[] getByteContent() {
1262:                    return content;
1263:                }
1264:
1265:                public boolean isForUpload() {
1266:                    return isForUpload;
1267:                }
1268:
1269:                public String toString() {
1270:                    return "PKG=" + pkg + ",Id=" + pkg.getId() + ",isForUpl="
1271:                            + isForUpload + "]";
1272:                }
1273:            }
1274:
1275:            public static byte[] convertSharkPackageContentXPDLByteArray(
1276:                    byte[] sharkPkgBytes) throws Exception {
1277:                Package shrkPkg = (Package) XMLUtil.deserialize(sharkPkgBytes);
1278:                shrkPkg.setReadOnly(false);
1279:                Iterator it = shrkPkg.getExternalPackages().toElements()
1280:                        .iterator();
1281:                while (it.hasNext()) {
1282:                    ExternalPackage ep = (ExternalPackage) it.next();
1283:                    String nhref = shrkPkg.getExternalPackageId(ep.getHref());
1284:                    ep.setHref(nhref);
1285:                }
1286:                ByteArrayOutputStream os = new ByteArrayOutputStream();
1287:                XMLUtil.packageToStream(shrkPkg, os);
1288:                byte[] content = os.toByteArray();
1289:                os.close();
1290:                return content;
1291:            }
1292:
1293:            protected void checkSecurity(WMSessionHandle shandle,
1294:                    String methodName, Map d) throws Exception {
1295:                SecurityManager sm = SharkEngineManager.getInstance()
1296:                        .getSecurityManager();
1297:                if (sm != null) {
1298:                    sm.check_security(shandle, this .getClass(), methodName, d);
1299:                }
1300:            }
1301:
1302:            public boolean isExternalPackageError(Package main, List errors) {
1303:                for (int i = 0; i < errors.size(); i++) {
1304:                    XMLValidationError err = (XMLValidationError) errors.get(i);
1305:                    if (XMLUtil.getPackage(err.getElement()) == main) {
1306:                        return false;
1307:                    }
1308:                }
1309:                return true;
1310:            }
1311:
1312:            public String createXPDLValidationErrorsString(List existingErrors) {
1313:                String str = "<html>";
1314:                for (int i = 0; i < existingErrors.size(); i++) {
1315:                    XMLValidationError verr = (XMLValidationError) existingErrors
1316:                            .get(i);
1317:
1318:                    String retVal = "";
1319:                    XMLElement el = verr.getElement();
1320:                    if (el != null) {
1321:
1322:                        retVal += "Type=" + verr.getType();
1323:                        retVal += ", Sub-Type=" + verr.getSubType();
1324:                        retVal += ", Location="
1325:                                + getLocString(getLocation(el), el) + ": ";
1326:                        retVal += "<br>";
1327:                        String err = ResourceManager
1328:                                .getLanguageDependentString(verr.getId());
1329:                        if (err == null) {
1330:                            err = verr.getId();
1331:                        }
1332:                        retVal += err;
1333:                        if (verr.getDescription() != null
1334:                                && verr.getDescription().length() > 0)
1335:                            retVal += ": " + verr.getDescription();
1336:                    }
1337:
1338:                    str = str + retVal + "<br><br>";
1339:                }
1340:                str += "</html>";
1341:                return str;
1342:            }
1343:
1344:            protected XMLElement getLocation(XMLElement el) {
1345:                XMLElement location = XMLUtil.getActivity(el);
1346:                if (location == null) {
1347:                    location = XMLUtil.getTransition(el);
1348:                }
1349:                if (location == null) {
1350:                    location = XMLUtil.getTransition(el);
1351:                }
1352:                if (location == null) {
1353:                    location = XMLUtil.getParentElement(TypeDeclaration.class,
1354:                            el);
1355:                }
1356:                if (location == null) {
1357:                    location = XMLUtil.getParentElement(FormalParameter.class,
1358:                            el);
1359:                }
1360:                if (location == null) {
1361:                    location = XMLUtil.getParentElement(Application.class, el);
1362:                }
1363:                if (location == null) {
1364:                    location = XMLUtil.getParentElement(Participant.class, el);
1365:                }
1366:                if (location == null) {
1367:                    location = XMLUtil.getParentElement(DataField.class, el);
1368:                }
1369:                ActivitySet as = XMLUtil.getActivitySet(el);
1370:                if (location == null) {
1371:                    location = as;
1372:                }
1373:                WorkflowProcess wp = XMLUtil.getWorkflowProcess(el);
1374:                if (location == null) {
1375:                    location = wp;
1376:                }
1377:                Package pkg = XMLUtil.getPackage(el);
1378:                if (location == null) {
1379:                    location = pkg;
1380:                }
1381:                return location;
1382:            }
1383:
1384:            protected String getLocString(XMLElement location, XMLElement el) {
1385:                ActivitySet as = XMLUtil.getActivitySet(el);
1386:                WorkflowProcess wp = XMLUtil.getWorkflowProcess(el);
1387:                Package pkg = XMLUtil.getPackage(el);
1388:
1389:                String loc = "Package" + " '" + pkg.getId() + "'";
1390:                if (wp != null) {
1391:                    loc += ", " + "WorkflowProcess" + " '" + wp.getId() + "'";
1392:                }
1393:                if (as != null) {
1394:                    loc += ", " + "ActivitySet" + " '" + as.getId() + "'";
1395:                }
1396:                if (location != as && location != wp && location != pkg) {
1397:                    loc += ", "
1398:                            + location.toName()
1399:                            + " '"
1400:                            + ((XMLComplexElement) location).get("Id")
1401:                                    .toValue() + "'";
1402:                }
1403:                if (el != location && el != as && el != wp && el != pkg) {
1404:                    XMLComplexElement sbflwOrTool = null;
1405:                    if (el instanceof  ActualParameter) {
1406:                        sbflwOrTool = (XMLComplexElement) el.getParent()
1407:                                .getParent();
1408:                    } else if (el instanceof  ActualParameters) {
1409:                        sbflwOrTool = (XMLComplexElement) el.getParent();
1410:                    }
1411:                    if (sbflwOrTool != null) {
1412:                        loc += ", " + sbflwOrTool.toName() + " '"
1413:                                + sbflwOrTool.get("Id").toValue() + "'";
1414:                    }
1415:                    loc += " -> " + el.toName();
1416:
1417:                }
1418:
1419:                return loc;
1420:            }
1421:
1422:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.