Source Code Cross Referenced for AbstractDynamicConverter.java in  » Search-Engine » compass-2.0 » org » compass » core » converter » dynamic » 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 » Search Engine » compass 2.0 » org.compass.core.converter.dynamic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.compass.core.converter.dynamic;
002:
003:        import java.lang.reflect.Array;
004:        import java.util.Collection;
005:        import java.util.Iterator;
006:
007:        import org.compass.core.Property;
008:        import org.compass.core.Resource;
009:        import org.compass.core.converter.ConversionException;
010:        import org.compass.core.converter.basic.AbstractBasicConverter;
011:        import org.compass.core.converter.basic.FormatConverter;
012:        import org.compass.core.mapping.Mapping;
013:        import org.compass.core.mapping.ResourcePropertyMapping;
014:        import org.compass.core.marshall.MarshallingContext;
015:
016:        /**
017:         * A simple base class for {@link DynamicConverter}. Requires implementation of
018:         * {@link #evaluate(Object,org.compass.core.mapping.ResourcePropertyMapping)}.
019:         *
020:         * <p>Also holds a {@link FormatConverter} for expression that return formatable
021:         * objects (like Date).
022:         *
023:         * @author kimchy
024:         */
025:        public abstract class AbstractDynamicConverter extends
026:                AbstractBasicConverter implements  DynamicConverter {
027:
028:            private FormatConverter formatConverter;
029:
030:            private Class type;
031:
032:            public DynamicConverter copy() {
033:                try {
034:                    DynamicConverter converter = (DynamicConverter) getClass()
035:                            .newInstance();
036:                    converter.setType(getType());
037:                    converter.setFormatConverter(formatConverter);
038:                    return converter;
039:                } catch (Exception e) {
040:                    throw new ConversionException("This should not happen", e);
041:                }
042:            }
043:
044:            public void setFormatConverter(FormatConverter formatConverter) {
045:                this .formatConverter = formatConverter;
046:            }
047:
048:            public boolean marshall(Resource resource, Object root,
049:                    Mapping mapping, MarshallingContext context)
050:                    throws ConversionException {
051:
052:                ResourcePropertyMapping resourcePropertyMapping = (ResourcePropertyMapping) mapping;
053:
054:                if (root == null) {
055:                    return false;
056:                }
057:                Object value = evaluate(root, resourcePropertyMapping);
058:                if (value == null) {
059:                    if (resourcePropertyMapping.hasNullValue()) {
060:                        addProperty(resourcePropertyMapping.getNullValue(),
061:                                resourcePropertyMapping, root, context,
062:                                resource);
063:                    }
064:                    return false;
065:                }
066:                // save the value in the search engine. Handle array/collection and single values
067:                if (value.getClass().isArray()) {
068:                    int length = Array.getLength(value);
069:                    for (int i = 0; i < length; i++) {
070:                        addProperty(Array.get(value, i),
071:                                resourcePropertyMapping, root, context,
072:                                resource);
073:                    }
074:                } else if (value instanceof  Collection) {
075:                    Collection colValues = (Collection) value;
076:                    for (Iterator it = colValues.iterator(); it.hasNext();) {
077:                        addProperty(it.next(), resourcePropertyMapping, root,
078:                                context, resource);
079:                    }
080:                } else {
081:                    addProperty(value, resourcePropertyMapping, root, context,
082:                            resource);
083:                }
084:                return resourcePropertyMapping.getStore() != Property.Store.NO;
085:            }
086:
087:            protected void addProperty(Object value,
088:                    ResourcePropertyMapping resourcePropertyMapping,
089:                    Object root, MarshallingContext context, Resource resource) {
090:                String sValue;
091:                if (formatConverter == null) {
092:                    sValue = value.toString();
093:                } else {
094:                    sValue = formatConverter.toString(value,
095:                            resourcePropertyMapping);
096:                }
097:                addProperty(sValue, resourcePropertyMapping, root, context,
098:                        resource);
099:            }
100:
101:            private void addProperty(String value,
102:                    ResourcePropertyMapping resourcePropertyMapping,
103:                    Object root, MarshallingContext context, Resource resource) {
104:                Property p = context.getResourceFactory().createProperty(value,
105:                        resourcePropertyMapping);
106:                doSetBoost(p, root, resourcePropertyMapping, context);
107:                resource.addProperty(p);
108:            }
109:
110:            /**
111:             * Evaluates the given data object using the configured expression.
112:             *
113:             * @param o                       The data object
114:             * @param resourcePropertyMapping The resource mapping
115:             * @return The object returned as a result of expression evaluation
116:             * @throws ConversionException
117:             */
118:            protected abstract Object evaluate(Object o,
119:                    ResourcePropertyMapping resourcePropertyMapping)
120:                    throws ConversionException;
121:
122:            /**
123:             * Does nothing since there is no meaning for un-marshalling for dynamic converters
124:             */
125:            public Object unmarshall(Resource resource, Mapping mapping,
126:                    MarshallingContext context) throws ConversionException {
127:                // nothing to do here
128:                return null;
129:            }
130:
131:            /**
132:             * Does nothing since there is no meaning for un-marshalling for dynamic converters
133:             */
134:            protected Object doFromString(String str,
135:                    ResourcePropertyMapping resourcePropertyMapping,
136:                    MarshallingContext context) throws ConversionException {
137:                // do nothing here
138:                return null;
139:            }
140:
141:            public Class getType() {
142:                return type;
143:            }
144:
145:            public void setType(Class type) {
146:                this.type = type;
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.