Source Code Cross Referenced for CreateObject.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » minilang » method » callops » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.minilang.method.callops 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CreateObject.java,v 1.1 2003/08/17 06:06:13 ajzeneski Exp $
003:         *
004:         *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005:         *
006:         *  Permission is hereby granted, free of charge, to any person obtaining a
007:         *  copy of this software and associated documentation files (the "Software"),
008:         *  to deal in the Software without restriction, including without limitation
009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         *  and/or sell copies of the Software, and to permit persons to whom the
011:         *  Software is furnished to do so, subject to the following conditions:
012:         *
013:         *  The above copyright notice and this permission notice shall be included
014:         *  in all copies or substantial portions of the Software.
015:         *
016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:        package org.ofbiz.minilang.method.callops;
025:
026:        import java.lang.reflect.*;
027:        import java.util.*;
028:
029:        import org.w3c.dom.*;
030:        import org.ofbiz.base.util.*;
031:
032:        import org.ofbiz.minilang.*;
033:        import org.ofbiz.minilang.method.*;
034:
035:        /**
036:         * Creates a Java object using the given fields as parameters
037:         *
038:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
039:         * @version    $Revision: 1.1 $
040:         * @since      2.0
041:         */
042:        public class CreateObject extends MethodOperation {
043:
044:            public static final String module = CreateObject.class.getName();
045:
046:            String className;
047:            ContextAccessor fieldAcsr;
048:            ContextAccessor mapAcsr;
049:
050:            /** A list of MethodObject objects to use as the method call parameters */
051:            List parameters;
052:
053:            public CreateObject(Element element, SimpleMethod simpleMethod) {
054:                super (element, simpleMethod);
055:                className = element.getAttribute("class-name");
056:                fieldAcsr = new ContextAccessor(element
057:                        .getAttribute("field-name"));
058:                mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
059:
060:                List parameterElements = UtilXml
061:                        .childElementList(element, null);
062:                if (parameterElements.size() > 0) {
063:                    parameters = new ArrayList(parameterElements.size());
064:
065:                    Iterator parameterIter = parameterElements.iterator();
066:                    while (parameterIter.hasNext()) {
067:                        Element parameterElement = (Element) parameterIter
068:                                .next();
069:                        MethodObject methodObject = null;
070:                        if ("string".equals(parameterElement.getNodeName())) {
071:                            methodObject = new StringObject(parameterElement,
072:                                    simpleMethod);
073:                        } else if ("field".equals(parameterElement
074:                                .getNodeName())) {
075:                            methodObject = new FieldObject(parameterElement,
076:                                    simpleMethod);
077:                        } else {
078:                            //whoops, invalid tag here, print warning
079:                            Debug.logWarning(
080:                                    "Found an unsupported tag under the call-object-method tag: "
081:                                            + parameterElement.getNodeName()
082:                                            + "; ignoring", module);
083:                        }
084:                        if (methodObject != null) {
085:                            parameters.add(methodObject);
086:                        }
087:                    }
088:                }
089:            }
090:
091:            public boolean exec(MethodContext methodContext) {
092:                String className = methodContext.expandString(this .className);
093:
094:                Class methodClass = null;
095:                try {
096:                    methodClass = ObjectType.loadClass(className, methodContext
097:                            .getLoader());
098:                } catch (ClassNotFoundException e) {
099:                    Debug
100:                            .logError(e,
101:                                    "Class to create not found with name "
102:                                            + className
103:                                            + " in create-object operation",
104:                                    module);
105:
106:                    String errMsg = "ERROR: Could not complete the "
107:                            + simpleMethod.getShortDescription()
108:                            + " process [Class to create not found with name "
109:                            + className + ": " + e.toString() + "]";
110:                    methodContext.setErrorReturn(errMsg, simpleMethod);
111:                    return false;
112:                }
113:
114:                Object[] args = null;
115:                Class[] parameterTypes = null;
116:                if (parameters != null) {
117:                    args = new Object[parameters.size()];
118:                    parameterTypes = new Class[parameters.size()];
119:
120:                    Iterator parameterIter = parameters.iterator();
121:                    int i = 0;
122:                    while (parameterIter.hasNext()) {
123:                        MethodObject methodObjectDef = (MethodObject) parameterIter
124:                                .next();
125:                        args[i] = methodObjectDef.getObject(methodContext);
126:
127:                        Class typeClass = methodObjectDef
128:                                .getTypeClass(methodContext.getLoader());
129:                        if (typeClass == null) {
130:                            String errMsg = "ERROR: Could not complete the "
131:                                    + simpleMethod.getShortDescription()
132:                                    + " process [Parameter type not found with name "
133:                                    + methodObjectDef.getTypeName() + "]";
134:                            Debug.logError(errMsg, module);
135:                            methodContext.setErrorReturn(errMsg, simpleMethod);
136:                            return false;
137:                        }
138:
139:                        parameterTypes[i] = typeClass;
140:                        i++;
141:                    }
142:                }
143:
144:                try {
145:                    Constructor constructor = methodClass
146:                            .getConstructor(parameterTypes);
147:                    try {
148:                        Object newObject = constructor.newInstance(args);
149:
150:                        //if fieldAcsr is empty, ignore return value
151:                        if (!fieldAcsr.isEmpty()) {
152:                            if (!mapAcsr.isEmpty()) {
153:                                Map retMap = (Map) mapAcsr.get(methodContext);
154:
155:                                if (retMap == null) {
156:                                    retMap = new HashMap();
157:                                    mapAcsr.put(methodContext, retMap);
158:                                }
159:                                fieldAcsr.put(retMap, newObject, methodContext);
160:                            } else {
161:                                // no map name, use the env
162:                                fieldAcsr.put(methodContext, newObject);
163:                            }
164:                        }
165:                    } catch (InstantiationException e) {
166:                        Debug
167:                                .logError(
168:                                        e,
169:                                        "Could not instantiate object in create-object operation",
170:                                        module);
171:
172:                        String errMsg = "ERROR: Could not complete the "
173:                                + simpleMethod.getShortDescription()
174:                                + " process [Could not instantiate object: "
175:                                + e.toString() + "]";
176:                        methodContext.setErrorReturn(errMsg, simpleMethod);
177:                        return false;
178:                    } catch (IllegalAccessException e) {
179:                        Debug
180:                                .logError(
181:                                        e,
182:                                        "Illegal access constructing object in create-object operation",
183:                                        module);
184:
185:                        String errMsg = "ERROR: Could not complete the "
186:                                + simpleMethod.getShortDescription()
187:                                + " process [Illegal access constructing object: "
188:                                + e.toString() + "]";
189:                        methodContext.setErrorReturn(errMsg, simpleMethod);
190:                        return false;
191:                    } catch (IllegalArgumentException e) {
192:                        Debug
193:                                .logError(
194:                                        e,
195:                                        "Illegal argument calling method in create-object operation",
196:                                        module);
197:
198:                        String errMsg = "ERROR: Could not complete the "
199:                                + simpleMethod.getShortDescription()
200:                                + " process [Illegal argument calling constructor: "
201:                                + e.toString() + "]";
202:                        methodContext.setErrorReturn(errMsg, simpleMethod);
203:                        return false;
204:                    } catch (InvocationTargetException e) {
205:                        Debug
206:                                .logError(
207:                                        e.getTargetException(),
208:                                        "Constructor in create-object operation threw an exception",
209:                                        module);
210:
211:                        String errMsg = "ERROR: Could not complete the "
212:                                + simpleMethod.getShortDescription()
213:                                + " process [Constructor in create-object threw an exception: "
214:                                + e.getTargetException() + "]";
215:                        methodContext.setErrorReturn(errMsg, simpleMethod);
216:                        return false;
217:                    }
218:                } catch (NoSuchMethodException e) {
219:                    Debug
220:                            .logError(
221:                                    e,
222:                                    "Could not find constructor to execute in simple-method create-object operation",
223:                                    module);
224:
225:                    String errMsg = "ERROR: Could not complete the "
226:                            + simpleMethod.getShortDescription()
227:                            + " process [Could not find constructor to execute: "
228:                            + e.toString() + "]";
229:                    methodContext.setErrorReturn(errMsg, simpleMethod);
230:                    return false;
231:                } catch (SecurityException e) {
232:                    Debug
233:                            .logError(
234:                                    e,
235:                                    "Security exception finding constructor to execute in simple-method create-object operation",
236:                                    module);
237:
238:                    String errMsg = "ERROR: Could not complete the "
239:                            + simpleMethod.getShortDescription()
240:                            + " process [Security exception finding constructor to execute: "
241:                            + e.toString() + "]";
242:                    methodContext.setErrorReturn(errMsg, simpleMethod);
243:                    return false;
244:                }
245:
246:                return true;
247:            }
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.