Source Code Cross Referenced for BeanConvertor.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » forms » datatype » convertor » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.forms.datatype.convertor 
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.cocoon.forms.datatype.convertor;
018:
019:        import org.apache.avalon.framework.CascadingRuntimeException;
020:        import org.apache.commons.collections.map.ReferenceMap;
021:        import org.apache.commons.jxpath.JXPathContext;
022:
023:        import org.xml.sax.ContentHandler;
024:        import org.xml.sax.SAXException;
025:
026:        import java.util.Locale;
027:        import java.util.Map;
028:
029:        /**
030:         * Converts String representation of beans to bean instances and vice versa.
031:         * 
032:         * <p>
033:         * Sometimes the toString() method doesn't give a good representation of a
034:         * Java Bean suited for selection list IDs. For this an optional  
035:         * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to 
036:         * have this convertor to use a different string representation.
037:         * </p>
038:         *
039:         * @version $Id$
040:         */
041:        public class BeanConvertor implements  Convertor {
042:            //~ Instance fields --------------------------------------------------------
043:
044:            private Class m_class;
045:
046:            private Map m_objects = new ReferenceMap();
047:
048:            private String m_idPath;
049:
050:            //~ Constructors -----------------------------------------------------------
051:
052:            /**
053:             * Construct a new BeanConvertor for a class
054:             *
055:             * @param className The package-qualified name of the class implementing
056:             *        the typesafe enum pattern.
057:             * @param idPath Path to the identity field of the bean
058:             *
059:             * @throws CascadingRuntimeException If the class cannot be found
060:             */
061:            public BeanConvertor(final String className, final String idPath) {
062:                try {
063:                    m_class = Class.forName(className);
064:                } catch (ClassNotFoundException e) {
065:                    throw new CascadingRuntimeException("Class " + className
066:                            + " not found", e);
067:                }
068:
069:                m_idPath = idPath;
070:            }
071:
072:            //~ Methods ----------------------------------------------------------------
073:
074:            /**
075:             * @see org.apache.cocoon.forms.datatype.convertor.Convertor#getTypeClass()
076:             */
077:            public Class getTypeClass() {
078:                return m_class;
079:            }
080:
081:            /**
082:             * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertFromString(java.lang.String,
083:             *      java.util.Locale,
084:             *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
085:             */
086:            public ConversionResult convertFromString(final String value,
087:                    final Locale locale, final FormatCache formatCache) {
088:                return new ConversionResult(m_objects.get(value));
089:            }
090:
091:            /**
092:             * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertToString(java.lang.Object,
093:             *      java.util.Locale,
094:             *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
095:             */
096:            public String convertToString(final Object value,
097:                    final Locale locale, final FormatCache formatCache) {
098:                String idValue = "";
099:
100:                if (null != value) {
101:                    if (m_idPath != null) {
102:                        final JXPathContext ctx = JXPathContext
103:                                .newContext(value);
104:                        idValue = ctx.getValue(m_idPath).toString();
105:                    } else {
106:                        idValue = value.toString();
107:                    }
108:                }
109:
110:                m_objects.put(idValue, value);
111:
112:                return idValue;
113:            }
114:
115:            /**
116:             * We do not enerate any SAX events
117:             *
118:             * @param contentHandler The contentHandler
119:             * @param locale The locale
120:             *
121:             * @throws SAXException Just in case of failure that could never happen
122:             */
123:            public void generateSaxFragment(
124:                    final ContentHandler contentHandler, final Locale locale)
125:                    throws SAXException {
126:                // intentionally empty
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.