Source Code Cross Referenced for PoolMode.java in  » Workflow-Engines » pegasus-2.1.0 » org » griphyn » cPlanner » poolinfo » 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.cPlanner.poolinfo 
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 at $PEGASUS_HOME/GTPL or
004:         * http://www.globus.org/toolkit/download/license.html.
005:         * This notice must appear in redistributions of this file
006:         * with or without modification.
007:         *
008:         * Redistributions of this Software, with or without modification, must reproduce
009:         * the GTPL in:
010:         * (1) the Software, or
011:         * (2) the Documentation or
012:         * some other similar material which is provided with the Software (if any).
013:         *
014:         * Copyright 1999-2004
015:         * University of Chicago and The University of Southern California.
016:         * All rights reserved.
017:         */package org.griphyn.cPlanner.poolinfo;
018:
019:        import org.griphyn.cPlanner.common.LogManager;
020:
021:        import org.griphyn.common.util.DynamicLoader;
022:        import org.griphyn.common.util.FactoryException;
023:
024:        import java.lang.reflect.Method;
025:
026:        /**
027:         * This class determines at runtime which
028:         * implementing class to use as a Pool Handle.
029:         * It uses the reflection package of java
030:         * to dynamically load a class. The class
031:         * to be loaded is specified by the
032:         * vds.pool.mode property.
033:         *
034:         * @author Karan Vahi
035:         * @author Gaurang Mehta
036:         * @version $Revision: 50 $
037:         */
038:        public class PoolMode {
039:
040:            /**
041:             * Constants to specify how to load the
042:             * class, as singleton or non singleton.
043:             */
044:            public static final int SINGLETON_LOAD = 0;
045:
046:            public static final int NON_SINGLETON_LOAD = 1;
047:
048:            /**
049:             * Constants for single read.
050:             *
051:             */
052:            public static final String SINGLE_READ = "single";
053:
054:            // public static final int SINGLE_READ_VALUE = 0;
055:
056:            //   public static final String SINGLE_READ_CLASS = "SingleReadPool";
057:
058:            /**
059:             * Constants for multiple read.
060:             */
061:            public static final String MULTIPLE_READ = "multiple";
062:
063:            //   public static final int MULTIPLE_READ_VALUE = 1;
064:
065:            //   public static final String MULTIPLE_READ_CLASS = "XML";
066:
067:            /**
068:             * Constants for xml pool read.
069:             */
070:            //    public static final String XML_READ = "xml";
071:            public static final int XML_READ_VALUE = 2;
072:
073:            public static final String XML_READ_CLASS = "XML";
074:
075:            /**
076:             * Constants for multiline text pool read.
077:             */
078:            //  public static final String TEXT_READ = "text";
079:            public static final int TEXT_READ_VALUE = 3;
080:
081:            public static final String TEXT_READ_CLASS = "Text";
082:
083:            /**
084:             * Constants for mode not defined.
085:             */
086:            public static final int UNDEFINED_READ_VALUE = -1;
087:
088:            public static final String PACKAGE_NAME = "org.griphyn.cPlanner.poolinfo.";
089:
090:            private static LogManager mLogger = LogManager.getInstance();
091:
092:            //add your constants here.
093:
094:            /**
095:             * Given a string readMode returns the
096:             * name of the class that implements
097:             * that read mode. If the readMode
098:             * doesnt equal any of the predefined
099:             * constants then the value of readMode
100:             * is taken as the name of the implementing class.
101:             *
102:             * @param readMode  The String form of the
103:             *              read mode, got from the property
104:             *              vds.pool.mode.
105:             *
106:             * @return  the corresponding int value
107:             *          of the mode. If not found
108:             *          then null
109:             *
110:             */
111:            public static String getImplementingClass(String readMode) {
112:                if (readMode.trim().equalsIgnoreCase(SINGLE_READ)
113:                        || readMode.trim().equalsIgnoreCase(MULTIPLE_READ)) {
114:                    throw new RuntimeException("The pool mode " + readMode
115:                            + " is no " + "longer supported. Please use the "
116:                            + XML_READ_CLASS + " mode or the "
117:                            + TEXT_READ_CLASS + " mode.");
118:                } else if (readMode.trim().equalsIgnoreCase(XML_READ_CLASS)) {
119:                    return XML_READ_CLASS;
120:                } else if (readMode.trim().equalsIgnoreCase(TEXT_READ_CLASS)) {
121:                    return TEXT_READ_CLASS;
122:                } else {
123:                    //no match to any predefined constant
124:                    //assume that the value of readMode is the
125:                    //name of the implementing class
126:                    return readMode;
127:                }
128:
129:            }
130:
131:            /**
132:             * Loads the pool info provider class using the reflection package
133:             * in java at runtime. The class is loaded as a singleton or
134:             * a non-singleton dependant on the parameter passed. The properties
135:             * file that is picked up is the default properties file from
136:             * $PEGASUS_HOME/etc directory.
137:             *
138:             * @param poolClass the name of the class that resides in the
139:             *                  package named PoolMode.PACKAGE_NAME or the
140:             *                  complete name of the class including the
141:             *                  package name.
142:             *
143:             * @param poolProvider  the path to the file, that contains the
144:             *                      pool configuration in the appropriate format
145:             *                      that the implementing poolClass understands.
146:             *
147:             *
148:             * @param lMode     the loading mode of the class. It specifies whether
149:             *                  the singleton object of the class needs to be
150:             *                  loaded or the non singleton instance.
151:             *
152:             * @return  the object corresponding to the pool info provider class.
153:             */
154:            public static PoolInfoProvider loadPoolInstance(String poolClass,
155:                    String poolProvider, int lMode) {
156:
157:                Object argList[] = new Object[2];
158:                argList[0] = poolProvider;
159:                argList[1] = org.griphyn.common.util.VDSProperties.PROPERTY_FILENAME;
160:
161:                return loadPoolInstance(poolClass, lMode, argList);
162:
163:            }
164:
165:            /**
166:             * Loads the pool info provider class using the reflection package
167:             * in java at runtime. The class is loaded as a singleton or
168:             * a non-singleton dependant on the parameter passed.
169:             *
170:             * @param poolClass the name of the class that resides in the
171:             *                  package named PoolMode.PACKAGE_NAME or the
172:             *                  complete name of the class including the
173:             *                  package name.
174:             *
175:             * @param poolProvider  the path to the file, that contains the
176:             *                      pool configuration in the appropriate format
177:             *                      that the implementing poolClass understands.
178:             *
179:             * @param propFileName  name of the properties file to picked from
180:             *                      $PEGASUS_HOME/etc/ directory. For the singleton
181:             *                      loading only the default file is picked up.
182:             *
183:             * @param lMode     the loading mode of the class. It specifies whether
184:             *                  the singleton object of the class needs to be
185:             *                  loaded or the non singleton instance.
186:             *
187:             * @return  the object corresponding to the pool info provider class.
188:             */
189:            public static PoolInfoProvider loadPoolInstance(String poolClass,
190:                    String poolProvider, String propFileName, int lMode) {
191:
192:                Object argList[] = new Object[2];
193:                argList[0] = poolProvider;
194:                argList[1] = propFileName;
195:
196:                return loadPoolInstance(poolClass, lMode, argList);
197:
198:            }
199:
200:            /**
201:             * Its returns the name of the method that needs to be invoked
202:             * to get the object of the implementing pool class. It determines
203:             * the method name on the basis of the value of the loading mode
204:             * specified.
205:             *
206:             * @param lMode     the loading mode of the class. It specifies whether
207:             *                  the singleton object of the class needs to be
208:             *                  loaded or the non singleton instance.
209:             *
210:             * @return  the name of the method that needs to be invoked.
211:             */
212:            public static String getMethodName(int lMode) {
213:                String name = null;
214:                if (lMode == SINGLETON_LOAD) {
215:                    name = "singletonInstance";
216:                } else {
217:                    if (lMode == NON_SINGLETON_LOAD) {
218:                        name = "nonSingletonInstance";
219:                    }
220:                }
221:                return name;
222:
223:            }
224:
225:            /**
226:             * Loads the appropriate class that implements a particular
227:             * pool mode using the reflection package in java at runtime.
228:             *
229:             * @param poolClass String
230:             *
231:             * @param lMode     the loading mode of the class. It specifies whether
232:             *                  the singleton object of the class needs to be
233:             *                  loaded or the non singleton instance.
234:             * @param argList Object[]
235:             * @return PoolInfoProvider
236:             *
237:             * @throws FactoryException that nests any error that
238:             *         might occur during the instantiation of the implementation.
239:             */
240:            private static PoolInfoProvider loadPoolInstance(String poolClass,
241:                    int lMode, Object[] argList) throws FactoryException {
242:                PoolInfoProvider pi = null;
243:                String mLogMsg = null;
244:                String methodName = getMethodName(lMode);
245:
246:                //get the complete name including
247:                //the package if the package name not
248:                //specified
249:                if (poolClass.indexOf(".") == -1) {
250:                    poolClass = PACKAGE_NAME + poolClass;
251:                }
252:
253:                DynamicLoader d = new DynamicLoader(poolClass);
254:
255:                try {
256:                    //instantiate the class
257:                    //with no constructor
258:                    Class cls = Class.forName(poolClass);
259:
260:                    //creating a new string to get
261:                    //it's class object that needs to
262:                    //be passed. Could be wrong potentially??
263:                    //This identifies the signature for
264:                    //the method
265:                    Class partypes[] = new Class[argList.length];
266:
267:                    for (int i = 0; i < argList.length; i++) {
268:                        partypes[i] = (argList[i] == null) ?
269:                        //try to put in a string
270:                        //actually the calling class should never pass
271:                        //null
272:                        new String().getClass()
273:                                : argList[i].getClass();
274:                    }
275:
276:                    //get the handle to the method
277:                    Method meth = cls.getMethod(methodName, partypes);
278:
279:                    //invoke the method that returns
280:                    //us the singleton instance
281:                    Object retobj = meth.invoke(null, argList);
282:                    pi = (PoolInfoProvider) retobj;
283:                } catch (Exception e) {
284:                    throw new FactoryException(
285:                            "Instantiating Create Directory", poolClass, e);
286:                }
287:
288:                return pi;
289:            }
290:
291:            /**
292:             * given a string Mode returns the
293:             * corresponding int value
294:             *
295:             * @param readMode  The String form of the
296:             *              read mode
297:             *
298:             * @return  the corresponding int value
299:             *          of the mode. If not found
300:             *          then null
301:             * @deprecated
302:             */
303:            public static int getValue(String readMode) {
304:                if (readMode.trim().equalsIgnoreCase(SINGLE_READ)) {
305:                    return -1;
306:                } else if (readMode.trim().equalsIgnoreCase(MULTIPLE_READ)) {
307:                    return -1;
308:                } else if (readMode.trim().equalsIgnoreCase(XML_READ_CLASS)) {
309:                    return XML_READ_VALUE;
310:                } else if (readMode.trim().equalsIgnoreCase(TEXT_READ_CLASS)) {
311:                    return TEXT_READ_VALUE;
312:                } else {
313:                    return UNDEFINED_READ_VALUE;
314:                }
315:            }
316:
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.