Source Code Cross Referenced for BaseVirtualFileSystemHolder.java in  » Workflow-Engines » JFolder » org » jfolder » common » files » 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 » JFolder » org.jfolder.common.files 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JFolder, Copyright 2001-2006 Gary Steinmetz
003:         *
004:         * Distributable under LGPL license.
005:         * See terms of license at gnu.org.
006:         */
007:
008:        package org.jfolder.common.files;
009:
010:        //base classes
011:        import java.io.ByteArrayOutputStream;
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.io.InputStream;
015:        import java.sql.Date;
016:        import java.util.ArrayList;
017:        import java.util.Collections;
018:        import java.util.HashMap;
019:        import java.util.Iterator;
020:        import java.util.StringTokenizer;
021:        import java.util.zip.ZipEntry;
022:        import java.util.zip.ZipInputStream;
023:        import java.util.zip.ZipOutputStream;
024:
025:        //project specific classes
026:        import org.jfolder.common.UnexpectedSystemException;
027:        import org.jfolder.common.utils.misc.MiscHelper;
028:
029:        //other classes
030:
031:        public abstract class BaseVirtualFileSystemHolder implements 
032:                VirtualFileSystemHolder {
033:
034:            private final static long ZIP_TIME = Date.valueOf("2001-01-01")
035:                    .getTime();
036:
037:            protected BaseVirtualFileSystemHolder() {
038:            }
039:
040:            //
041:            protected abstract HashMap getLocalFilesAsHashMap();
042:
043:            protected abstract HashMap getLocalDirectoriesAsHashMap();
044:
045:            //
046:            protected abstract VirtualFileSystemFile createLocalFile(
047:                    String inName, byte inContent[]);
048:
049:            protected abstract VirtualFileSystemFile updateLocalFile(
050:                    String inName, byte inContent[]);
051:
052:            protected abstract void deleteLocalFile(String inName);
053:
054:            //
055:            protected abstract VirtualFileSystemDirectory createLocalDirectory(
056:                    String inName);
057:
058:            protected abstract void deleteLocalDirectory(String inName);
059:
060:            protected abstract boolean isRemovePropogateActive();
061:
062:            //
063:            public VirtualFileSystemDirectory copyDirectory(String inSource,
064:                    String inDestination) {
065:
066:                VirtualFileSystemDirectory outValue = null;
067:
068:                if (isFilePresent(inSource)) {
069:                    throw new UnexpectedSystemException("Directory '"
070:                            + inSource
071:                            + "' is actually the name of an existing file");
072:                }
073:                if (!isDirectoryPresent(inSource)) {
074:                    throw new UnexpectedSystemException("Directory '"
075:                            + inSource + "' does not exist");
076:                } else if (isFilePresent(inDestination)) {
077:                    throw new UnexpectedSystemException("Directory '"
078:                            + inDestination
079:                            + "' is actually the name of an existing file");
080:                } else if (isDirectoryPresent(inDestination)) {
081:                    throw new UnexpectedSystemException("Directory '"
082:                            + inDestination
083:                            + "' is actually the name of an existing directory");
084:                } else if (!isDirectoryNameValid(inDestination)) {
085:                    throw new UnexpectedSystemException(
086:                            "Proposed directory name '" + inDestination
087:                                    + "' is not valid");
088:                } else {
089:
090:                    outValue = createDirectory(inDestination);
091:                    VirtualFileSystemDirectory sourceVsd = getDirectory(inSource);
092:                    copyDirectory(sourceVsd, outValue);
093:                }
094:
095:                return outValue;
096:            }
097:
098:            public final static void copyDirectory(
099:                    VirtualFileSystemHolder inSource,
100:                    VirtualFileSystemHolder inDestination) {
101:
102:                ArrayList subDirNames = inSource.getLocalDirectories();
103:                for (int i = 0; i < subDirNames.size(); i++) {
104:                    //String nextSubDirName = (String)subDirNames.get(i);
105:                    VirtualFileSystemDirectory nextSourceSubDir = (VirtualFileSystemDirectory) subDirNames
106:                            .get(i);
107:                    VirtualFileSystemDirectory nextDestinationSubDir = inDestination
108:                            .createDirectory(nextSourceSubDir.getName());
109:                    //
110:                    copyDirectory(nextSourceSubDir, nextDestinationSubDir);
111:                }
112:
113:                ArrayList subFileNames = inSource.getLocalFiles();
114:                for (int i = 0; i < subFileNames.size(); i++) {
115:                    //MiscHelper.println(
116:                    //    "BasVirSysHol nextSubFileName = " + subFileNames.get(i));
117:                    //String nextSubFileName = (String)subFileNames.get(i);
118:                    //VirtualSystemFile nextSubFile = inSource.getFile(nextSubFileName);
119:                    VirtualFileSystemFile nextSubFile = (VirtualFileSystemFile) subFileNames
120:                            .get(i);
121:                    inDestination.createFile(nextSubFile.getName(), nextSubFile
122:                            .getContent());
123:                }
124:            }
125:
126:            //
127:            public boolean isDirectoryOrFilePresent(String inName) {
128:
129:                boolean outValue = false;
130:
131:                outValue = (isDirectoryPresent(inName) || (isFilePresent(inName)));
132:
133:                return outValue;
134:            }
135:
136:            //utility functions
137:            //
138:            public final static boolean isFileNameValid(String inName) {
139:                return MiscHelper.isRegularExpressionMatch(inName,
140:                        VALID_FILE_NAME, true);
141:            }
142:
143:            public final static boolean isDirectoryPathValid(String inPath) {
144:
145:                boolean outValue = true;
146:
147:                ArrayList dirList = parseDirectoryName(inPath);
148:                for (int i = 0; i < dirList.size(); i++) {
149:                    String nextPathPart = (String) dirList.get(i);
150:                    outValue &= isDirectoryNameValid(nextPathPart);
151:                }
152:
153:                return outValue;
154:            }
155:
156:            public final static boolean isDirectoryNameValid(String inName) {
157:                return MiscHelper.isRegularExpressionMatch(inName,
158:                        VALID_DIRECTORY_NAME, true);
159:            }
160:
161:            //
162:            protected final static ArrayList getSortedComponents(
163:                    HashMap inComponents) {
164:
165:                ArrayList outValue = new ArrayList();
166:
167:                //
168:                Iterator namesIter = inComponents.keySet().iterator();
169:                ArrayList namesList = new ArrayList();
170:                while (namesIter.hasNext()) {
171:                    namesList.add(namesIter.next());
172:                }
173:                Collections.sort(namesList);
174:
175:                //
176:                for (int i = 0; i < namesList.size(); i++) {
177:                    outValue.add(inComponents.get(namesList.get(i)));
178:                }
179:
180:                return outValue;
181:            }
182:
183:            protected final static VirtualFileSystemHolder getOrCreateDir(
184:                    ArrayList inDir, int inIndex, VirtualFileSystemHolder inBase) {
185:
186:                VirtualFileSystemHolder outValue = null;
187:
188:                if (inIndex < inDir.size()) {
189:                    String nextSubDir = (String) inDir.get(inIndex);
190:                    VirtualFileSystemDirectory nextFsd = inBase
191:                            .getOrCreateLocalDirectory(nextSubDir);
192:
193:                    outValue = getOrCreateDir(inDir, inIndex + 1, nextFsd);
194:                } else {
195:                    outValue = inBase;
196:                }
197:
198:                return outValue;
199:            }
200:
201:            protected final static void parseZipInfo(InputStream inIs,
202:                    VirtualFileSystemHolder inRootFsh) throws IOException {
203:
204:                ZipInputStream zis = new ZipInputStream(inIs);
205:
206:                ZipEntry nextEntry = null;
207:
208:                while ((nextEntry = zis.getNextEntry()) != null) {
209:
210:                    ArrayList nextEntryParts = getNameParts(nextEntry.getName());
211:
212:                    if (nextEntry.isDirectory()) {
213:
214:                        //createDir(nextEntryFile);
215:                        getOrCreateDir(nextEntryParts, 0, inRootFsh);
216:                    } else {
217:
218:                        String fileName = (String) nextEntryParts
219:                                .get(nextEntryParts.size() - 1);
220:                        nextEntryParts.remove(nextEntryParts.size() - 1);
221:                        VirtualFileSystemHolder fileDir = getOrCreateDir(
222:                                nextEntryParts, 0, inRootFsh);
223:
224:                        //
225:                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
226:                        //
227:                        byte buffer[] = new byte[1024];
228:                        int len = 0;
229:                        while ((len = zis.read(buffer, 0, buffer.length)) != -1) {
230:                            baos.write(buffer, 0, len);
231:                        }
232:                        baos.flush();
233:                        baos.close();
234:                        //
235:                        byte content[] = baos.toByteArray();
236:
237:                        //
238:                        fileDir.createFile(fileName, content);
239:                    }
240:                    //MiscHelper.println(nextEntry.getName());
241:                    zis.closeEntry();
242:                }
243:
244:                zis.close();
245:            }
246:
247:            protected final static ArrayList getNameParts(String inName) {
248:
249:                ArrayList outValue = new ArrayList();
250:
251:                inName = inName.replace(File.separatorChar,
252:                        DIRECTORY_SEPARATOR_CHAR);
253:
254:                //
255:                while (inName.endsWith(DIRECTORY_SEPARATOR)) {
256:                    inName = inName.substring(0, inName.length()
257:                            - DIRECTORY_SEPARATOR.length());
258:                }
259:
260:                //
261:                while (inName.startsWith(DIRECTORY_SEPARATOR)) {
262:                    inName = inName.substring(DIRECTORY_SEPARATOR.length(),
263:                            inName.length());
264:                }
265:
266:                //
267:                StringTokenizer st = new StringTokenizer(inName,
268:                        DIRECTORY_SEPARATOR);
269:                while (st.hasMoreTokens()) {
270:                    String nextToken = st.nextToken();
271:                    outValue.add(nextToken);
272:                }
273:
274:                return outValue;
275:            }
276:
277:            //
278:            //
279:            //
280:            //
281:            //
282:            //
283:            //
284:            //
285:            //
286:            //
287:            //
288:            public boolean isDirectoryPresent(String inName) {
289:                return getLocalDirectoriesAsHashMap().containsKey(
290:                        inName.toUpperCase());
291:            }
292:
293:            public boolean isFilePresent(String inName) {
294:                return getLocalFilesAsHashMap().containsKey(
295:                        inName.toUpperCase());
296:            }
297:
298:            //
299:            public VirtualFileSystemDirectory getDirectory(String inName) {
300:
301:                VirtualFileSystemDirectory outValue = null;
302:
303:                if (isDirectoryPresent(inName)) {
304:                    Object o = getLocalDirectoriesAsHashMap().get(
305:                            inName.toUpperCase());
306:                    outValue = (VirtualFileSystemDirectory) o;
307:                } else {
308:                    throw new UnexpectedSystemException("Directory '" + inName
309:                            + "' is not present");
310:                }
311:
312:                return outValue;
313:            }
314:
315:            public VirtualFileSystemFile getFile(String inName) {
316:
317:                VirtualFileSystemFile outValue = null;
318:
319:                if (isFilePresent(inName)) {
320:                    outValue = (VirtualFileSystemFile) getLocalFilesAsHashMap()
321:                            .get(inName.toUpperCase());
322:                } else {
323:                    throw new UnexpectedSystemException("File '" + inName
324:                            + "' is not present");
325:                }
326:
327:                return outValue;
328:            }
329:
330:            //
331:            public ArrayList getLocalDirectories() {
332:
333:                ArrayList outValue = null;
334:
335:                //
336:
337:                outValue = getSortedComponents(getLocalDirectoriesAsHashMap());
338:
339:                return outValue;
340:            }
341:
342:            public ArrayList getLocalFiles() {
343:
344:                ArrayList outValue = null;
345:
346:                outValue = getSortedComponents(getLocalFilesAsHashMap());
347:
348:                return outValue;
349:            }
350:
351:            //
352:            private ArrayList removeThisTest = new ArrayList();
353:
354:            public VirtualFileSystemDirectory createDirectory(String inName) {
355:
356:                VirtualFileSystemDirectory outValue = null;
357:
358:                //
359:                if (inName != null//) {//
360:                        //&& inName.equals("0_0")) {
361:                        && inName.equals("Images")) {
362:
363:                    MiscHelper
364:                            .println("BasVirFilSysHol creDir remove Test for 0_0");
365:                    Exception nextException = new UnexpectedSystemException(
366:                            "0_0 already found for " + this );
367:                    this .removeThisTest.add(nextException);
368:
369:                    //if (this.removeThisTest != null) {
370:                    //    MiscHelper.writeMessage(this, this.removeThisTest);
371:                    //    MiscHelper.writeMessage(this, nextException);
372:                    //}
373:                    //else {
374:                    //    this.removeThisTest = nextException;
375:                    //}
376:                }
377:
378:                if (isDirectoryOrFilePresent(inName)) {
379:                    MiscHelper.println("BasVirFilSysHol creDir exeption for = "
380:                            + this );
381:                    for (int i = 0; i < this .removeThisTest.size(); i++) {
382:                        Exception nextE = ((Exception) this .removeThisTest
383:                                .get(i));
384:                        MiscHelper.writeMessage(this , nextE);
385:                    }
386:                    throw new UnexpectedSystemException("'" + inName
387:                            + "' already used by another file or directory");
388:                } else if (!isDirectoryNameValid(inName)) {
389:                    throw new UnexpectedSystemException("'" + inName
390:                            + "' is not a valid directory name");
391:                } else {
392:                    outValue = createLocalDirectory(inName);
393:                    //getLocalDirectoriesAsHashMap().put(
394:                    //    inName.toUpperCase(), outValue);
395:                }
396:
397:                return outValue;
398:            }
399:
400:            public VirtualFileSystemFile getAbsoluteFile(String inName) {
401:
402:                VirtualFileSystemFile outValue = null;
403:
404:                ArrayList path = parseDirectoryName(inName);
405:
406:                String fileName = ((String) path.get(path.size() - 1));
407:                path.remove(path.size() - 1);
408:
409:                VirtualFileSystemHolder vfsh = getOrCreateDir(path, 0, this );
410:                outValue = vfsh.getFile(fileName);
411:
412:                return outValue;
413:            }
414:
415:            public boolean isAbsoluteFilePresent(String inName) {
416:
417:                boolean outValue = false;
418:
419:                ArrayList path = parseDirectoryName(inName);
420:
421:                String fileName = ((String) path.get(path.size() - 1));
422:                path.remove(path.size() - 1);
423:
424:                String dirName = parseDirectoryArray(path);
425:                if (isAbsoluteDirectoryPresent(dirName)) {
426:                    VirtualFileSystemHolder vfsh = getOrCreateAbsoluteDirectory(dirName);
427:                    //
428:                    outValue = vfsh.isFilePresent(fileName);
429:                } else {
430:                    outValue = false;
431:                }
432:
433:                return outValue;
434:            }
435:
436:            public VirtualFileSystemHolder getOrCreateAbsoluteDirectory(
437:                    String inName) {
438:
439:                VirtualFileSystemHolder outValue = null;
440:
441:                ArrayList path = parseDirectoryName(inName);
442:
443:                outValue = getOrCreateDir(path, 0, this );
444:
445:                return outValue;
446:            }
447:
448:            public VirtualFileSystemDirectory getOrCreateLocalDirectory(
449:                    String inName) {
450:
451:                VirtualFileSystemDirectory outValue = null;
452:
453:                if (isFilePresent(inName)) {
454:                    throw new UnexpectedSystemException("'" + inName
455:                            + "' already used by a file, not a directory");
456:                } else if (isDirectoryPresent(inName)) {
457:                    outValue = getDirectory(inName);
458:                } else {
459:                    outValue = createDirectory(inName);
460:                }
461:
462:                return outValue;
463:            }
464:
465:            public VirtualFileSystemFile createFile(String inName,
466:                    byte inContent[]) {
467:
468:                VirtualFileSystemFile outValue = null;
469:
470:                if (isDirectoryOrFilePresent(inName)) {
471:                    throw new UnexpectedSystemException("'" + inName
472:                            + "' already used by another file or directory");
473:                } else if (!isFileNameValid(inName)) {
474:                    throw new UnexpectedSystemException("'" + inName
475:                            + "' is not a valid file name");
476:                } else {
477:                    outValue = createLocalFile(inName, inContent);
478:                    //getLocalFilesAsHashMap().put(inName.toUpperCase(), outValue);
479:                }
480:
481:                return outValue;
482:            }
483:
484:            //
485:            public void removeDirectory(String inName) {
486:                if (inName.equals("Images")) {
487:                    MiscHelper.println("Images Found");
488:                }
489:                if (isDirectoryPresent(inName)) {
490:                    if (isRemovePropogateActive()) {
491:                        VirtualFileSystemDirectory parentVfsd = getDirectory(inName);
492:                        //
493:                        ArrayList localFiles = parentVfsd.getLocalFiles();
494:                        for (int i = 0; i < localFiles.size(); i++) {
495:                            VirtualFileSystemFile subVfsf = (VirtualFileSystemFile) localFiles
496:                                    .get(i);
497:                            parentVfsd.removeFile(subVfsf.getName());
498:                        }
499:                        //
500:                        ArrayList localDirs = parentVfsd.getLocalDirectories();
501:                        for (int i = 0; i < localDirs.size(); i++) {
502:                            VirtualFileSystemDirectory subVfsd = (VirtualFileSystemDirectory) localDirs
503:                                    .get(i);
504:                            parentVfsd.removeDirectory(subVfsd.getName());
505:                            //
506:                            //subVfsd.removeDirectory(subVfsd.getName());
507:                        }
508:                        //
509:                    }
510:                    deleteLocalDirectory(inName);
511:                    //getLocalDirectoriesAsHashMap().remove(inName.toUpperCase());
512:                } else {
513:                    throw new UnexpectedSystemException("'" + inName
514:                            + "' does not exist");
515:                }
516:            }
517:
518:            public void removeFile(String inName) {
519:                if (isFilePresent(inName)) {
520:                    deleteLocalFile(inName);
521:                    //getLocalFilesAsHashMap().remove(inName.toUpperCase());
522:                } else {
523:                    throw new UnexpectedSystemException("'" + inName
524:                            + "' does not exist");
525:                }
526:            }
527:
528:            //
529:            public void updateFile(String inName, byte inContent[]) {
530:                if (isDirectoryPresent(inName)) {
531:                    throw new UnexpectedSystemException("'" + inName
532:                            + "' is a directory, not a file");
533:                } else if (!isDirectoryOrFilePresent(inName)) {
534:                    throw new UnexpectedSystemException("'" + inName
535:                            + "' does not exist");
536:                } else {
537:                    updateLocalFile(inName, inContent);
538:                    //VirtualSystemFile fsf = new VirtualSystemFile(inName, inContent);
539:                    //getLocalFilesAsHashMap().put(inName.toUpperCase(), fsf);
540:                }
541:            }
542:
543:            protected void zip(ZipOutputStream inZos, String inDir)
544:                    throws IOException {
545:
546:                //create directory entry
547:                ZipEntry dirZe = new ZipEntry(inDir);
548:                dirZe.setTime(ZIP_TIME);
549:                inZos.putNextEntry(dirZe);
550:                inZos.closeEntry();
551:
552:                //explore sub directories
553:                ArrayList subDirectories = getLocalDirectories();
554:                for (int i = 0; i < subDirectories.size(); i++) {
555:                    VirtualFileSystemDirectory d = (VirtualFileSystemDirectory) subDirectories
556:                            .get(i);
557:                    ((BaseVirtualFileSystemHolder) d).zip(inZos, inDir
558:                            + d.getName() + DIRECTORY_SEPARATOR);
559:                }
560:
561:                //zip local files
562:                ArrayList files = getLocalFiles();
563:                for (int i = 0; i < files.size(); i++) {
564:                    VirtualFileSystemFile f = (VirtualFileSystemFile) files
565:                            .get(i);
566:                    byte content[] = f.getContent();
567:                    ZipEntry fileZe = new ZipEntry(inDir + f.getName());
568:                    fileZe.setTime(ZIP_TIME);
569:                    inZos.putNextEntry(fileZe);
570:                    inZos.write(content, 0, content.length);
571:                    inZos.closeEntry();
572:                }
573:
574:            }
575:
576:            protected void copyTo(VirtualFileSystemHolder inFsh) {
577:
578:                ArrayList subDirectories = getLocalDirectories();
579:                for (int i = 0; i < subDirectories.size(); i++) {
580:                    VirtualFileSystemDirectory nextFsd = (VirtualFileSystemDirectory) subDirectories
581:                            .get(i);
582:
583:                    VirtualFileSystemDirectory nextCopyFsd = inFsh
584:                            .createDirectory(nextFsd.getName());
585:                    ((BaseVirtualFileSystemHolder) nextFsd).copyTo(nextCopyFsd);
586:                }
587:
588:                ArrayList files = getLocalFiles();
589:                for (int i = 0; i < files.size(); i++) {
590:                    VirtualFileSystemFile nextFsf = (VirtualFileSystemFile) files
591:                            .get(i);
592:                    inFsh.createFile(nextFsf.getName(), nextFsf.getContent());
593:                }
594:            }
595:
596:            //
597:            public int hashCode() {
598:
599:                int outValue = 0;
600:
601:                int fshHashCode[] = new int[1];
602:                fshHashCode[0] = 0;
603:                boolean fshFilePresent[] = new boolean[1];
604:                fshFilePresent[0] = false;
605:
606:                explore(fshHashCode, fshFilePresent);
607:
608:                outValue = fshHashCode[0];
609:
610:                return outValue;
611:            }
612:
613:            public boolean equals(Object inObject) {
614:
615:                boolean outValue = false;
616:
617:                if (inObject != null) {
618:                    Class c1 = this .getClass();
619:                    Class c2 = inObject.getClass();
620:
621:                    if (c1.equals(c2)) {
622:
623:                        outValue = true;
624:
625:                        VirtualFileSystemHolder fsh2 = (VirtualFileSystemHolder) inObject;
626:
627:                        //
628:                        ArrayList subDirectories1 = this .getLocalDirectories();
629:                        ArrayList subDirectories2 = fsh2.getLocalDirectories();
630:                        for (int i = 0; i < subDirectories1.size() && outValue; i++) {
631:                            VirtualFileSystemDirectory fsd1 = (VirtualFileSystemDirectory) subDirectories1
632:                                    .get(i);
633:                            if (fsh2.isDirectoryPresent(fsd1.getName())) {
634:                                VirtualFileSystemDirectory fsd2 = (VirtualFileSystemDirectory) fsd1
635:                                        .getDirectory(fsd1.getName());
636:                                outValue &= fsd1.equals(fsd2);
637:                            } else {
638:                                int fsd1HashCode[] = new int[1];
639:                                fsd1HashCode[0] = 0;
640:                                boolean fsd1FilePresent[] = new boolean[1];
641:                                fsd1FilePresent[0] = false;
642:                                //
643:                                ((BaseVirtualFileSystemHolder) fsd1).explore(
644:                                        fsd1HashCode, fsd1FilePresent);
645:                                outValue &= !fsd1FilePresent[0];
646:                            }
647:                        }
648:                        for (int i = 0; i < subDirectories2.size() && outValue; i++) {
649:                            VirtualFileSystemDirectory fsd2 = (VirtualFileSystemDirectory) subDirectories2
650:                                    .get(i);
651:                            if (this .isDirectoryPresent(fsd2.getName())) {
652:                                //comparison already done above, no need to repeat
653:                            } else {
654:                                int fsd2HashCode[] = new int[1];
655:                                fsd2HashCode[0] = 0;
656:                                boolean fsd2FilePresent[] = new boolean[1];
657:                                fsd2FilePresent[0] = false;
658:                                //
659:                                ((BaseVirtualFileSystemHolder) fsd2).explore(
660:                                        fsd2HashCode, fsd2FilePresent);
661:                                outValue &= !fsd2FilePresent[0];
662:                            }
663:                        }
664:
665:                        //
666:                        ArrayList files1 = this .getLocalFiles();
667:                        ArrayList files2 = fsh2.getLocalFiles();
668:                        for (int i = 0; i < files1.size() && outValue; i++) {
669:                            VirtualFileSystemFile fsf1 = (VirtualFileSystemFile) files1
670:                                    .get(i);
671:                            if (fsh2.isFilePresent(fsf1.getName())) {
672:                                VirtualFileSystemFile fsf2 = fsh2.getFile(fsf1
673:                                        .getName());
674:                                outValue &= fsf1.equals(fsf2);
675:                            } else {
676:                                outValue = false;
677:                            }
678:                        }
679:                        for (int i = 0; i < files2.size() && outValue; i++) {
680:                            VirtualFileSystemFile fsf2 = (VirtualFileSystemFile) files2
681:                                    .get(i);
682:                            if (fsh2.isFilePresent(fsf2.getName())) {
683:                                //comparison already done above, no need to repeat
684:                            } else {
685:                                outValue = false;
686:                            }
687:                        }
688:                    } else {
689:                        outValue = false;
690:                    }
691:                }
692:
693:                return outValue;
694:            }
695:
696:            protected void explore(int inHashCode[], boolean inFilePresent[]) {
697:
698:                ArrayList subDirectories = getLocalDirectories();
699:                for (int i = 0; i < subDirectories.size(); i++) {
700:                    BaseVirtualFileSystemHolder fsd = (BaseVirtualFileSystemHolder) subDirectories
701:                            .get(i);
702:                    fsd.explore(inHashCode, inFilePresent);
703:                }
704:
705:                ArrayList files = getLocalFiles();
706:                for (int i = 0; i < files.size(); i++) {
707:                    VirtualFileSystemFile fsf = (VirtualFileSystemFile) files
708:                            .get(i);
709:                    inFilePresent[0] = true;
710:                    inHashCode[0] = inHashCode[0] + fsf.hashCode();
711:                }
712:            }
713:
714:            //
715:            public final static ArrayList parseDirectoryName(String inDir) {
716:
717:                ArrayList outValue = new ArrayList();
718:
719:                //
720:                if (inDir.startsWith(DIRECTORY_SEPARATOR)) {
721:                    inDir = inDir.substring(DIRECTORY_SEPARATOR.length());
722:                }
723:                //
724:                if (inDir.endsWith(DIRECTORY_SEPARATOR)) {
725:                    inDir = inDir.substring(0, inDir.length()
726:                            - DIRECTORY_SEPARATOR.length());
727:                }
728:
729:                StringTokenizer st = new StringTokenizer(inDir,
730:                        DIRECTORY_SEPARATOR);
731:                while (st.hasMoreTokens()) {
732:                    outValue.add(st.nextToken());
733:                }
734:
735:                return outValue;
736:            }
737:
738:            //
739:            public final static String parseDirectoryArray(ArrayList inDir) {
740:
741:                StringBuffer outValue = new StringBuffer();
742:
743:                outValue.append(DIRECTORY_SEPARATOR);
744:                for (int i = 0; i < inDir.size(); i++) {
745:                    outValue.append(inDir.get(i));
746:                    outValue.append(DIRECTORY_SEPARATOR);
747:                }
748:
749:                return outValue.toString();
750:            }
751:
752:            public boolean isFileBlockingAbsoluteDirectory(String inName) {
753:
754:                boolean outValue = false;
755:
756:                ArrayList dir = parseDirectoryName(inName);
757:                outValue = !isFileNotBlockingAbsoluteDirectory(dir, 0, this );
758:
759:                return outValue;
760:            }
761:
762:            private final static boolean isFileNotBlockingAbsoluteDirectory(
763:                    ArrayList inDir, int inIndex, VirtualFileSystemHolder inVsh) {
764:
765:                boolean outValue = false;
766:
767:                if (inIndex >= inDir.size()) {
768:                    outValue = true;
769:                } else {
770:                    String subDir = (String) inDir.get(inIndex);
771:                    if (inVsh.isFilePresent(subDir)) {
772:                        outValue = false;
773:                    } else if (inVsh.isDirectoryPresent(subDir)) {
774:                        VirtualFileSystemDirectory nextDir = inVsh
775:                                .getDirectory(subDir);
776:                        outValue = isAbsoluteDirectoryPresent(inDir,
777:                                inIndex + 1, nextDir);
778:                    } else {
779:                        outValue = true;
780:                    }
781:                }
782:
783:                return outValue;
784:            }
785:
786:            public boolean isAbsoluteDirectoryPresent(String inName) {
787:
788:                boolean outValue = false;
789:
790:                ArrayList dir = parseDirectoryName(inName);
791:                outValue = isAbsoluteDirectoryPresent(dir, 0, this );
792:
793:                return outValue;
794:            }
795:
796:            private final static boolean isAbsoluteDirectoryPresent(
797:                    ArrayList inDir, int inIndex, VirtualFileSystemHolder inVsh) {
798:
799:                boolean outValue = false;
800:
801:                if (inIndex >= inDir.size()) {
802:                    outValue = true;
803:                } else {
804:                    String subDir = (String) inDir.get(inIndex);
805:                    if (inVsh.isDirectoryPresent(subDir)) {
806:                        VirtualFileSystemDirectory nextDir = inVsh
807:                                .getDirectory(subDir);
808:                        outValue = isAbsoluteDirectoryPresent(inDir,
809:                                inIndex + 1, nextDir);
810:                    } else {
811:                        outValue = false;
812:                    }
813:                }
814:
815:                return outValue;
816:            }
817:
818:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.