Source Code Cross Referenced for FlatFileFactory.java in  » Workflow-Engines » pegasus-2.1.0 » org » griphyn » vdl » euryale » 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 » pegasus 2.1.0 » org.griphyn.vdl.euryale 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file or a portion of this file is licensed under the terms of
003:         * the Globus Toolkit Public License, found in file ../GTPL, or at
004:         * http://www.globus.org/toolkit/download/license.html. This notice must
005:         * appear in redistributions of this file, with or without modification.
006:         *
007:         * Redistributions of this Software, with or without modification, must
008:         * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009:         * some other similar material which is provided with the Software (if
010:         * any).
011:         *
012:         * Copyright 1999-2004 University of Chicago and The University of
013:         * Southern California. All rights reserved.
014:         */
015:        package org.griphyn.vdl.euryale;
016:
017:        import org.griphyn.common.util.Separator;
018:        import org.griphyn.common.util.Currently;
019:        import java.io.*;
020:        import java.util.*;
021:
022:        /**
023:         * This file factory generates a stream of submit files within the same
024:         * toplevel directory. There is no subdirectory structuring.
025:         *
026:         * @author Kavitha Ranganathan
027:         * @author Jens-S. Vöckler
028:         * @author Yong Zhao
029:         * @version $Revision: 289 $
030:         *
031:         * @see DAX2DAG
032:         */
033:        public class FlatFileFactory implements  FileFactory {
034:            /**
035:             * Contains the base directory where to store all files into.
036:             */
037:            private File m_directory;
038:
039:            /**
040:             * Counts the number of times the virtual constructor was called.
041:             */
042:            private int m_count;
043:
044:            /**
045:             * Helping structure to avoid repeated memory requests. Stores the
046:             * path string of the base directory for later perusal.
047:             * @see #getBaseDirectory()
048:             */
049:            private String mh_directory;
050:
051:            /**
052:             * Resets the helper structures after changing layout parameters. You
053:             * will also need to call this function after you invoked the virtual
054:             * constructors, but want to change parameter pertaining to the
055:             * directory structure. The structured file count will also be reset!
056:             */
057:            public void reset() {
058:                m_count = 0;
059:                mh_directory = m_directory.getPath();
060:            }
061:
062:            /**
063:             * Constructor: Creates the directory and employs sanity checks.
064:             * @param directory is the place where files should be placed.
065:             * @throws IOException if the location is not a writable directory,
066:             * or cannot be created as such.
067:             */
068:            public FlatFileFactory(File directory) throws IOException {
069:                sanityCheck(directory);
070:                m_directory = directory;
071:                m_count = 0;
072:                mh_directory = m_directory.getPath();
073:            }
074:
075:            /**
076:             * Constructor: Creates the directory and employs sanity checks.
077:             * @param directory is the place where files should be placed.
078:             * @throws IOException if the location is not a writable directory,
079:             * or cannot be created as such.
080:             */
081:            public FlatFileFactory(String directory) throws IOException {
082:                File base = new File(directory);
083:                sanityCheck(base);
084:                m_directory = base;
085:                m_count = 0;
086:                mh_directory = m_directory.getPath();
087:            }
088:
089:            /**
090:             * Virtual constructor: Creates the next file with the given basename.
091:             * @param basename is the filename to create. Don't specify dirs here.
092:             * @return a File structure which points to the new file. Nothing is
093:             * created through this method, and creation may still fail.
094:             * @see #getCount()
095:             */
096:            public File createFile(String basename) throws IOException {
097:                return createFlatFile(basename);
098:            }
099:
100:            /**
101:             * Virtual constructor: Creates the next file with the given basename.
102:             * @param basename is the filename to create. Don't specify dirs here.
103:             * @return a File structure which points to the new file. Nothing is
104:             * created through this method, and creation may still fail.
105:             * @see #getCount()
106:             */
107:            public File createFlatFile(String basename) throws IOException {
108:                m_count++;
109:                return new File(m_directory, basename);
110:            }
111:
112:            /**
113:             * Returns the number of times the virtual constructor for structured
114:             * files was called. Since this is a flat file class, it will be 0.
115:             * @return the count for createFile invocations.
116:             * @see #createFile( String )
117:             */
118:            public int getCount() {
119:                return 0;
120:            }
121:
122:            /**
123:             * Returns the number of times the virtual constructor was called.
124:             * @return the count for createFile invocations.
125:             * @see #createFile( String )
126:             */
127:            public int getFlatCount() {
128:                return m_count;
129:            }
130:
131:            /**
132:             * Returns base directory. We want to be on the safe side.
133:             * @return the directory passed to the constructor.
134:             * @see #setBaseDirectory( File )
135:             */
136:            public File getBaseDirectory() {
137:                return m_directory;
138:            }
139:
140:            /**
141:             * Checks the destination location for existence, if it can
142:             * be created, if it is writable etc.
143:             * @param dir is the new base directory to optionally create
144:             */
145:            protected void sanityCheck(File dir) throws IOException {
146:                if (dir.exists()) {
147:                    // location exists
148:                    if (dir.isDirectory()) {
149:                        // ok, isa directory
150:                        if (dir.canWrite()) {
151:                            // can write, all is well
152:                            return;
153:                        } else {
154:                            // all is there, but I cannot write to dir
155:                            throw new IOException(
156:                                    "Cannot write to existing directory "
157:                                            + dir.getPath());
158:                        }
159:                    } else {
160:                        // exists but not a directory
161:                        throw new IOException("Destination " + dir.getPath()
162:                                + " already "
163:                                + "exists, but is not a directory.");
164:                    }
165:                } else {
166:                    // does not exist, try to make it
167:                    if (!dir.mkdirs()) {
168:                        throw new IOException(
169:                                "Unable to create directory destination "
170:                                        + dir.getPath());
171:                    }
172:                }
173:            }
174:
175:            /**
176:             * Accessor to set a different base directory. Note that this accessor
177:             * may only be called before any of the virtual constructors were
178:             * invoked the first time.
179:             * @param base is the new directory to set things to
180:             * @throws VTorInUseException if the virtual constructor is already in use.
181:             * @throws IOException if there is something wrong with the directory
182:             * @see #getBaseDirectory()
183:             * @see #reset()
184:             */
185:            public void setBaseDirectory(File base) throws IOException,
186:                    VTorInUseException {
187:                if (m_count != 0)
188:                    throw new VTorInUseException();
189:                sanityCheck(base);
190:                m_directory = base;
191:                reset(); // will invoke _virtual_ reset :-)
192:            }
193:
194:            /**
195:             * Constructs a virtual basename by removing the directory from a
196:             * given file. If the file's directory does not match our stored
197:             * directory prefix, nothing will be removed. This method is essential
198:             * in order to assemble relative pathnames to the base directory.
199:             *
200:             * @param file is an arbitrary file, should have been constructed using
201:             * the virtual constructor.
202:             * @return a relative pathname with the base directory removed. Note
203:             * that may will still contain directories. In case of an arbitrary
204:             * file, the full filename may be returned.
205:             */
206:            public String getName(File file) {
207:                String path = file.getPath();
208:                if (path.startsWith(mh_directory)) {
209:                    // yes, one of ours
210:                    return path.substring(mh_directory.length() + 1);
211:                } else {
212:                    // eek, an alien
213:                    return path;
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.