Source Code Cross Referenced for KvpRequestReader.java in  » GIS » GeoServer » org » geoserver » ows » 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 » GIS » GeoServer » org.geoserver.ows 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.geoserver.ows;
006:
007:        import org.geoserver.ows.util.OwsUtils;
008:        import org.geotools.util.Converters;
009:
010:        import java.lang.reflect.Method;
011:        import java.util.Iterator;
012:        import java.util.Map;
013:        import java.util.logging.Logger;
014:
015:        /**
016:         * Creates a request bean from a kvp set.
017:         * <p>
018:         * A request bean is an object which captures the parameters of an operation
019:         * being requested to a service.
020:         * </p>
021:         * <p>
022:         * This class is intended to be subclassed in cases when the creation
023:         * and initilization of a request bean cannot be created reflectivley.
024:         * </p>
025:         * <p>
026:         * The type of the request bean must be declared by the class.
027:         * See {@link #getRequestBean()}.
028:         * </p>
029:         * <p>
030:         * Instances need to be declared in a spring context like the following:
031:         * <pre>
032:         *         <code>
033:         *    &lt;bean id="myKvpRequestReader" class="org.geoserver.ows.KvpRequestReader"&gt;
034:         *      &lt;constructor-arg value="com.xyz.MyRequestBean"/&gt;
035:         *    &lt;/bean&gt;
036:         *         </code>
037:         * </pre>
038:         * Where <code>com.xyz.MyRequestBean</code> is a simple java bean such as:
039:         * <pre>
040:         *         <code>
041:         *   public class MyRequestBean {
042:         *
043:         *      public void setX( Object x ) {
044:         *        ...
045:         *      }
046:         *
047:         *      public Object getX() {
048:         *        ...
049:         *      }
050:         *   }
051:         *         </code>
052:         * </pre>
053:         * </p>
054:         *
055:         * @author Justin Deoliveira, The Open Planning Project
056:         *
057:         */
058:        public class KvpRequestReader {
059:            /**
060:             * logging instance
061:             */
062:            protected static Logger LOGGER = org.geotools.util.logging.Logging
063:                    .getLogger("org.geoserver.ows");
064:
065:            /**
066:             * The class of the request bean
067:             */
068:            private Class requestBean;
069:
070:            /**
071:             * Creats the new kvp request reader.
072:             *
073:             * @param requestBean The type of the request read, not <code>null</code>
074:             */
075:            public KvpRequestReader(Class requestBean) {
076:                if (requestBean == null) {
077:                    throw new NullPointerException();
078:                }
079:
080:                this .requestBean = requestBean;
081:            }
082:
083:            /**
084:             * @return The class of the request bean.
085:             */
086:            public final Class getRequestBean() {
087:                return requestBean;
088:            }
089:
090:            /**
091:             * Creats a new instance of the request object.
092:             * <p>
093:             * Subclasses may with to override this method. The default implementation
094:             * attempts to reflectivley create an instance of the request bean.
095:             * </p>
096:             * @return A new instance of the request.
097:             */
098:            public Object createRequest() throws Exception {
099:                return getRequestBean().newInstance();
100:            }
101:
102:            /**
103:             * Reads the request from the set of kvp parameters.
104:             * <p>
105:             * Subclasses may wish to override this method. The default implementation
106:             * uses java bean reflection to populate the request bean with parameters
107:             * taken from the kvp map.
108:             * </p>
109:             * <p>
110:             * The "raw" (unparsed) kvp map is also made available.
111:             * </p>
112:             * <p>
113:             * This method may return a new instance of the request object, or the original
114:             * passed in.
115:             * </p>
116:             * @param request The request instance.
117:             * @param kvp The kvp set, map of String,Object.
118:             * @param rawKvp The raw kvp set (unparsed), map of String,String
119:             * 
120:             * @return A new request object, or the ori
121:             */
122:            public Object read(Object request, Map kvp, Map rawKvp)
123:                    throws Exception {
124:                for (Iterator e = kvp.entrySet().iterator(); e.hasNext();) {
125:                    Map.Entry entry = (Map.Entry) e.next();
126:                    String property = (String) entry.getKey();
127:                    Object value = entry.getValue();
128:
129:                    if (value == null) {
130:                        continue;
131:                    }
132:
133:                    Method setter = OwsUtils.setter(request.getClass(),
134:                            property, value.getClass());
135:
136:                    if (setter == null) {
137:                        //no setter matching the object of teh type, try to convert
138:                        setter = OwsUtils.setter(request.getClass(), property,
139:                                null);
140:                        if (setter != null) {
141:                            //convert
142:                            Class target = setter.getParameterTypes()[0];
143:                            Object converted = Converters
144:                                    .convert(value, target);
145:                            if (converted != null) {
146:                                value = converted;
147:                            } else {
148:                                setter = null;
149:                            }
150:                        }
151:                    }
152:
153:                    if (setter != null) {
154:                        setter.invoke(request, new Object[] { value });
155:                    }
156:                }
157:
158:                return request;
159:            }
160:
161:            /**
162:             * Equals override, equality is based on {@link #getRequestBean()}
163:             */
164:            public final boolean equals(Object obj) {
165:                if (obj instanceof  KvpRequestReader) {
166:                    KvpRequestReader other = (KvpRequestReader) obj;
167:
168:                    return requestBean == other.requestBean;
169:                }
170:
171:                return false;
172:            }
173:
174:            public final int hashCode() {
175:                return requestBean.hashCode();
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.