Source Code Cross Referenced for BaseInvoker.java in  » Groupware » coefficient » za » org » coefficient » invokers » base » 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 » Groupware » coefficient » za.org.coefficient.invokers.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Coefficient - facilitates project based collaboration
003:         * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
004:         * PO Box 395
005:         * Pretoria 0001, RSA
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:
020:        package za.org.coefficient.invokers.base;
021:
022:        import org.apache.commons.beanutils.MethodUtils;
023:        import org.apache.commons.beanutils.PropertyUtils;
024:        import org.apache.commons.lang.StringUtils;
025:
026:        import za.co.csir.icomtek.workflow.interfaces.WorkflowContext;
027:        import za.co.csir.icomtek.workflow.interfaces.WorkflowModuleInvoker;
028:        import za.org.coefficient.interfaces.Invoker;
029:        import za.org.coefficient.core.Constants;
030:
031:        import za.org.coefficient.authentication.Role;
032:        import za.org.coefficient.exception.ConfigurationException;
033:        import za.org.coefficient.interfaces.CoefficientContext;
034:        import za.org.coefficient.interfaces.ModuleLocal;
035:        import za.org.coefficient.interfaces.ThemeLocalIf;
036:        import za.org.coefficient.util.ejb.SecurityUtil;
037:
038:        /**
039:         * This is an abstract base class that provides most of the funtionality
040:         * an invoker requires. This allows us to invoke methods on 
041:         * modules, services, and themes without specifiying the methods that know
042:         * about the environment.
043:         *
044:         * @version $Revision: 1.6 $ $Date: 2004/11/09 13:52:11 $
045:         * @author <a href="mailto:detkin@csir.co.za">Dylan Etkin</a>
046:         *
047:         */
048:        public abstract class BaseInvoker implements  Invoker,
049:                WorkflowModuleInvoker {
050:            //~ Static fields/initializers =============================================
051:
052:            private static final String CREATE = "create";
053:            private static final String LOCAL = "Local";
054:
055:            //~ Methods ================================================================
056:
057:            /**
058:             * This method will look for a request parameter named module and
059:             * one named op and will try to fire that operation on the module.
060:             */
061:            public Object invoke(CoefficientContext ctx) throws Exception {
062:                // Fire the module
063:                String module = ctx.getParameter("module");
064:                String operation = ctx.getParameter("op");
065:                if (module == null || module.trim().equals("")) {
066:                    if (ctx.getCurrentUser() == null) {
067:                        module = Constants.WELCOME_MODULE;
068:                    } else {
069:                        // Default to the MyPage
070:                        module = "MyData";
071:                    }
072:                }
073:
074:                return invokeOpOnModule(module, operation, ctx);
075:            }
076:
077:            public Object invokeGetterOnModule(String module, String method)
078:                    throws Exception {
079:                if ((method == null) || (module == null)) {
080:                    throw new ConfigurationException(
081:                            "module and method must not be null");
082:                }
083:                Object retVal = null;
084:
085:                // Find the module
086:                ModuleLocal mod = getModule(module);
087:                try {
088:                    if (mod != null) {
089:                        // invoke it
090:                        retVal = PropertyUtils.getProperty(mod, method);
091:                    }
092:                } catch (NoSuchMethodException nsme) {
093:                    nsme.printStackTrace();
094:                } catch (IllegalAccessException iae) {
095:                    iae.printStackTrace();
096:                }
097:
098:                return retVal;
099:            }
100:
101:            public Object invokeMethodOnModule(String module, String method,
102:                    Object[] paramVals) throws Exception {
103:                if ((method == null) || (module == null)) {
104:                    throw new ConfigurationException(
105:                            "module and method must not be null");
106:                }
107:                Object retVal = null;
108:
109:                // Find the module
110:                ModuleLocal mod = getModule(module);
111:                try {
112:                    if (mod != null) {
113:                        // invoke it
114:                        retVal = MethodUtils.invokeMethod(mod, method,
115:                                paramVals);
116:                    }
117:                } catch (NoSuchMethodException nsme) {
118:                    nsme.printStackTrace();
119:                } catch (IllegalAccessException iae) {
120:                    iae.printStackTrace();
121:                }
122:
123:                return retVal;
124:            }
125:
126:            public Object invokeMethodOnService(String serviceName,
127:                    String method, Object[] paramVals) throws Exception {
128:                if ((method == null) || (serviceName == null)) {
129:                    throw new ConfigurationException(
130:                            "serviceName and method must not be null");
131:                }
132:                Object retVal = null;
133:
134:                // Find the service
135:                Object service = getService(serviceName);
136:                try {
137:                    if (service != null) {
138:                        // invoke it
139:                        retVal = MethodUtils.invokeMethod(service, method,
140:                                paramVals);
141:                    }
142:                } catch (NoSuchMethodException nsme) {
143:                    nsme.printStackTrace();
144:                } catch (IllegalAccessException iae) {
145:                    iae.printStackTrace();
146:                }
147:
148:                return retVal;
149:            }
150:
151:            /**
152:             * This method will invoke the named operation on the named module
153:             * with the given context as a parameter
154:             */
155:            public Object invokeOpOnModule(String module, String operation,
156:                    CoefficientContext ctx) throws Exception {
157:                Object retVal = null;
158:
159:                // Fire the module
160:                ModuleLocal mod = getModule(module);
161:                try {
162:                    if (mod != null) {
163:
164:                        if (mod.isProjectRequired() && ctx.getProject() == null) {
165:                            ctx
166:                                    .setError("You must select a project to perform this operation");
167:                        } else {
168:                            // first thing to do is always set the context
169:                            PropertyUtils.setProperty(mod,
170:                                    "coefficientContext", ctx);
171:                            if (operation == null) {
172:                                // Get the "main" method from the module and invoke it
173:                                operation = (String) PropertyUtils.getProperty(
174:                                        mod, "mainMethod");
175:                            }
176:
177:                            // perform the security check
178:                            Role role = SecurityUtil.getHighestRoleForUser(ctx
179:                                    .getCurrentUser(), ctx.getProject());
180:                            String err = mod.canExecuteForRole(ctx, operation,
181:                                    role);
182:                            if (err == null) {
183:                                // invoke the operation on the module
184:                                retVal = MethodUtils.invokeMethod(mod,
185:                                        operation, ctx);
186:                            } else {
187:                                ctx.setError(err);
188:                            }
189:                        }
190:                    } else {
191:                        ctx.setError("<b>No such module exists!</b>");
192:                    }
193:                } catch (NoSuchMethodException nsme) {
194:                    nsme.printStackTrace();
195:                    ctx.setError("<b>No such operation exists on module "
196:                            + module + "!</b>");
197:                } catch (IllegalAccessException iae) {
198:                    iae.printStackTrace();
199:                    ctx.setError("<b>No such operation exists on module "
200:                            + module + "!</b>");
201:                }
202:
203:                if (ctx.isError()) {
204:                    retVal = ctx;
205:                }
206:                return retVal;
207:            }
208:
209:            /**
210:             * NOTE: This is bad and is only done to give the workflow some
211:             * autonomy
212:             * This method will invoke the named operation on the named module
213:             * with the given a workflow context which is a CoefficientContext
214:             */
215:            public Object invokeOpOnModule(String module, String operation,
216:                    WorkflowContext ctx) throws Exception {
217:                if (ctx instanceof  CoefficientContext) {
218:                    CoefficientContext pctx = (CoefficientContext) ctx;
219:
220:                    return invokeOpOnModule(module, operation, pctx);
221:                } else {
222:                    return null;
223:                }
224:            }
225:
226:            public Object invokeMethodOnTheme(String theme, String method,
227:                    Object[] paramVals) throws Exception {
228:                if ((theme == null) || (method == null)) {
229:                    throw new ConfigurationException(
230:                            "theme and method must not be null");
231:                }
232:                Object retVal = null;
233:
234:                // Find the module
235:                ThemeLocalIf themeIf = getTheme(theme);
236:                try {
237:                    if (themeIf != null) {
238:                        // invoke it
239:                        retVal = MethodUtils.invokeMethod(themeIf, method,
240:                                paramVals);
241:                    }
242:                } catch (NoSuchMethodException nsme) {
243:                    nsme.printStackTrace();
244:                } catch (IllegalAccessException iae) {
245:                    iae.printStackTrace();
246:                }
247:                return retVal;
248:            }
249:
250:            public abstract Object getService(String serviceName)
251:                    throws Exception;
252:
253:            protected abstract ThemeLocalIf getTheme(String theme)
254:                    throws Exception;
255:
256:            protected abstract ModuleLocal getModule(String module)
257:                    throws Exception;
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.