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


001:        /*
002:         * Copyright 2004-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.compass.core.converter.xsem;
018:
019:        import org.compass.core.Property;
020:        import org.compass.core.Resource;
021:        import org.compass.core.converter.ConversionException;
022:        import org.compass.core.converter.Converter;
023:        import org.compass.core.engine.naming.PropertyPath;
024:        import org.compass.core.mapping.Mapping;
025:        import org.compass.core.mapping.ResourcePropertyMapping;
026:        import org.compass.core.mapping.xsem.XmlPropertyMapping;
027:        import org.compass.core.marshall.MarshallingContext;
028:        import org.compass.core.xml.XmlObject;
029:
030:        /**
031:         * A simple converter which uses the String value of {@link org.compass.core.xml.XmlObject#getValue()}.
032:         * It is the deafult converter associated with the value converter of {@link XmlPropertyMapping} if none
033:         * is specified. It can also be used as a base class for more specialized converters.
034:         *
035:         * @author kimchy
036:         */
037:        public class SimpleXmlValueConverter implements  Converter {
038:
039:            public boolean marshall(Resource resource, Object root,
040:                    Mapping mapping, MarshallingContext context)
041:                    throws ConversionException {
042:                XmlPropertyMapping xmlPropertyMapping = (XmlPropertyMapping) mapping;
043:                // don't save a null value if the context does not states so
044:                if (root == null && !handleNulls(xmlPropertyMapping, context)) {
045:                    return false;
046:                }
047:                XmlObject xmlObject = (XmlObject) root;
048:                String sValue = getNullValue(xmlPropertyMapping, context);
049:                if (root != null) {
050:                    sValue = toString(xmlObject, xmlPropertyMapping);
051:                }
052:                PropertyPath path = xmlPropertyMapping.getPath();
053:                String propertyName = path == null ? null : path.getPath();
054:                if (propertyName == null) {
055:                    if (xmlObject == null) {
056:                        // nothing we can do here, no name, no nothing...
057:                        return false;
058:                    }
059:                    propertyName = xmlObject.getName();
060:                }
061:                Property p = context.getResourceFactory().createProperty(
062:                        propertyName, sValue, xmlPropertyMapping);
063:                doSetBoost(p, root, xmlPropertyMapping, context);
064:                resource.addProperty(p);
065:
066:                return xmlPropertyMapping.getStore() != Property.Store.NO;
067:            }
068:
069:            /**
070:             * <p>Should the converter handle nulls? Handling nulls means should the
071:             * converter process nulls or not. Usually the converter will not
072:             * persist null values, but sometimes it might be needed
073:             * ({@link org.compass.core.marshall.MarshallingContext#handleNulls()}).
074:             *
075:             * <p>If a specific null value is configured with the {@link org.compass.core.mapping.ResourcePropertyMapping}
076:             * then the converter will always handle nulls and write it.
077:             *
078:             * @param context The marshalling context
079:             * @return <code>true</code> if the converter should handle null values
080:             */
081:            protected boolean handleNulls(
082:                    ResourcePropertyMapping resourcePropertyMapping,
083:                    MarshallingContext context) {
084:                return resourcePropertyMapping.hasNullValue()
085:                        || context.handleNulls();
086:            }
087:
088:            /**
089:             * If the converter handle nulls, the value that will be stored in the
090:             * search engine for <code>null</code> values (during the marshall process). Uses
091:             * {@link org.compass.core.mapping.ResourcePropertyMapping#getNullValue()}.
092:             *
093:             * @param resourcePropertyMapping The resource proeprty mapping to get the null value from
094:             * @param context                 The marshalling context
095:             * @return Null value that will be inserted for <code>null</code>s.
096:             */
097:            protected String getNullValue(
098:                    ResourcePropertyMapping resourcePropertyMapping,
099:                    MarshallingContext context) {
100:                return resourcePropertyMapping.getNullValue();
101:            }
102:
103:            /**
104:             * A simple extension point that allows to set the boost value for the created {@link Property}.
105:             * <p/>
106:             * The default implemenation uses the statically defined boost value in the mapping definition
107:             * ({@link org.compass.core.mapping.ResourcePropertyMapping#getBoost()}) to set the boost level
108:             * using {@link Property#setBoost(float)}
109:             *
110:             * @param property                The property to set the boost on
111:             * @param root                    The object that is marshalled into a property
112:             * @param resourcePropertyMapping The Resource Property Mapping definition
113:             * @throws ConversionException
114:             */
115:            protected void doSetBoost(Property property, Object root,
116:                    ResourcePropertyMapping resourcePropertyMapping,
117:                    MarshallingContext context) throws ConversionException {
118:                property.setBoost(resourcePropertyMapping.getBoost());
119:            }
120:
121:            /**
122:             * Default implementation of toString, simply calls {@link org.compass.core.xml.XmlObject#getValue()}.
123:             */
124:            public String toString(XmlObject xmlObject,
125:                    ResourcePropertyMapping resourcePropertyMapping) {
126:                return xmlObject.getValue();
127:            }
128:
129:            /**
130:             * Not supported operation.
131:             */
132:            public Object unmarshall(Resource resource, Mapping mapping,
133:                    MarshallingContext context) throws ConversionException {
134:                return new ConversionException("Not supported");
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.