Source Code Cross Referenced for ObjectStringConverter.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » strategy » 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 » Library » Apache commons betwixt 0.8 src » org.apache.commons.betwixt.strategy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.betwixt.strategy;
018:
019:        import java.io.Serializable;
020:
021:        import org.apache.commons.betwixt.Options;
022:        import org.apache.commons.betwixt.expression.Context;
023:
024:        /** 
025:         * <p>Strategy class for string &lt;-&gt; object conversions.
026:         * Implementations of this interface are used by Betwixt to perform
027:         * string &lt;-&gt; object conversions.
028:         * This performs only the most basic conversions.
029:         * Most applications will use a subclass.
030:         * </p>
031:         * <p>It is strongly recommended that (in order to support round tripping)
032:         * that <code>objectToString</code> and <code>stringToObject</code>
033:         * are inverse functions.
034:         * In other words, given the same flavour, context and type the applying 
035:         * objectToString to the result of stringToObject should be equal to the 
036:         * original input.
037:         * </p>
038:         * @author Robert Burrell Donkin 
039:         * @since 0.5
040:         */
041:        public class ObjectStringConverter implements  Serializable {
042:
043:            /** Standard name for option giving flavour */
044:            public static final String FLAVOUR_OPTION_NAME = "org.apache.commons.betwixt.flavour";
045:
046:            /**
047:             * Converts an object to a string representation.
048:             * This basic implementation returns object.toString() 
049:             * or an empty string if the given object is null.
050:             *
051:             * @param object the object to be converted, possibly null
052:             * @param type the property class of the object, not null
053:             * @param flavour a string allow symantic differences in formatting to be communicated
054:             * @param context the context, not null
055:             * @deprecated 0.7 use {@link #objectToString(Object, Class, Context)} instead. 
056:             * The preferred way to support flavours is by setting the
057:             * <code>org.apache.commons.betwixt.FLAVOUR</code> option.
058:             * This can then be retrieved by calling {@link Context#getOptions()}
059:             * @return a String representation, not null
060:             */
061:            public String objectToString(Object object, Class type,
062:                    String flavour, Context context) {
063:                if (object != null) {
064:                    return object.toString();
065:                }
066:                return "";
067:            }
068:
069:            /**
070:             * Converts a string representation to an object.
071:             * It is acceptable for an implementation to return the string if it cannot convert 
072:             * the string to the given class type.
073:             * This basic implementation just returns a string.
074:             * 
075:             * @param value the String to be converted
076:             * @param type the property class to be returned (if possible), not null
077:             * @param flavour a string allow symantic differences in formatting to be communicated
078:             * @param context the context, not null
079:             * @deprecated 0.7 use {@link #stringToObject(String, Class, Context)} instead.
080:             * The preferred way to support flavours is by setting the
081:             * <code>org.apache.commons.betwixt.FLAVOUR</code> option.
082:             * This can then be retrieved by calling {@link Context#getOptions()}
083:             * @return an Object converted from the String, not null
084:             */
085:            public Object stringToObject(String value, Class type,
086:                    String flavour, Context context) {
087:                return value;
088:            }
089:
090:            /**
091:             * Converts an object to a string representation.
092:             * This basic implementation returns object.toString() 
093:             * or an empty string if the given object is null.
094:             *
095:             * @since 0.7
096:             * @param object the object to be converted, possibly null
097:             * @param type the property class of the object, not null
098:             * @param context the context, not null
099:             * @return a String representation, not null
100:             */
101:            public String objectToString(Object object, Class type,
102:                    Context context) {
103:                String flavour = getFlavour(context);
104:                return objectToString(object, type, flavour, context);
105:            }
106:
107:            /**
108:             * Converts a string representation to an object.
109:             * It is acceptable for an implementation to return the string if it cannot convert 
110:             * the string to the given class type.
111:             * This basic implementation just returns a string.
112:             * 
113:             * @since 0.7
114:             * @param value the String to be converted
115:             * @param type the property class to be returned (if possible), not null
116:             * @param context the context, not null
117:             * @return an Object converted from the String, not null
118:             */
119:            public Object stringToObject(String value, Class type,
120:                    Context context) {
121:                String flavour = getFlavour(context);
122:                return stringToObject(value, type, flavour, context);
123:            }
124:
125:            /**
126:             * Gets the current flavour from the context.
127:             * @param context <code>Context</code>, not null
128:             */
129:            private String getFlavour(Context context) {
130:                String flavour = null;
131:                Options options = context.getOptions();
132:                if (options != null) {
133:                    flavour = options.getValue(FLAVOUR_OPTION_NAME);
134:                }
135:                return flavour;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.