Source Code Cross Referenced for WrapperHelper.java in  » ESB » celtix-1.0 » org » objectweb » celtix » jaxb » 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 » ESB » celtix 1.0 » org.objectweb.celtix.jaxb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.jaxb;
002:
003:        import java.lang.reflect.Field;
004:        import java.lang.reflect.InvocationTargetException;
005:        import java.lang.reflect.Method;
006:        import java.util.Collection;
007:        import java.util.List;
008:
009:        import javax.xml.bind.annotation.XmlElement;
010:
011:        public final class WrapperHelper {
012:
013:            private WrapperHelper() {
014:                //complete
015:            }
016:
017:            public static void setWrappedPart(String partName,
018:                    Object wrapperType, Object part)
019:                    throws IllegalAccessException, NoSuchMethodException,
020:                    InvocationTargetException {
021:
022:                if (part instanceof  List) {
023:                    setWrappedListProperty(partName, wrapperType, part);
024:                } else {
025:                    String fieldName = partName;
026:                    if (JAXBUtils.isJavaKeyword(partName)) {
027:                        fieldName = JAXBUtils.nameToIdentifier(partName,
028:                                JAXBUtils.IdentifierType.VARIABLE);
029:                    }
030:
031:                    XmlElement el = null;
032:                    for (Field field : wrapperType.getClass()
033:                            .getDeclaredFields()) {
034:                        if (field.getName().equals(fieldName)) {
035:                            //JAXB Type get XmlElement Annotation
036:                            el = field.getAnnotation(XmlElement.class);
037:                            assert el != null;
038:                        }
039:                    }
040:
041:                    if (part == null) {
042:                        if (!el.nillable()) {
043:                            throw new IllegalArgumentException(
044:                                    "null value for field not permitted.");
045:                        }
046:                        return;
047:                    }
048:
049:                    String modifier = JAXBUtils.nameToIdentifier(partName,
050:                            JAXBUtils.IdentifierType.SETTER);
051:
052:                    boolean setInvoked = false;
053:                    for (Method method : wrapperType.getClass().getMethods()) {
054:                        if (method.getParameterTypes() != null
055:                                && method.getParameterTypes().length == 1
056:                                && modifier.equals(method.getName())) {
057:
058:                            Class<?> clazz = method.getParameterTypes()[0];
059:                            if (method.getParameterTypes()[0].isPrimitive()) {
060:                                clazz = el.type();
061:                            }
062:
063:                            if (clazz.isAssignableFrom(part.getClass())) {
064:                                method.invoke(wrapperType, part);
065:                                setInvoked = true;
066:                                break;
067:                            }
068:                        }
069:                    }
070:
071:                    if (!setInvoked) {
072:                        throw new IllegalArgumentException(
073:                                "Could not find a modifier method on Wrapper Type");
074:                    }
075:                }
076:            }
077:
078:            private static void setWrappedListProperty(String partName,
079:                    Object wrapperType, Object part)
080:                    throws IllegalAccessException, NoSuchMethodException,
081:                    InvocationTargetException {
082:
083:                String accessorName = JAXBUtils.nameToIdentifier(partName,
084:                        JAXBUtils.IdentifierType.GETTER);
085:                for (Method method : wrapperType.getClass().getMethods()) {
086:                    if (accessorName.equals(method.getName())
087:                            && List.class.isAssignableFrom(method
088:                                    .getReturnType())) {
089:
090:                        Object ret = method.invoke(wrapperType);
091:                        Method addAll = ret.getClass().getMethod("addAll",
092:                                Collection.class);
093:                        addAll.invoke(ret, part);
094:                        break;
095:                    }
096:                }
097:            }
098:
099:            public static Object getWrappedPart(String partName,
100:                    Object wrapperType, Class<?> partClazz)
101:                    throws IllegalAccessException, NoSuchMethodException,
102:                    InvocationTargetException {
103:
104:                String accessor = JAXBUtils.nameToIdentifier(partName,
105:                        JAXBUtils.IdentifierType.GETTER);
106:
107:                if (partClazz.equals(boolean.class)
108:                        || partClazz.equals(Boolean.class)) {
109:                    //JAXB Exception to get the Boolean property
110:                    accessor = accessor.replaceFirst("get", "is");
111:                }
112:
113:                for (Method method : wrapperType.getClass().getMethods()) {
114:                    if (method.getParameterTypes().length == 0
115:                            && accessor.equals(method.getName())) {
116:
117:                        Class<?> clazz = method.getReturnType();
118:
119:                        if (clazz.isPrimitive() && !partClazz.isPrimitive()) {
120:                            for (Field field : wrapperType.getClass()
121:                                    .getDeclaredFields()) {
122:                                if (JAXBUtils.isJavaKeyword(partName)) {
123:                                    partName = JAXBUtils.nameToIdentifier(
124:                                            partName,
125:                                            JAXBUtils.IdentifierType.VARIABLE);
126:                                }
127:                                if (field.getName().equals(partName)) {
128:                                    //JAXB Type get XmlElement Annotation
129:                                    clazz = field.getAnnotation(
130:                                            XmlElement.class).type();
131:                                }
132:                            }
133:                        }
134:                        //TODO Support For Nillable Attribute
135:                        if (clazz.isAssignableFrom(partClazz)) {
136:                            return method.invoke(wrapperType);
137:                        }
138:                    }
139:                }
140:                return null;
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.