Source Code Cross Referenced for ValidatorMappingProcessor.java in  » Search-Engine » compass-2.0 » org » compass » core » config » process » 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.config.process 
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.config.process;
018:
019:        import java.util.Iterator;
020:
021:        import org.compass.core.config.CompassSettings;
022:        import org.compass.core.converter.ConverterLookup;
023:        import org.compass.core.engine.naming.PropertyNamingStrategy;
024:        import org.compass.core.mapping.CompassMapping;
025:        import org.compass.core.mapping.InvalidMappingException;
026:        import org.compass.core.mapping.Mapping;
027:        import org.compass.core.mapping.MappingException;
028:        import org.compass.core.mapping.ResourceMapping;
029:        import org.compass.core.mapping.ResourcePropertyMapping;
030:        import org.compass.core.mapping.osem.ClassMapping;
031:        import org.compass.core.mapping.osem.HasRefAliasMapping;
032:
033:        /**
034:         * @author kimchy
035:         */
036:        public class ValidatorMappingProcessor implements  MappingProcessor {
037:
038:            public CompassMapping process(CompassMapping compassMapping,
039:                    PropertyNamingStrategy namingStrategy,
040:                    ConverterLookup converterLookup, CompassSettings settings)
041:                    throws MappingException {
042:                ResourceMapping[] rootMappings = compassMapping
043:                        .getRootMappings();
044:                for (int i = 0; i < rootMappings.length; i++) {
045:                    ResourceMapping resourceMapping = rootMappings[i];
046:                    validateRootMapping(resourceMapping);
047:                }
048:                return compassMapping;
049:            }
050:
051:            private void validateRootMapping(ResourceMapping resourceMapping)
052:                    throws MappingException {
053:                validatieHasAtLeastOneId(resourceMapping);
054:                validateMulitRefAliasHasPoly(resourceMapping);
055:                String[] resourcePropertyNames = resourceMapping
056:                        .getResourcePropertyNames();
057:                for (int i = 0; i < resourcePropertyNames.length; i++) {
058:                    String propertyName = resourcePropertyNames[i];
059:                    ResourcePropertyMapping[] resourcePropertyMapping = resourceMapping
060:                            .getResourcePropertyMappings(propertyName);
061:                    validateDuplicateExcludeFromAll(resourceMapping,
062:                            propertyName, resourcePropertyMapping);
063:                    validateDuplicateAnalyzer(resourceMapping, propertyName,
064:                            resourcePropertyMapping);
065:                }
066:            }
067:
068:            private void validatieHasAtLeastOneId(
069:                    ResourceMapping resourceMapping) {
070:                Mapping[] idMappings = resourceMapping.getIdMappings();
071:                if (idMappings.length == 0) {
072:                    throw new MappingException(
073:                            "Mapping for alias ["
074:                                    + resourceMapping.getAlias()
075:                                    + "] has no id mappings defined. "
076:                                    + "Either you forgot to add id mappings for it, or it is a component mapping that requires no ids and it "
077:                                    + "is not configured with root=false");
078:                }
079:            }
080:
081:            private void validateMulitRefAliasHasPoly(
082:                    ResourceMapping resourceMapping) {
083:                if (!(resourceMapping instanceof  ClassMapping)) {
084:                    return;
085:                }
086:                ClassMapping classMapping = (ClassMapping) resourceMapping;
087:                for (Iterator it = classMapping.mappingsIt(); it.hasNext();) {
088:                    Mapping innerMapping = (Mapping) it.next();
089:                    if (innerMapping instanceof  HasRefAliasMapping) {
090:                        ClassMapping[] refMappings = ((HasRefAliasMapping) innerMapping)
091:                                .getRefClassMappings();
092:                        if (refMappings.length > 1) {
093:                            for (int i = 0; i < refMappings.length; i++) {
094:                                if (!refMappings[i].isPoly()) {
095:                                    throw new MappingException(
096:                                            "Mapping for alias ["
097:                                                    + classMapping.getAlias()
098:                                                    + "] and reference/component mapping ["
099:                                                    + innerMapping.getName()
100:                                                    + "] has more than one ref-alias mappings, but class mapping ["
101:                                                    + refMappings[i].getAlias()
102:                                                    + "] is not defined as poly");
103:                                }
104:                            }
105:                        }
106:                    }
107:                }
108:
109:            }
110:
111:            private void validateDuplicateExcludeFromAll(
112:                    ResourceMapping resourceMapping, String propertyName,
113:                    ResourcePropertyMapping[] resourcePropertyMapping)
114:                    throws MappingException {
115:                if (resourcePropertyMapping.length == 1) {
116:                    return;
117:                }
118:                ResourcePropertyMapping.ExcludeFromAllType excludeFromAll = resourcePropertyMapping[0]
119:                        .getExcludeFromAll();
120:                for (int i = 1; i < resourcePropertyMapping.length; i++) {
121:                    if (resourcePropertyMapping[i].isInternal()) {
122:                        continue;
123:                    }
124:                    if (excludeFromAll != resourcePropertyMapping[i]
125:                            .getExcludeFromAll()) {
126:                        throw new InvalidMappingException(
127:                                "Resource property / meta-data ["
128:                                        + propertyName
129:                                        + "] of alias ["
130:                                        + resourceMapping.getAlias()
131:                                        + "] has different exclude from all settings");
132:                    }
133:                }
134:            }
135:
136:            private void validateDuplicateAnalyzer(
137:                    ResourceMapping resourceMapping, String propertyName,
138:                    ResourcePropertyMapping[] resourcePropertyMapping)
139:                    throws MappingException {
140:                if (resourcePropertyMapping.length == 1) {
141:                    return;
142:                }
143:                boolean first = true;
144:                String lastAnalyzer = null;
145:                for (int i = 0; i < resourcePropertyMapping.length; i++) {
146:                    ResourcePropertyMapping propertyMapping = resourcePropertyMapping[i];
147:                    // don't worry about internal properties, since they have nothing to
148:                    // do with the analyzer
149:                    if (propertyMapping.isInternal()) {
150:                        continue;
151:                    }
152:                    if (propertyMapping.getAnalyzer() != null) {
153:                        if (lastAnalyzer == null && !first) {
154:                            // we passed several mappings with no analyzers, and now we
155:                            // found one that has
156:                            throw new InvalidMappingException(
157:                                    "Resource property / meta-data ["
158:                                            + propertyName
159:                                            + "] of alias ["
160:                                            + resourceMapping.getAlias()
161:                                            + "] has an anlyzer set, and some do not. Please set for all of them the same analyzer.");
162:                        }
163:                        if (first) {
164:                            lastAnalyzer = propertyMapping.getAnalyzer();
165:                        } else {
166:                            if (!propertyMapping.getAnalyzer().equals(
167:                                    lastAnalyzer)) {
168:                                throw new InvalidMappingException(
169:                                        "Resource property / meta-data ["
170:                                                + propertyName
171:                                                + "] of alias ["
172:                                                + resourceMapping.getAlias()
173:                                                + "] has several anlyzers set. Please set for all of them the same analyzer.");
174:                            }
175:                        }
176:                    } else {
177:                        if (lastAnalyzer != null) {
178:                            throw new InvalidMappingException(
179:                                    "Resource property / meta-data ["
180:                                            + propertyName
181:                                            + "] of alias ["
182:                                            + resourceMapping.getAlias()
183:                                            + "] has several anlyzers set. Please set for all of them the same analyzer.");
184:                        }
185:                    }
186:                    if (first) {
187:                        first = false;
188:                    }
189:                }
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.