Source Code Cross Referenced for Compiler.java in  » J2EE » facelets » com » sun » facelets » compiler » 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 » J2EE » facelets » com.sun.facelets.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed under the Common Development and Distribution License,
003:         * you may not use this file except in compliance with the License.
004:         * You may obtain a copy of the License at
005:         * 
006:         *   http://www.sun.com/cddl/
007:         *   
008:         * Unless required by applicable law or agreed to in writing, software
009:         * distributed under the License is distributed on an "AS IS" BASIS,
010:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
011:         * implied. See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         */package com.sun.facelets.compiler;
014:
015:        import java.io.IOException;
016:        import java.net.URL;
017:        import java.util.ArrayList;
018:        import java.util.HashMap;
019:        import java.util.List;
020:        import java.util.Map;
021:        import java.util.logging.Level;
022:        import java.util.logging.Logger;
023:
024:        import javax.el.ELException;
025:        import javax.el.ExpressionFactory;
026:        import javax.faces.FacesException;
027:        import javax.faces.context.FacesContext;
028:
029:        import com.sun.facelets.FaceletException;
030:        import com.sun.facelets.FaceletHandler;
031:        import com.sun.facelets.tag.CompositeTagDecorator;
032:        import com.sun.facelets.tag.CompositeTagLibrary;
033:        import com.sun.facelets.tag.TagDecorator;
034:        import com.sun.facelets.tag.TagLibrary;
035:        import com.sun.facelets.tag.ui.UILibrary;
036:        import com.sun.facelets.util.ParameterCheck;
037:        import com.sun.facelets.util.FacesAPI;
038:        import com.sun.facelets.util.ReflectionUtil;
039:
040:        /**
041:         * A Compiler instance may handle compiling multiple sources
042:         * 
043:         * @author Jacob Hookom
044:         * @version $Id: Compiler.java,v 1.15 2006/10/19 03:48:12 jhook Exp $
045:         */
046:        public abstract class Compiler {
047:
048:            protected final static Logger log = Logger
049:                    .getLogger("facelets.compiler");
050:
051:            public final static String EXPRESSION_FACTORY = "compiler.ExpressionFactory";
052:
053:            private static final TagLibrary EMPTY_LIBRARY = new CompositeTagLibrary(
054:                    new TagLibrary[0]);
055:
056:            private static final TagDecorator EMPTY_DECORATOR = new CompositeTagDecorator(
057:                    new TagDecorator[0]);
058:
059:            private boolean validating = false;
060:
061:            private boolean trimmingWhitespace = false;
062:
063:            private boolean trimmingComments = false;
064:
065:            private final List libraries = new ArrayList();
066:
067:            private final List decorators = new ArrayList();
068:
069:            private final Map features = new HashMap();
070:
071:            private boolean initialized = false;
072:
073:            /**
074:             * 
075:             */
076:            public Compiler() {
077:
078:            }
079:
080:            private synchronized void initialize() {
081:                if (this .initialized)
082:                    return;
083:                log.fine("Initializing");
084:                try {
085:                    TagLibraryConfig cfg = new TagLibraryConfig();
086:                    cfg.loadImplicit(this );
087:
088:                    if (!this .createTagLibrary().containsNamespace(
089:                            UILibrary.Namespace)) {
090:                        log
091:                                .severe("Missing Built-in Tag Libraries! Make sure they are included within the META-INF directory of Facelets' Jar");
092:                    }
093:
094:                } catch (IOException e) {
095:                    log.log(Level.SEVERE, "Compiler Initialization Error", e);
096:                } finally {
097:                    this .initialized = true;
098:                }
099:                log.fine("Initialization Successful");
100:            }
101:
102:            public final FaceletHandler compile(URL src, String alias)
103:                    throws IOException, FaceletException, ELException,
104:                    FacesException {
105:                if (!this .initialized)
106:                    this .initialize();
107:                return this .doCompile(src, alias);
108:            }
109:
110:            protected abstract FaceletHandler doCompile(URL src, String alias)
111:                    throws IOException, FaceletException, ELException,
112:                    FacesException;
113:
114:            public final TagDecorator createTagDecorator() {
115:                if (this .decorators.size() > 0) {
116:                    return new CompositeTagDecorator(
117:                            (TagDecorator[]) this .decorators
118:                                    .toArray(new TagDecorator[this .decorators
119:                                            .size()]));
120:                }
121:                return EMPTY_DECORATOR;
122:            }
123:
124:            public final void addTagDecorator(TagDecorator decorator) {
125:                ParameterCheck.notNull("decorator", decorator);
126:                if (!this .decorators.contains(decorator)) {
127:                    this .decorators.add(decorator);
128:                }
129:            }
130:
131:            public final ExpressionFactory createExpressionFactory() {
132:                ExpressionFactory el = null;
133:                el = (ExpressionFactory) this 
134:                        .featureInstance(EXPRESSION_FACTORY);
135:                if (el == null && FacesAPI.getVersion() >= 12) {
136:                    try {
137:                        el = FacesContext.getCurrentInstance().getApplication()
138:                                .getExpressionFactory();
139:                        if (el == null) {
140:                            log
141:                                    .warning("No default ExpressionFactory from Faces Implementation, attempting to load from Feature["
142:                                            + EXPRESSION_FACTORY + "]");
143:                        }
144:                    } catch (Exception e) {
145:                        // do nothing
146:                    }
147:                }
148:                if (el == null) {
149:                    this .features.put(EXPRESSION_FACTORY,
150:                            "com.sun.el.ExpressionFactoryImpl");
151:                    el = (ExpressionFactory) this 
152:                            .featureInstance(EXPRESSION_FACTORY);
153:                }
154:                return el;
155:            }
156:
157:            private final Object featureInstance(String name) {
158:                String type = (String) this .features.get(name);
159:                if (type != null) {
160:                    try {
161:                        return ReflectionUtil.forName(type).newInstance();
162:                    } catch (Throwable t) {
163:                        throw new FaceletException(
164:                                "Could not instantiate feature[" + name + "]: "
165:                                        + type);
166:                    }
167:                }
168:                return null;
169:            }
170:
171:            public final TagLibrary createTagLibrary() {
172:                if (this .libraries.size() > 0) {
173:                    return new CompositeTagLibrary(
174:                            (TagLibrary[]) this .libraries
175:                                    .toArray(new TagLibrary[this .libraries
176:                                            .size()]));
177:                }
178:                return EMPTY_LIBRARY;
179:            }
180:
181:            public final void addTagLibrary(TagLibrary library) {
182:                ParameterCheck.notNull("library", library);
183:                if (!this .libraries.contains(library)) {
184:                    this .libraries.add(library);
185:                }
186:            }
187:
188:            public final void setFeature(String name, String value) {
189:                this .features.put(name, value);
190:            }
191:
192:            public final String getFeature(String name) {
193:                return (String) this .features.get(name);
194:            }
195:
196:            public final boolean isTrimmingComments() {
197:                return this .trimmingComments;
198:            }
199:
200:            public final void setTrimmingComments(boolean trimmingComments) {
201:                this .trimmingComments = trimmingComments;
202:            }
203:
204:            public final boolean isTrimmingWhitespace() {
205:                return this .trimmingWhitespace;
206:            }
207:
208:            public final void setTrimmingWhitespace(boolean trimmingWhitespace) {
209:                this .trimmingWhitespace = trimmingWhitespace;
210:            }
211:
212:            public final boolean isValidating() {
213:                return this .validating;
214:            }
215:
216:            public final void setValidating(boolean validating) {
217:                this.validating = validating;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.