Source Code Cross Referenced for Utils.java in  » Workflow-Engines » OpenWFE » org » openwfe » gpe » xml » 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 » Workflow Engines » OpenWFE » org.openwfe.gpe.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 16.05.2005
003:         *
004:         */
005:        package org.openwfe.gpe.xml;
006:
007:        import java.lang.reflect.Field;
008:        import java.lang.reflect.InvocationTargetException;
009:        import java.lang.reflect.Method;
010:
011:        import org.eclipse.jface.dialogs.MessageDialog;
012:        import org.eclipse.ui.views.properties.IPropertyDescriptor;
013:        import org.jdom.Attribute;
014:        import org.jdom.Element;
015:        import org.openwfe.gpe.model.AbstractFlow;
016:        import org.openwfe.gpe.model.DefinedComposite;
017:        import org.openwfe.gpe.model.WorkflowElement;
018:
019:        /**
020:         * @author Helena
021:         *
022:         * This class contains utility methods for creating method names 
023:         * from the attibutes of the model classes or the XMl elements
024:         * Then the corresponding getter or setter methods are invoked
025:         */
026:
027:        public abstract class Utils {
028:
029:            public static String setMethodName(Attribute attribute) {
030:
031:                String methodName = "";
032:                Attribute el = (Attribute) attribute;
033:                String name = el.getName();
034:                String[] tab = name.split("-");
035:                if (tab.length != 0) {
036:                    String temp = tab[0].substring(0, 1).toUpperCase()
037:                            + tab[0].substring(1);
038:                    for (int j = 1; j < tab.length; j++) {
039:                        temp = temp + tab[j].substring(0, 1).toUpperCase()
040:                                + tab[j].substring(1);
041:                        ;
042:
043:                    }
044:                    name = temp;
045:                }
046:                methodName = name;
047:                return methodName;
048:            }
049:
050:            public static String getFieldName(Attribute attribute,
051:                    Object instance) {
052:                String fieldname = "";
053:                if (instance instanceof  DefinedComposite
054:                        || instance instanceof  WorkflowElement) {
055:                    if (attribute.getName().equalsIgnoreCase("name")) {
056:                        fieldname = "privateName";
057:                    } else {
058:                        fieldname = Utils.setMethodName(attribute);
059:                    }
060:                } else {
061:                    fieldname = Utils.setMethodName(attribute);
062:                }
063:                return fieldname;
064:            }
065:
066:            public static void setAttribute(Object o, String fieldname,
067:                    String value) {
068:
069:                Class clazz = o.getClass();
070:                Field field = null;
071:                String methodName = "set"
072:                        + fieldname.substring(0, 1).toUpperCase()
073:                        + fieldname.substring(1);
074:                Class partypes[] = new Class[1];
075:                partypes[0] = String.class;
076:                Method m = null;
077:                try {
078:                    m = clazz.getMethod(methodName, partypes);
079:                } catch (SecurityException e1) {
080:                    e1.printStackTrace();
081:                } catch (NoSuchMethodException e1) {
082:                    Hashtable_Creation map = new Hashtable_Creation();
083:                    MessageDialog.openInformation(null, "Alert",
084:                            "The attribute " + fieldname
085:                                    + " is undefined for element "
086:                                    + map.findElement(o));
087:                    return;
088:                    //e1.printStackTrace();
089:                }
090:                Object arglist[] = new Object[1];
091:                arglist[0] = new String(value);
092:                try {
093:                    m.invoke(o, arglist);
094:                } catch (IllegalArgumentException e2) {
095:                    e2.printStackTrace();
096:                } catch (IllegalAccessException e2) {
097:                    e2.printStackTrace();
098:                } catch (InvocationTargetException e2) {
099:                    e2.printStackTrace();
100:                }
101:            }
102:
103:            public static void getAttributes(Object element, Element current) {
104:                //Class clazz = element.getClass();
105:                AbstractFlow flow = (AbstractFlow) element;
106:                IPropertyDescriptor[] descriptors = flow
107:                        .getPropertyDescriptors();
108:                if (descriptors.length != 0) {
109:                    for (int i = 0; i < descriptors.length; i++) {
110:                        String methodName = getMethodName(descriptors[i]);
111:
112:                        try {
113:                            Object temp = getAttribute(flow, methodName);
114:                            String attr = (String) temp;
115:                            if (!(attr.equalsIgnoreCase("") || (flow instanceof  WorkflowElement && (descriptors[i]
116:                                    .getDisplayName().equalsIgnoreCase(
117:                                            WorkflowElement.DESCRIPTION) || descriptors[i]
118:                                    .getDisplayName().equalsIgnoreCase(
119:                                            WorkflowElement.LANGUAGE)))))
120:                                current.setAttribute(descriptors[i]
121:                                        .getDisplayName(), (String) temp);
122:                        } catch (SecurityException e) {
123:                            e.printStackTrace();
124:                        } catch (NoSuchMethodException e) {
125:                            e.printStackTrace();
126:                        } catch (InvocationTargetException e) {
127:                            e.printStackTrace();
128:                        } catch (IllegalAccessException e) {
129:                            e.printStackTrace();
130:                        }
131:                    }
132:                }
133:                return;
134:            }
135:
136:            public static String getMethodName(IPropertyDescriptor attribute) {
137:                String name = attribute.getId().toString();
138:                String[] tab = name.split("-");
139:                if (tab.length != 0) {
140:                    String temp = tab[0].substring(0, 1).toUpperCase()
141:                            + tab[0].substring(1);
142:                    for (int j = 1; j < tab.length; j++) {
143:                        temp = temp + tab[j].substring(0, 1).toUpperCase()
144:                                + tab[j].substring(1);
145:                        ;
146:                    }
147:                    name = temp;
148:                }
149:                String methodName = "get" + name;
150:                return methodName;
151:            }
152:
153:            public static Object getAttribute(Object o, String methodName)
154:                    throws SecurityException, NoSuchMethodException,
155:                    InvocationTargetException, IllegalAccessException,
156:                    InvocationTargetException {
157:                Class clazz = o.getClass();
158:                Method getMethod = clazz.getMethod(methodName, new Class[] {});
159:                return getMethod.invoke(o, new Object[] {});
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.