Source Code Cross Referenced for ScriptedController.java in  » XML-UI » xmlgui » org » beryl » gui » 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 » XML UI » xmlgui » org.beryl.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui;
023:
024:        import groovy.lang.GroovyClassLoader;
025:
026:        import java.io.BufferedInputStream;
027:        import java.io.File;
028:        import java.io.FileInputStream;
029:        import java.io.IOException;
030:        import java.io.InputStream;
031:        import java.lang.reflect.InvocationTargetException;
032:        import java.lang.reflect.Method;
033:        import java.net.URL;
034:
035:        import org.codehaus.groovy.syntax.SyntaxException;
036:
037:        /**
038:         * Abstract scripted controller class. All created GUI scripts should subclass
039:         * from this class
040:         */
041:        public abstract class ScriptedController extends Controller {
042:            private GroovyClassLoader loader = null;
043:
044:            /**
045:             * Create a new scripted controller
046:             */
047:            public ScriptedController() {
048:                loader = (GroovyClassLoader) Thread.currentThread()
049:                        .getContextClassLoader();
050:            }
051:
052:            /**
053:             * Load a groovy script containing another scripted controller
054:             * @param scriptFile The script file
055:             * @return The instance
056:             * @throws GUIExceptions If there were errors while loading/parsing/compiling/instantiating the script
057:             */
058:            protected ScriptedController loadScript(String scriptFile)
059:                    throws GUIException {
060:                return loadScript(scriptFile, null);
061:            }
062:
063:            /**
064:             * Load a groovy script containing another scripted controller
065:             * @param scriptFile The script file
066:             * @return The instance
067:             * @throws GUIExceptions If there were errors while loading/parsing/compiling/instantiating the script
068:             */
069:            protected ScriptedController loadScript(String scriptFile,
070:                    Object parameters[]) throws GUIException {
071:                try {
072:                    InputStream stream = null;
073:                    File file = new File(scriptFile);
074:
075:                    if (file.exists()) {
076:                        stream = new FileInputStream(file);
077:                    } else {
078:                        URL url = getClass().getResource(scriptFile);
079:                        if (url == null)
080:                            throw new GUIException("Script file [" + scriptFile
081:                                    + "] not found");
082:                        stream = url.openStream();
083:                    }
084:
085:                    if (file.exists()) {
086:                        stream = new FileInputStream(file);
087:                    } else {
088:                        URL url = getClass().getResource(scriptFile);
089:                        if (url == null)
090:                            throw new GUIException("Script file [" + scriptFile
091:                                    + "] not found");
092:                        stream = url.openStream();
093:                    }
094:
095:                    Class scriptClass = loader.parseClass(
096:                            new BufferedInputStream(stream), scriptFile);
097:                    Object instance = scriptClass.newInstance();
098:
099:                    if (parameters == null || parameters.length == 0)
100:                        return (ScriptedController) instance;
101:
102:                    Method methods[] = scriptClass.getMethods();
103:
104:                    String className = scriptClass.getName();
105:                    if (className.indexOf('.') != -1)
106:                        className = className.substring(className
107:                                .lastIndexOf('.') + 1, className.length());
108:
109:                    for (int i = 0; i < methods.length; i++) {
110:                        Method method = methods[i];
111:                        if (method.getName().equals(className)
112:                                && method.getParameterTypes().length == parameters.length) {
113:                            method.invoke(instance, parameters);
114:                            return (ScriptedController) instance;
115:                        }
116:                    }
117:                    throw new GUIException(
118:                            "No matching constructor found while trying to load a script");
119:                } catch (IOException e) {
120:                    throw new GUIException(
121:                            "I/O Exception while trying to load a script", e);
122:                } catch (SyntaxException e) {
123:                    throw new GUIException(
124:                            "Syntax error while trying to load a script", e);
125:                } catch (IllegalAccessException e) {
126:                    throw new GUIException(
127:                            "Access error while trying to load a script", e);
128:                } catch (InstantiationException e) {
129:                    throw new GUIException(
130:                            "Instantiation error while trying to load a script",
131:                            e);
132:                } catch (InvocationTargetException e) {
133:                    throw new GUIException(
134:                            "Exception while trying to instantiate a script", e);
135:                } catch (ClassCastException e) {
136:                    throw new GUIException(
137:                            "Error while trying to load a script: Does not extend from ScriptedController",
138:                            e);
139:                }
140:            }
141:
142:            public static ScriptedController launchScript(String scriptFile,
143:                    Object parameters[]) throws GUIException {
144:                /* Initialize the script class loader */
145:                Thread.currentThread().setContextClassLoader(
146:                        new GroovyClassLoader(ScriptedController.class
147:                                .getClassLoader()));
148:
149:                ScriptedController tmp = new ScriptedController() {
150:                    public void eventOccured(GUIEvent event) {
151:                    }
152:                };
153:                return tmp.loadScript(scriptFile, parameters);
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.