Source Code Cross Referenced for LZClientObject.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » remote » json » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.remote.json 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * LZClientObject.java
003:         * ****************************************************************************/package org.openlaszlo.remote.json;
004:
005:        import java.io.*;
006:        import java.lang.reflect.*;
007:        import javax.servlet.http.*;
008:        import org.openlaszlo.iv.flash.util.*;
009:        import org.openlaszlo.iv.flash.api.action.*;
010:        import org.openlaszlo.iv.flash.api.*;
011:        import org.openlaszlo.utils.*;
012:        import org.openlaszlo.xml.internal.DataCommon;
013:        import org.openlaszlo.xml.internal.DataContext;
014:        import org.openlaszlo.sc.ScriptCompiler;
015:        import org.apache.log4j.*;
016:
017:        /**
018:         * Utility class to create object JSON based on a server object.
019:         */
020:        public class LZClientObject {
021:            public static Logger mLogger = Logger
022:                    .getLogger(LZClientObject.class);
023:
024:            /**
025:             */
026:            public static String createObjectProgram(String classname,
027:                    String scope, Class c) {
028:                if (mLogger.isDebugEnabled()) {
029:                    mLogger.debug("createObjectProgram (JSON)(" + classname
030:                            + "," + "," + scope + "," + c.getName() + ")");
031:                }
032:
033:                StringBuffer body = new StringBuffer();
034:
035:                // Tells client data returned is an object 
036:                // this.__LZstubload = true
037:                body.append("{");
038:                body.append("__LZstubload: true, ");
039:                // SOAP specific information
040:                body.append("stubinfo: ");
041:                body.append("{remoteClass: " + ScriptCompiler.quote(classname)
042:                        + "}, ");
043:
044:                // object.stub
045:                body.append("stub: ");
046:                {
047:
048:                    body.append("{");
049:
050:                    int count = 0;
051:                    boolean onlyStatic = "staticobject".equals(scope);
052:
053:                    //------------------------------------------------------------
054:                    // Create methods for object
055:                    Method[] methods = c.getMethods();
056:                    for (int i = 0; i < methods.length; i++) {
057:
058:                        // Skip Object methods
059:                        if (methods[i].getDeclaringClass() == Object.class) {
060:                            continue;
061:                        }
062:
063:                        // Check if we only want static methods
064:                        if (onlyStatic
065:                                && !Modifier
066:                                        .isStatic(methods[i].getModifiers())) {
067:                            continue;
068:                        }
069:
070:                        // Skip toString method.
071:                        String methodName = methods[i].getName();
072:                        if ("toString".equals(methodName)) {
073:                            continue;
074:                        }
075:
076:                        count++;
077:
078:                        if (i > 0) {
079:                            body.append(",");
080:                        }
081:
082:                        //------------------------------------------------------------
083:                        //
084:                        body.append(methodName + ": function (){");
085:                        {
086:                            // Check to see if method's last two parameters are
087:                            // HttpServletRequest and HttpServletResponse.
088:                            Class[] params = methods[i].getParameterTypes();
089:                            int len = params.length;
090:                            boolean doreq = // next to last or last argument
091:                            (len > 1 && params[len - 2] == HttpServletRequest.class)
092:                                    || (len > 0 && params[len - 1] == HttpServletRequest.class);
093:                            boolean dores = // should be last argument
094:                            (len > 0 && params[len - 1] == HttpServletResponse.class);
095:
096:                            // arguments.callee.args gets set in the client and includes
097:                            // secure and secureport information.  
098:                            //
099:                            body.append(" var args = arguments.callee.args;\n");
100:                            // 
101:
102:                            // _root.LzRemote.invoke(
103:                            //     arguments,
104:                            //     delegate,
105:                            //     classname,
106:                            //     classname + "." + methodName,
107:                            //     { op: 'session', doreq..., dores... },
108:                            //     this.secure,
109:                            //     this.secureport
110:                            // );
111:
112:                            body.append("return LzJavaRPCService.invoke(");
113:                            body.append("arguments[1], ");
114:                            body.append("arguments[0], ");
115:
116:                            body.append("{");
117:                            {
118:                                // { op: 'invoke', oname: varname, scope: scope, 
119:                                //   objectreturntype: objectreturntype, 
120:                                //   doreq: TBD, dores: TBD}
121:
122:                                body.append("op: 'invoke', ");
123:                                body
124:                                        .append("objectreturntype: args.objectreturntype, ");
125:                                body.append("oname: args.attributename, ");
126:                                body.append("scope: args.scope ,");
127:                                body.append("classname: "
128:                                        + ScriptCompiler.quote(classname)
129:                                        + ", ");
130:                                body.append("methodname: "
131:                                        + ScriptCompiler.quote(classname + "."
132:                                                + methodName));
133:
134:                                if (doreq) {
135:                                    body.append(", doreq: true");
136:                                }
137:                                if (dores) {
138:                                    body.append(", dores: true");
139:                                }
140:                            }
141:                            body.append("}, \n");
142:                            body.append("args.secure, args.securport);\n");
143:                        }
144:                        body.append("}");
145:                    }
146:                    body.append("}");
147:                }
148:
149:                body.append("}\n");
150:
151:                return body.toString();
152:            }
153:
154:            /**
155:               Return JSON representation of CLASSNAME
156:             */
157:            public static byte[] createObject(String classname, String scope,
158:                    int ignore) throws IOException {
159:                if (mLogger.isDebugEnabled()) {
160:                    mLogger.debug("createObject(JSON)(" + classname + ","
161:                            + scope + ")");
162:                }
163:
164:                Class c;
165:                try {
166:                    c = Class.forName(classname);
167:                } catch (ClassNotFoundException e) {
168:                    throw new RuntimeException("Can't find class " + classname);
169:                }
170:
171:                int i = 0;
172:                try {
173:                    String buf = createObjectProgram(classname, scope, c);
174:                    mLogger.debug("ClientObject:");
175:                    mLogger.debug(buf);
176:                    return buf.getBytes("UTF-8");
177:                } catch (IOException e) {
178:                    mLogger.error("io error creating object JSON: "
179:                            + e.getMessage());
180:                    throw e;
181:                }
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.