Source Code Cross Referenced for PJwrapper.java in  » Web-Server » Brazil » sunlabs » brazil » util » 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 » Web Server » Brazil » sunlabs.brazil.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * PJwrapper.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1999-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): suhler.
022:         *
023:         * Version:  1.5
024:         * Created by suhler on 99/01/05
025:         * Last modified by suhler on 00/05/31 13:52:32
026:         */
027:
028:        package sunlabs.brazil.util;
029:
030:        import java.lang.reflect.Method;
031:        import java.lang.reflect.InvocationTargetException;
032:
033:        /**
034:         * Wrap a pJama invocation, to allow for persistent operation.
035:         * pJama is an implementation of orthoginal persistance, allowin session
036:         * state to be recovered after server shut-downs.
037:         * See <a href=http://www.sun.com/research/forest/>here</a>
038:         * for more information.
039:         * This utility class allows a server application to run with the pJama
040:         * persistent VM by dynamically locating  and binding the classes at run time.
041:         * If pJama is not available, a standard <b>transient</b> implementation is
042:         * used instead.
043:         *
044:         * @author		Stephen Uhler
045:         * @version            @(#) PJwrapper.java 1.4 99/08/06 12:31:42
046:         *
047:         */
048:
049:        /*
050:         * To use with the persistent store, identify a "root" object for persistence.
051:         * This is normally a static reference:
052:         *   Static Type root= null;		// <Type> is the objects class
053:         *
054:         * When you are ready to start the store:
055:         *   if (root == null) {
056:         *      root = initStore("some identifying string", Type.class)
057:         *   }
058:         *
059:         * Any time you want stabilization, call:
060:         *   stabilize()
061:         *
062:         * If the store didn't start, you still get a valid instance of <root>, 
063:         * but isPersistent() returns false, and getError() returns why.
064:         */
065:
066:        public class PJwrapper {
067:            private static boolean persistent = false; // is persistence on?
068:            private static String error = null; // last error message
069:            private static Class pClass;
070:
071:            private PJwrapper() {
072:            }
073:
074:            /**
075:             * See if we are using persistence.
076:             * @return	true, is persistence is enabled.
077:             */
078:
079:            public static boolean isPersistent() {
080:                return persistent;
081:            }
082:
083:            /**
084:             * Return the cause of most recent failure.
085:             */
086:
087:            public static String getError() {
088:                return error;
089:            }
090:
091:            /**
092:             * Do a one-time store initialization,
093:             * @param  The string name to identify this store
094:             * @param  The type of the object to be the store root
095:             * @return The root object.  If one didn't exist, it is
096:             *		created with newInstance()
097:             */
098:
099:            public static Object initStore(String name, Class type) {
100:                Object root = null;
101:                Object store = getStore();
102:                if (store == null) {
103:                    try {
104:                        root = (Object) (type.newInstance());
105:                    } catch (Exception e) {
106:                        error = e.toString();
107:                    }
108:                    return root;
109:                }
110:                try {
111:                    Class[] rootParams = { java.lang.String.class };
112:                    Object[] rootArgs = { name };
113:                    Method rootMethod = pClass
114:                            .getMethod("getPRoot", rootParams);
115:                    root = (Object) rootMethod.invoke(store, rootArgs);
116:                    if (root == null) {
117:                        Class[] newParams = { java.lang.String.class,
118:                                java.lang.Object.class };
119:                        Object[] newArgs = { name, null };
120:                        root = (Object) type.newInstance();
121:                        newArgs[1] = root;
122:                        Method newMethod = pClass.getMethod("newPRoot",
123:                                newParams);
124:                        newMethod.invoke(store, newArgs);
125:                    }
126:                    persistent = true;
127:                } catch (Exception e) {
128:                    error = e.toString();
129:                    try {
130:                        root = (Object) (type.newInstance());
131:                    } catch (Exception e2) {
132:                        error += " " + e2.toString();
133:                    }
134:                }
135:                return root;
136:            }
137:
138:            /**
139:             * Stabilize the store
140:             * @return		true if successful.  Use getError() to extract
141:             *			     reason for failure
142:             */
143:
144:            public static boolean stabilize() {
145:                boolean result = false;
146:                if (!persistent) {
147:                    return false;
148:                }
149:                try {
150:                    Object store = getStore();
151:                    Class[] stabilizeParams = new Class[0];
152:                    Object[] stabilizeArgs = new Object[0];
153:                    Method stableMethod = pClass.getMethod("stabilizeAll",
154:                            stabilizeParams);
155:                    stableMethod.invoke(store, stabilizeArgs);
156:                    result = true;
157:                } catch (Exception e) {
158:                    error = e.toString();
159:                }
160:                return result;
161:            }
162:
163:            /**
164:             * get an initial store reference
165:             * @return		null, if no store available
166:             */
167:
168:            private static Object getStore() {
169:                Object store = null;
170:                try {
171:                    pClass = Class.forName("org.opj.store.PJStoreImpl");
172:                    Class[] storeParams = new Class[0];
173:                    Object[] storeArgs = new Object[0];
174:                    Method storeMethod = pClass.getMethod("getStore",
175:                            storeParams);
176:                    store = storeMethod.invoke(null, storeArgs);
177:                    persistent = true;
178:                } catch (InvocationTargetException e) {
179:                    error = e.getTargetException().toString();
180:                } catch (Exception e) {
181:                    error = e.toString();
182:                }
183:                return store;
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.