Source Code Cross Referenced for Janino2ElementInfo.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » 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 Framework » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: Janino2ElementInfo.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import com.uwyn.rife.config.RifeConfig;
011:        import com.uwyn.rife.engine.exceptions.EngineException;
012:        import com.uwyn.rife.engine.exceptions.NotFoundProcessingErrorException;
013:        import com.uwyn.rife.engine.exceptions.ParsingErrorException;
014:        import com.uwyn.rife.engine.exceptions.ProcessingErrorException;
015:        import com.uwyn.rife.resources.ResourceFinder;
016:        import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
017:        import com.uwyn.rife.tools.InnerClassException;
018:        import com.uwyn.rife.tools.InputStreamUser;
019:        import java.io.InputStream;
020:        import java.lang.reflect.InvocationTargetException;
021:        import java.net.URL;
022:        import org.codehaus.janino.Scanner;
023:        import org.codehaus.janino.ScriptEvaluator;
024:
025:        class Janino2ElementInfo implements  ElementInfoProcessor {
026:            Janino2ElementInfo() {
027:            }
028:
029:            public void processElementInfo(ElementInfoBuilder builder,
030:                    String declarationName, ResourceFinder resourceFinder)
031:                    throws EngineException {
032:                JaninoProcessor processor = new JaninoProcessor(builder);
033:
034:                String processed_path = null;
035:                try {
036:                    // process the element declaration
037:                    try {
038:                        processed_path = declarationName;
039:                        processor.processJanino(processed_path, resourceFinder);
040:                    } catch (NotFoundProcessingErrorException e) {
041:                        processed_path = DEFAULT_ELEMENTS_PATH
042:                                + declarationName;
043:                        processor.processJanino(processed_path, resourceFinder);
044:                    }
045:                } catch (Exception e) {
046:                    throw new ProcessingErrorException("element",
047:                            declarationName, e);
048:                }
049:
050:                // obtain the modification time
051:                if (RifeConfig.Engine.getSiteAutoReload()) {
052:                    URL resource = resourceFinder.getResource(processed_path);
053:                    if (null == resource) {
054:                        throw new NotFoundProcessingErrorException("element",
055:                                processed_path, null);
056:                    }
057:
058:                    try {
059:                        builder.addResourceModificationTime(new UrlResource(
060:                                resource, processed_path), resourceFinder
061:                                .getModificationTime(resource));
062:                    } catch (ResourceFinderErrorException e) {
063:                        throw new ProcessingErrorException(
064:                                "element",
065:                                declarationName,
066:                                "Error while retrieving the modification time.",
067:                                e);
068:                    }
069:                }
070:            }
071:
072:            private class JaninoProcessor {
073:                private ElementInfoBuilder mElementInfoBuilder = null;
074:
075:                private JaninoProcessor(ElementInfoBuilder builder) {
076:                    mElementInfoBuilder = builder;
077:                }
078:
079:                public synchronized void processJanino(final String janinoPath,
080:                        ResourceFinder resourceFinder) {
081:                    if (null == janinoPath)
082:                        throw new IllegalArgumentException(
083:                                "janinoPath can't be null.");
084:                    if (janinoPath.length() == 0)
085:                        throw new IllegalArgumentException(
086:                                "janinoPath can't be empty.");
087:                    if (null == resourceFinder)
088:                        throw new IllegalArgumentException(
089:                                "resourceFinder can't be null.");
090:
091:                    // retrieve a stream towards the janino script
092:                    ScriptEvaluator evaluator = null;
093:                    try {
094:                        evaluator = resourceFinder.useStream(janinoPath,
095:                                new InputStreamUser() {
096:                                    public ScriptEvaluator useInputStream(
097:                                            InputStream stream)
098:                                            throws InnerClassException {
099:                                        if (null == stream) {
100:                                            throw new NotFoundProcessingErrorException(
101:                                                    "element", janinoPath, null);
102:                                        }
103:
104:                                        // parse the janino script and create an evaluator
105:                                        try {
106:                                            return new ScriptEvaluator(
107:                                                    new Scanner(janinoPath,
108:                                                            stream),
109:                                                    Void.TYPE,
110:                                                    new String[] { "builder" },
111:                                                    new Class[] { ElementInfoBuilder.class },
112:                                                    new Class[0], getClass()
113:                                                            .getClassLoader());
114:                                        } catch (Throwable e) {
115:                                            throw new ParsingErrorException(
116:                                                    "element", janinoPath, e);
117:                                        }
118:                                    }
119:                                });
120:                    } catch (ResourceFinderErrorException e) {
121:                        throw new NotFoundProcessingErrorException("element",
122:                                janinoPath, e);
123:                    }
124:
125:                    // evaluate the script and provide the parameter
126:                    try {
127:                        evaluator
128:                                .evaluate(new Object[] { mElementInfoBuilder });
129:                    } catch (InvocationTargetException e) {
130:                        throw new ProcessingErrorException("element",
131:                                janinoPath, e);
132:                    }
133:                }
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.