Source Code Cross Referenced for compile.java in  » Scripting » Pnuts » org » pnuts » lib » 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 » Scripting » Pnuts » org.pnuts.lib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * compile.java
003:         *
004:         * Copyright (c) 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         * See the file "LICENSE.txt" for information on usage and redistribution
007:         * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008:         */
009:        package org.pnuts.lib;
010:
011:        import java.io.File;
012:        import java.io.InputStream;
013:        import java.io.Reader;
014:        import java.util.zip.ZipOutputStream;
015:        import java.net.URL;
016:        import pnuts.lang.Context;
017:        import pnuts.lang.Pnuts;
018:        import pnuts.lang.PnutsException;
019:        import pnuts.lang.PnutsFunction;
020:        import pnuts.compiler.ClassFileHandler;
021:        import pnuts.compiler.FileWriterHandler;
022:        import pnuts.compiler.ZipWriterHandler;
023:        import pnuts.compiler.Compiler;
024:        import pnuts.ext.CachedScript;
025:
026:        public class compile extends PnutsFunction {
027:
028:            public compile() {
029:                super ("compile");
030:            }
031:
032:            public boolean defined(int nargs) {
033:                return nargs >= 1 && nargs <= 3;
034:            }
035:
036:            Object compileObject(Object arg, Context context) {
037:                Compiler compiler = new Compiler();
038:                if (arg instanceof  PnutsFunction) {
039:                    return compiler.compile((PnutsFunction) arg, context);
040:                }
041:                Pnuts parsed = parse.parse(arg, context);
042:                if (!(arg instanceof  Pnuts)) {
043:                    parsed.setScriptSource(arg);
044:                }
045:                try {
046:                    return compiler.compile(parsed, context);
047:                } catch (Exception e) {
048:                    return parsed;
049:                }
050:            }
051:
052:            protected Object exec(Object args[], Context context) {
053:                int nargs = args.length;
054:                if (nargs == 1) {
055:                    Object arg = args[0];
056:                    return compileObject(arg, context);
057:                } else if (nargs == 2) {
058:                    Object arg = args[0];
059:                    boolean reload = ((Boolean) args[1]).booleanValue();
060:                    if (!reload || (arg instanceof  InputStream)
061:                            || (arg instanceof  Reader)
062:                            || (arg instanceof  String)) {
063:                        return compileObject(arg, context);
064:                    }
065:                    URL url;
066:                    try {
067:                        if (arg instanceof  URL) {
068:                            url = (URL) arg;
069:                        } else if (arg instanceof  File) {
070:                            url = ((File) arg).toURL();
071:                        } else {
072:                            throw new IllegalArgumentException(String
073:                                    .valueOf(arg));
074:                        }
075:                        return new CachedScript(url, context
076:                                .getScriptEncoding(), context);
077:                    } catch (Exception e) {
078:                        throw new PnutsException(e, context);
079:                    }
080:
081:                } else if (nargs == 3) {
082:                    Object src = args[0];
083:                    String name = (String) args[1];
084:                    Object dest = args[2];
085:                    Compiler compiler = new Compiler(name, false, true);
086:                    ClassFileHandler handler;
087:                    if (dest instanceof  String) {
088:                        handler = new FileWriterHandler(new File((String) dest));
089:                    } else if (dest instanceof  File) {
090:                        handler = new FileWriterHandler((File) dest);
091:                    } else if (dest instanceof  ZipOutputStream) {
092:                        handler = new ZipWriterHandler((ZipOutputStream) dest);
093:                    } else {
094:                        throw new IllegalArgumentException(String.valueOf(dest));
095:                    }
096:                    Pnuts parsed = parse.parse(src, context);
097:                    if (!(src instanceof  Pnuts)) {
098:                        parsed.setScriptSource(src);
099:                    }
100:                    compiler.compile(parsed, handler);
101:                } else {
102:                    undefined(args, context);
103:                }
104:                return null;
105:            }
106:
107:            public String toString() {
108:                return "function compile((InputStream|Reader|String|File|URL|Pnuts) input {, reloadUpdatedScript }) or ((Pnuts|String)source, String className, (File|ZipOutputStream)output)";
109:            }
110:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.