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


001:        package org.enhydra.shark.admin.repositorymanagement;
002:
003:        import java.io.File;
004:        import java.io.FileFilter;
005:        import java.io.FileOutputStream;
006:        import java.util.ArrayList;
007:        import java.util.Collection;
008:        import java.util.Collections;
009:        import java.util.Iterator;
010:        import java.util.List;
011:        import java.util.Map;
012:
013:        import org.enhydra.shark.api.admin.RepositoryMgr;
014:        import org.enhydra.shark.utilities.MiscUtilities;
015:        import org.enhydra.shark.utilities.SequencedHashMap;
016:        import org.enhydra.shark.xpdl.XMLUtil;
017:
018:        /**
019:         * @author Nenad Stefanovic, Sasa Bojanic
020:         */
021:        public class RepositoryManager implements  RepositoryMgr {
022:            private static PackageFileFilter packageFileFilter = new PackageFileFilter();
023:            private static ArisxmlFileFilterAris arisxmlFileFilter = new ArisxmlFileFilterAris();
024:
025:            private static RepositoryMgr anInstance;
026:
027:            private static String EXTERNAL_PACKAGES_REPOSITORY = "repository/external";
028:
029:            private RepositoryManager() {
030:            }
031:
032:            public static RepositoryMgr getInstance() {
033:                if (null == anInstance) {
034:                    synchronized (RepositoryManager.class) {
035:                        if (null == anInstance) {
036:                            anInstance = new RepositoryManager();
037:                            try {
038:                                anInstance
039:                                        .setPathToXPDLRepositoryFolder(EXTERNAL_PACKAGES_REPOSITORY);
040:                            } catch (Exception ex) {
041:                            }
042:                        }
043:                    }
044:                }
045:                return anInstance;
046:            }
047:
048:            public void setPathToXPDLRepositoryFolder(String xpdlRepFolder)
049:                    throws Exception {
050:                RepositoryManager.EXTERNAL_PACKAGES_REPOSITORY = xpdlRepFolder;
051:                File f = new File(xpdlRepFolder);
052:                if (!f.isAbsolute()) {
053:                    f = f.getAbsoluteFile();
054:                }
055:
056:                if (!f.exists()) {
057:                    throw new Exception("Folder " + xpdlRepFolder
058:                            + " does not exist");
059:                }
060:                try {
061:                    EXTERNAL_PACKAGES_REPOSITORY = f.getCanonicalPath();
062:                } catch (Exception ex) {
063:                    EXTERNAL_PACKAGES_REPOSITORY = f.getAbsolutePath();
064:                }
065:            }
066:
067:            public String getPathToXPDLRepositoryFolder() throws Exception {
068:                return EXTERNAL_PACKAGES_REPOSITORY;
069:            }
070:
071:            public void deletePackage(String relativePath) throws Exception {
072:                String path = EXTERNAL_PACKAGES_REPOSITORY + File.separator
073:                        + relativePath;
074:                File pkgFile = new File(path);
075:                if (!pkgFile.exists() || pkgFile.isDirectory()) {
076:                    System.err
077:                            .println("RepositoryManager -> deleting of the file "
078:                                    + path
079:                                    + " failed because it does not exist, or it is a directory");
080:                    throw new Exception(
081:                            "RepositoryManager -> deleting of the file "
082:                                    + path
083:                                    + " failed because it does not exist, or it is a directory");
084:                }
085:                boolean isDeleted = false;
086:                try {
087:                    isDeleted = pkgFile.delete();
088:                } catch (Exception ex) {
089:                    System.err
090:                            .println("RepositoryManager -> deleting of the file "
091:                                    + path + " failed - it might be locked");
092:                    throw new Exception(
093:                            "RepositoryManager -> deleting of the file " + path
094:                                    + " failed - it might be locked");
095:                }
096:                if (!isDeleted) {
097:                    throw new Exception(
098:                            "RepositoryManager -> deleting of the file " + path
099:                                    + " NOT deleted");
100:                }
101:                System.out.println("RepositoryManager -> file " + path
102:                        + " is successfully deleted from repository");
103:
104:            }
105:
106:            public void uploadPackage(byte[] pkgContent, String relativePath)
107:                    throws Exception {
108:                String path = EXTERNAL_PACKAGES_REPOSITORY + File.separator
109:                        + relativePath;
110:                File pkgFile = new File(path);
111:                File parentFile = pkgFile.getParentFile();
112:                // if the file exists, or the parent file exists and it is not directory -> can't
113:                // create
114:                if (pkgFile.exists()
115:                        || (parentFile.exists() && !parentFile.isDirectory())) {
116:                    System.err
117:                            .println("RepositoryManager -> upload of the file "
118:                                    + path
119:                                    + " failed because it already exists or its parent is not directory");
120:                    throw new Exception(
121:                            "RepositoryManager -> upload of the file "
122:                                    + path
123:                                    + " failed because it already exists or its parent is not directory");
124:                }
125:
126:                if (!parentFile.exists()) {
127:                    parentFile.mkdirs();
128:                }
129:
130:                try {
131:                    FileOutputStream fos = new FileOutputStream(pkgFile);
132:                    fos.write(pkgContent);
133:                    // Write to file
134:                    fos.flush();
135:                    fos.close();
136:                } catch (Exception ex) {
137:                    System.err
138:                            .println("RepositoryManager -> upload of the file "
139:                                    + path + " failed");
140:                    throw ex;
141:                }
142:
143:                System.out.println("RepositoryManager -> file " + path
144:                        + " is successfully uploaded into repository");
145:            }
146:
147:            public String[] getPackagePaths() throws Exception {
148:                List packageFiles = getDefinedPackageFiles(EXTERNAL_PACKAGES_REPOSITORY);
149:                Collection pfls = new ArrayList();
150:                Iterator pfi = packageFiles.iterator();
151:                Collections.sort(packageFiles);
152:                while (pfi.hasNext()) {
153:                    File f = (File) pfi.next();
154:                    String fileName;
155:                    try {
156:                        fileName = f.getCanonicalPath();
157:                    } catch (Exception ex) {
158:                        fileName = f.getAbsolutePath();
159:                    }
160:                    fileName = fileName.substring(EXTERNAL_PACKAGES_REPOSITORY
161:                            .length() + 1);
162:                    pfls.add(fileName);
163:                }
164:                String[] pfs = new String[pfls.size()];
165:                pfls.toArray(pfs);
166:                return pfs;
167:            }
168:
169:            public String[] getArisxmlPaths() throws Exception {
170:                List arisxmlFiles = getDefinedArisXmlFiles(EXTERNAL_PACKAGES_REPOSITORY);
171:                Collection pfls = new ArrayList();
172:                Iterator pfi = arisxmlFiles.iterator();
173:                Collections.sort(arisxmlFiles);
174:                while (pfi.hasNext()) {
175:                    File f = (File) pfi.next();
176:                    String fileName;
177:                    try {
178:                        fileName = f.getCanonicalPath();
179:                    } catch (Exception ex) {
180:                        fileName = f.getAbsolutePath();
181:                    }
182:                    fileName = fileName.substring(EXTERNAL_PACKAGES_REPOSITORY
183:                            .length() + 1);
184:                    pfls.add(fileName);
185:                }
186:                String[] pfs = new String[pfls.size()];
187:                pfls.toArray(pfs);
188:                return pfs;
189:            }
190:
191:            public Map getPackagePathToIdMapping() throws Exception {
192:                List packageFiles = getDefinedPackageFiles(EXTERNAL_PACKAGES_REPOSITORY);
193:                Map m = new SequencedHashMap();
194:                Iterator pfi = packageFiles.iterator();
195:                Collections.sort(packageFiles);
196:                while (pfi.hasNext()) {
197:                    File f = (File) pfi.next();
198:                    String fileName;
199:                    try {
200:                        fileName = f.getCanonicalPath();
201:                    } catch (Exception ex) {
202:                        fileName = f.getAbsolutePath();
203:                    }
204:                    String pkgId = XMLUtil.getIdFromFile(fileName);
205:                    if (pkgId != null && pkgId.length() > 0) {
206:                        fileName = fileName
207:                                .substring(EXTERNAL_PACKAGES_REPOSITORY
208:                                        .length() + 1);
209:                        m.put(fileName, pkgId);
210:                    }
211:                }
212:                return m;
213:            }
214:
215:            public String getPackageId(String relativePath) throws Exception {
216:                relativePath = XMLUtil.convertToSystemPath(relativePath);
217:                List packageFiles = getDefinedPackageFiles(EXTERNAL_PACKAGES_REPOSITORY);
218:                Iterator pfi = packageFiles.iterator();
219:                while (pfi.hasNext()) {
220:                    File f = (File) pfi.next();
221:                    String fileName;
222:                    try {
223:                        fileName = f.getCanonicalPath();
224:                    } catch (Exception ex) {
225:                        fileName = f.getAbsolutePath();
226:                    }
227:                    String relFileName = fileName
228:                            .substring(EXTERNAL_PACKAGES_REPOSITORY.length() + 1);
229:                    if (relFileName.equals(relativePath)) {
230:                        return XMLUtil.getIdFromFile(fileName);
231:                    }
232:                }
233:                return null;
234:            }
235:
236:            static List getDefinedPackageFiles(String repository) {
237:                File startingFolder = new File(repository);
238:                List packageFiles = new ArrayList();
239:                if (!startingFolder.exists()) {
240:                    System.out.println("RepositoryManager -> Repository "
241:                            + startingFolder + " doesn't exist");
242:                }
243:                MiscUtilities.traverse(startingFolder, packageFiles,
244:                        packageFileFilter);
245:                //      packageFiles = Arrays.asList(startingFolder.listFiles(packageFileFilter));
246:
247:                return packageFiles;
248:            }
249:
250:            static List getDefinedArisXmlFiles(String repository) {
251:                File startingFolder = new File(repository);
252:                List packageFiles = new ArrayList();
253:                if (!startingFolder.exists()) {
254:                    System.out.println("RepositoryManager -> Repository "
255:                            + startingFolder + " doesn't exist");
256:                }
257:                MiscUtilities.traverse(startingFolder, packageFiles,
258:                        arisxmlFileFilter);
259:                //      packageFiles = Arrays.asList(startingFolder.listFiles(packageFileFilter));
260:
261:                return packageFiles;
262:            }
263:
264:        }
265:
266:        class PackageFileFilter implements  FileFilter {
267:            public boolean accept(File pathname) {
268:                return pathname.isDirectory()
269:                        || pathname.getName().endsWith(".xpdl");
270:            }
271:        }
272:
273:        class ArisxmlFileFilterAris implements  FileFilter {
274:            public boolean accept(File pathname) {
275:                return pathname.isDirectory()
276:                        || pathname.getName().endsWith(".aml");
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.