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


0001:        /*
0002:         * Copyright 2004-2006 the original author or authors.
0003:         *
0004:         * Licensed under the Apache License, Version 2.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         *
0008:         *      http://www.apache.org/licenses/LICENSE-2.0
0009:         *
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.compass.core.config.binding;
0018:
0019:        import java.util.ArrayList;
0020:        import java.util.StringTokenizer;
0021:
0022:        import org.apache.commons.logging.Log;
0023:        import org.apache.commons.logging.LogFactory;
0024:        import org.compass.core.Property;
0025:        import org.compass.core.config.CommonMetaDataLookup;
0026:        import org.compass.core.config.CompassConfigurable;
0027:        import org.compass.core.config.CompassSettings;
0028:        import org.compass.core.config.ConfigurationException;
0029:        import org.compass.core.converter.mapping.osem.MetaDataFormatDelegateConverter;
0030:        import org.compass.core.engine.naming.StaticPropertyPath;
0031:        import org.compass.core.engine.subindex.ConstantSubIndexHash;
0032:        import org.compass.core.engine.subindex.SubIndexHash;
0033:        import org.compass.core.mapping.AbstractResourceMapping;
0034:        import org.compass.core.mapping.AliasMapping;
0035:        import org.compass.core.mapping.CascadeMapping;
0036:        import org.compass.core.mapping.CompassMapping;
0037:        import org.compass.core.mapping.ContractMapping;
0038:        import org.compass.core.mapping.Mapping;
0039:        import org.compass.core.mapping.MappingException;
0040:        import org.compass.core.mapping.ResourcePropertyMapping;
0041:        import org.compass.core.mapping.SpellCheckType;
0042:        import org.compass.core.mapping.internal.DefaultAllMapping;
0043:        import org.compass.core.mapping.internal.InternalResourceMapping;
0044:        import org.compass.core.mapping.internal.InternalResourcePropertyMapping;
0045:        import org.compass.core.mapping.osem.ClassBoostPropertyMapping;
0046:        import org.compass.core.mapping.osem.ClassIdPropertyMapping;
0047:        import org.compass.core.mapping.osem.ClassMapping;
0048:        import org.compass.core.mapping.osem.ClassPropertyAnalyzerController;
0049:        import org.compass.core.mapping.osem.ClassPropertyMapping;
0050:        import org.compass.core.mapping.osem.ClassPropertyMetaDataMapping;
0051:        import org.compass.core.mapping.osem.ComponentMapping;
0052:        import org.compass.core.mapping.osem.ConstantMetaDataMapping;
0053:        import org.compass.core.mapping.osem.DynamicMetaDataMapping;
0054:        import org.compass.core.mapping.osem.IdComponentMapping;
0055:        import org.compass.core.mapping.osem.ParentMapping;
0056:        import org.compass.core.mapping.osem.PlainCascadeMapping;
0057:        import org.compass.core.mapping.osem.ReferenceMapping;
0058:        import org.compass.core.mapping.rsem.RawBoostPropertyMapping;
0059:        import org.compass.core.mapping.rsem.RawResourceMapping;
0060:        import org.compass.core.mapping.rsem.RawResourcePropertyAnalyzerController;
0061:        import org.compass.core.mapping.rsem.RawResourcePropertyIdMapping;
0062:        import org.compass.core.mapping.rsem.RawResourcePropertyMapping;
0063:        import org.compass.core.mapping.xsem.XmlBoostPropertyMapping;
0064:        import org.compass.core.mapping.xsem.XmlContentMapping;
0065:        import org.compass.core.mapping.xsem.XmlIdMapping;
0066:        import org.compass.core.mapping.xsem.XmlObjectMapping;
0067:        import org.compass.core.mapping.xsem.XmlPropertyAnalyzerController;
0068:        import org.compass.core.mapping.xsem.XmlPropertyMapping;
0069:        import org.compass.core.metadata.Alias;
0070:        import org.compass.core.metadata.CompassMetaData;
0071:        import org.compass.core.util.ClassUtils;
0072:        import org.compass.core.util.DTDEntityResolver;
0073:        import org.compass.core.util.StringUtils;
0074:        import org.compass.core.util.config.ConfigurationHelper;
0075:        import org.xml.sax.EntityResolver;
0076:
0077:        /**
0078:         * @author kimchy
0079:         */
0080:        public class XmlMappingBinding extends AbstractXmlMappingBinding {
0081:
0082:            public static final Log log = LogFactory
0083:                    .getLog(XmlMappingBinding.class);
0084:
0085:            private CommonMetaDataLookup valueLookup;
0086:
0087:            public void setUpBinding(CompassMapping mapping,
0088:                    CompassMetaData metaData, CompassSettings settings) {
0089:                super .setUpBinding(mapping, metaData, settings);
0090:                this .valueLookup = new CommonMetaDataLookup(metaData);
0091:            }
0092:
0093:            protected EntityResolver doGetEntityResolver() {
0094:                return new DTDEntityResolver();
0095:            }
0096:
0097:            protected String getSuffix() {
0098:                return ".cpm.xml";
0099:            }
0100:
0101:            protected boolean doAddConfiguration(ConfigurationHelper doc)
0102:                    throws ConfigurationException, MappingException {
0103:                if (!doc.getName().equals("compass-core-mapping")) {
0104:                    return false;
0105:                }
0106:
0107:                String defaultPackage = doc.getAttribute("package", null);
0108:                if (defaultPackage != null) {
0109:                    defaultPackage = defaultPackage + ".";
0110:                } else {
0111:                    defaultPackage = "";
0112:                }
0113:                ConfigurationHelper[] contractArr = doc.getChildren("contract");
0114:                for (ConfigurationHelper aContractArr : contractArr) {
0115:                    ContractMapping contractMapping = new ContractMapping();
0116:                    bindContract(aContractArr, contractMapping);
0117:                    mapping.addMapping(contractMapping);
0118:                }
0119:                ConfigurationHelper[] resourceContractArr = doc
0120:                        .getChildren("resource-contract");
0121:                for (ConfigurationHelper aResourceContractArr : resourceContractArr) {
0122:                    ContractMapping contractMapping = new ContractMapping();
0123:                    bindResourceContract(aResourceContractArr, contractMapping);
0124:                    mapping.addMapping(contractMapping);
0125:                }
0126:                ConfigurationHelper[] classArr = doc.getChildren("class");
0127:                for (ConfigurationHelper classConf : classArr) {
0128:                    String alias = classConf.getAttribute("alias");
0129:                    boolean newClassMapping = false;
0130:                    ClassMapping classMapping;
0131:                    AliasMapping aliasMapping = mapping.getAliasMapping(alias);
0132:                    if (aliasMapping != null) {
0133:                        if (!(aliasMapping instanceof  ClassMapping)) {
0134:                            throw new MappingException(
0135:                                    "Defined searchable annotation on a class with alias ["
0136:                                            + alias + "] but it"
0137:                                            + " not of type class mapping");
0138:                        }
0139:                        classMapping = (ClassMapping) aliasMapping;
0140:                    } else {
0141:                        classMapping = new ClassMapping();
0142:                        newClassMapping = true;
0143:                    }
0144:                    bindClass(classConf, classMapping, defaultPackage);
0145:                    if (newClassMapping) {
0146:                        mapping.addMapping(classMapping);
0147:                    }
0148:                }
0149:                ConfigurationHelper[] resourceArr = doc.getChildren("resource");
0150:                for (ConfigurationHelper aResourceArr : resourceArr) {
0151:                    RawResourceMapping rawResourceMapping = new RawResourceMapping();
0152:                    bindResource(aResourceArr, rawResourceMapping);
0153:                    mapping.addMapping(rawResourceMapping);
0154:                }
0155:                ConfigurationHelper[] xmlObjectArr = doc
0156:                        .getChildren("xml-object");
0157:                for (ConfigurationHelper aXmlObjectArr : xmlObjectArr) {
0158:                    XmlObjectMapping xmlObjectMapping = new XmlObjectMapping();
0159:                    bindXmlObject(aXmlObjectArr, xmlObjectMapping);
0160:                    mapping.addMapping(xmlObjectMapping);
0161:                }
0162:
0163:                return true;
0164:            }
0165:
0166:            private void bindXmlObject(ConfigurationHelper xmlObjectConf,
0167:                    XmlObjectMapping xmlObjectMapping)
0168:                    throws ConfigurationException {
0169:                String aliasValue = xmlObjectConf.getAttribute("alias");
0170:                Alias alias = valueLookup.lookupAlias(aliasValue);
0171:                if (alias == null) {
0172:                    xmlObjectMapping.setAlias(aliasValue);
0173:                } else {
0174:                    xmlObjectMapping.setAlias(alias.getName());
0175:                }
0176:
0177:                bindSubIndexHash(xmlObjectConf, xmlObjectMapping);
0178:
0179:                bindExtends(xmlObjectConf, xmlObjectMapping);
0180:
0181:                bindAll(xmlObjectConf, xmlObjectMapping);
0182:                bindSpellCheck(xmlObjectConf, xmlObjectMapping);
0183:
0184:                String analyzer = xmlObjectConf.getAttribute("analyzer", null);
0185:                xmlObjectMapping.setAnalyzer(analyzer);
0186:
0187:                xmlObjectMapping.setRoot(true);
0188:                xmlObjectMapping.setBoost(getBoost(xmlObjectConf));
0189:
0190:                xmlObjectMapping.setXPath(xmlObjectConf.getAttribute("xpath",
0191:                        null));
0192:
0193:                bindConverter(xmlObjectConf, xmlObjectMapping);
0194:
0195:                bindXmlObjectChildren(xmlObjectConf, xmlObjectMapping);
0196:            }
0197:
0198:            private void bindXmlObjectChildren(
0199:                    ConfigurationHelper resourceConf,
0200:                    AliasMapping resourceMapping) {
0201:                ConfigurationHelper[] ids = resourceConf.getChildren("xml-id");
0202:                for (ConfigurationHelper id : ids) {
0203:                    XmlIdMapping xmlIdMapping = new XmlIdMapping();
0204:                    bindXmlProperty(id, xmlIdMapping, resourceMapping);
0205:                    resourceMapping.addMapping(xmlIdMapping);
0206:                }
0207:
0208:                ConfigurationHelper[] properties = resourceConf
0209:                        .getChildren("xml-property");
0210:                for (ConfigurationHelper property : properties) {
0211:                    XmlPropertyMapping xmlPropertyMapping = new XmlPropertyMapping();
0212:                    bindXmlProperty(property, xmlPropertyMapping,
0213:                            resourceMapping);
0214:                    resourceMapping.addMapping(xmlPropertyMapping);
0215:                }
0216:
0217:                ConfigurationHelper xmlContentConf = resourceConf.getChild(
0218:                        "xml-content", false);
0219:                if (xmlContentConf != null) {
0220:                    XmlContentMapping xmlContentMapping = new XmlContentMapping();
0221:                    bindXmlContent(xmlContentConf, xmlContentMapping);
0222:                    resourceMapping.addMapping(xmlContentMapping);
0223:                }
0224:
0225:                ConfigurationHelper analyzerConf = resourceConf.getChild(
0226:                        "xml-analyzer", false);
0227:                if (analyzerConf != null) {
0228:                    XmlPropertyAnalyzerController analyzerController = new XmlPropertyAnalyzerController();
0229:                    bindXmlProperty(analyzerConf, analyzerController,
0230:                            resourceMapping);
0231:                    analyzerController.setNullAnalyzer(analyzerConf
0232:                            .getAttribute("null-analyzer", null));
0233:                    resourceMapping.addMapping(analyzerController);
0234:                }
0235:
0236:                ConfigurationHelper boostConf = resourceConf.getChild(
0237:                        "xml-boost", false);
0238:                if (boostConf != null) {
0239:                    XmlBoostPropertyMapping boostPropertyMapping = new XmlBoostPropertyMapping();
0240:                    bindXmlProperty(boostConf, boostPropertyMapping,
0241:                            resourceMapping);
0242:                    String defaultBoost = boostConf.getAttribute("default",
0243:                            null);
0244:                    if (defaultBoost != null) {
0245:                        boostPropertyMapping.setDefaultBoost(Float
0246:                                .parseFloat(defaultBoost));
0247:                    }
0248:                    resourceMapping.addMapping(boostPropertyMapping);
0249:                }
0250:            }
0251:
0252:            private void bindXmlContent(ConfigurationHelper xmlContentConf,
0253:                    XmlContentMapping xmlContentMapping) {
0254:
0255:                String name = xmlContentConf.getAttribute("name", null);
0256:                if (name != null) {
0257:                    name = valueLookup.lookupMetaDataName(name);
0258:                }
0259:                xmlContentMapping.setName(name);
0260:                xmlContentMapping.setPath(new StaticPropertyPath(name));
0261:                bindConverter(xmlContentConf, xmlContentMapping);
0262:                String storeType = xmlContentConf.getAttribute("store", "yes");
0263:                xmlContentMapping
0264:                        .setStore(Property.Store.fromString(storeType));
0265:                xmlContentMapping.setInternal(true);
0266:            }
0267:
0268:            private void bindXmlProperty(ConfigurationHelper xmlPropConf,
0269:                    XmlPropertyMapping xmlPropertyMapping,
0270:                    AliasMapping aliasMapping) {
0271:                String name = xmlPropConf.getAttribute("name", null);
0272:                if (name != null) {
0273:                    name = valueLookup.lookupMetaDataName(name);
0274:                }
0275:                xmlPropertyMapping.setBoost(getBoost(xmlPropConf));
0276:                xmlPropertyMapping.setName(name);
0277:                xmlPropertyMapping.setPath((name == null ? null
0278:                        : new StaticPropertyPath(name)));
0279:                bindConverter(xmlPropConf, xmlPropertyMapping);
0280:                String storeType = xmlPropConf.getAttribute("store", "yes");
0281:                xmlPropertyMapping.setStore(Property.Store
0282:                        .fromString(storeType));
0283:                String indexType = xmlPropConf.getAttribute("index",
0284:                        "tokenized");
0285:                xmlPropertyMapping.setIndex(Property.Index
0286:                        .fromString(indexType));
0287:                String termVectorType = xmlPropConf.getAttribute("term-vector",
0288:                        "no");
0289:                xmlPropertyMapping.setTermVector(Property.TermVector
0290:                        .fromString(termVectorType));
0291:                boolean omitNorms = xmlPropConf.getAttributeAsBoolean(
0292:                        "omit-norms", false);
0293:                xmlPropertyMapping.setOmitNorms(omitNorms);
0294:                String reverseType = xmlPropConf.getAttribute("reverse", "no");
0295:                xmlPropertyMapping
0296:                        .setReverse(ResourcePropertyMapping.ReverseType
0297:                                .fromString(reverseType));
0298:                xmlPropertyMapping.setInternal(false);
0299:                xmlPropertyMapping.setAnalyzer(xmlPropConf.getAttribute(
0300:                        "analyzer", aliasMapping.getAnalyzer()));
0301:                xmlPropertyMapping.setNullValue(xmlPropConf.getAttribute(
0302:                        "null-value", null));
0303:                String excludeFromAll = xmlPropConf.getAttribute(
0304:                        "exclude-from-all", "no");
0305:                xmlPropertyMapping
0306:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0307:                                .fromString(excludeFromAll));
0308:                boolean override = xmlPropConf.getAttributeAsBoolean(
0309:                        "override", true);
0310:                xmlPropertyMapping.setOverrideByName(override);
0311:
0312:                xmlPropertyMapping.setXPath(xmlPropConf.getAttribute("xpath"));
0313:
0314:                xmlPropertyMapping.setValueConverterName(xmlPropConf
0315:                        .getAttribute("value-converter", null));
0316:
0317:                bindSpellCheck(xmlPropConf, xmlPropertyMapping);
0318:            }
0319:
0320:            private void bindResourceContract(ConfigurationHelper contractConf,
0321:                    ContractMapping contractMapping)
0322:                    throws ConfigurationException {
0323:                String aliasValue = contractConf.getAttribute("alias");
0324:                Alias alias = valueLookup.lookupAlias(aliasValue);
0325:                if (alias == null) {
0326:                    contractMapping.setAlias(aliasValue);
0327:                } else {
0328:                    contractMapping.setAlias(alias.getName());
0329:                }
0330:                bindExtends(contractConf, contractMapping);
0331:
0332:                bindResourceMappingChildren(contractConf, contractMapping);
0333:            }
0334:
0335:            private void bindResource(ConfigurationHelper resourceConf,
0336:                    RawResourceMapping rawResourceMapping)
0337:                    throws ConfigurationException {
0338:                String aliasValue = resourceConf.getAttribute("alias");
0339:                Alias alias = valueLookup.lookupAlias(aliasValue);
0340:                if (alias == null) {
0341:                    rawResourceMapping.setAlias(aliasValue);
0342:                } else {
0343:                    rawResourceMapping.setAlias(alias.getName());
0344:                }
0345:
0346:                bindSubIndexHash(resourceConf, rawResourceMapping);
0347:
0348:                bindExtends(resourceConf, rawResourceMapping);
0349:
0350:                String analyzer = resourceConf.getAttribute("analyzer", null);
0351:                rawResourceMapping.setAnalyzer(analyzer);
0352:
0353:                bindAll(resourceConf, rawResourceMapping);
0354:                bindSpellCheck(resourceConf, rawResourceMapping);
0355:
0356:                rawResourceMapping.setRoot(true);
0357:                rawResourceMapping.setBoost(getBoost(resourceConf));
0358:
0359:                bindResourceMappingChildren(resourceConf, rawResourceMapping);
0360:            }
0361:
0362:            private void bindResourceMappingChildren(
0363:                    ConfigurationHelper resourceConf,
0364:                    AliasMapping resourceMapping) {
0365:                ConfigurationHelper[] ids = resourceConf
0366:                        .getChildren("resource-id");
0367:                for (ConfigurationHelper id : ids) {
0368:                    RawResourcePropertyIdMapping rawIdPropertyMapping = new RawResourcePropertyIdMapping();
0369:                    bindResourceProperty(id, rawIdPropertyMapping,
0370:                            resourceMapping);
0371:                    resourceMapping.addMapping(rawIdPropertyMapping);
0372:                }
0373:
0374:                ConfigurationHelper[] properties = resourceConf
0375:                        .getChildren("resource-property");
0376:                for (ConfigurationHelper property : properties) {
0377:                    RawResourcePropertyMapping rawPropertyMapping = new RawResourcePropertyMapping();
0378:                    bindResourceProperty(property, rawPropertyMapping,
0379:                            resourceMapping);
0380:                    resourceMapping.addMapping(rawPropertyMapping);
0381:                }
0382:
0383:                ConfigurationHelper analyzerConf = resourceConf.getChild(
0384:                        "resource-analyzer", false);
0385:                if (analyzerConf != null) {
0386:                    RawResourcePropertyAnalyzerController analyzerController = new RawResourcePropertyAnalyzerController();
0387:                    bindResourceProperty(analyzerConf, analyzerController,
0388:                            resourceMapping);
0389:                    analyzerController.setNullAnalyzer(analyzerConf
0390:                            .getAttribute("null-analyzer", null));
0391:                    resourceMapping.addMapping(analyzerController);
0392:                }
0393:
0394:                ConfigurationHelper boostConf = resourceConf.getChild(
0395:                        "resource-boost", false);
0396:                if (boostConf != null) {
0397:                    RawBoostPropertyMapping boostPropertyMapping = new RawBoostPropertyMapping();
0398:                    bindResourceProperty(boostConf, boostPropertyMapping,
0399:                            resourceMapping);
0400:                    String defaultBoost = boostConf.getAttribute("default",
0401:                            null);
0402:                    if (defaultBoost != null) {
0403:                        boostPropertyMapping.setDefaultBoost(Float
0404:                                .parseFloat(defaultBoost));
0405:                    }
0406:                    resourceMapping.addMapping(boostPropertyMapping);
0407:                }
0408:            }
0409:
0410:            private void bindResourceProperty(
0411:                    ConfigurationHelper resourcePropConf,
0412:                    RawResourcePropertyMapping propertyMapping,
0413:                    AliasMapping aliasMapping) {
0414:                String name = valueLookup.lookupMetaDataName(resourcePropConf
0415:                        .getAttribute("name"));
0416:                propertyMapping.setBoost(getBoost(resourcePropConf));
0417:                propertyMapping.setName(name);
0418:                propertyMapping.setPath(new StaticPropertyPath(name));
0419:                bindConverter(resourcePropConf, propertyMapping);
0420:                String storeType = resourcePropConf
0421:                        .getAttribute("store", "yes");
0422:                propertyMapping.setStore(Property.Store.fromString(storeType));
0423:                String indexType = resourcePropConf.getAttribute("index",
0424:                        "tokenized");
0425:                propertyMapping.setIndex(Property.Index.fromString(indexType));
0426:                String termVectorType = resourcePropConf.getAttribute(
0427:                        "term-vector", "no");
0428:                propertyMapping.setTermVector(Property.TermVector
0429:                        .fromString(termVectorType));
0430:                boolean omitNorms = resourcePropConf.getAttributeAsBoolean(
0431:                        "omit-norms", false);
0432:                propertyMapping.setOmitNorms(omitNorms);
0433:                String reverseType = resourcePropConf.getAttribute("reverse",
0434:                        "no");
0435:                propertyMapping.setReverse(ResourcePropertyMapping.ReverseType
0436:                        .fromString(reverseType));
0437:                propertyMapping.setInternal(false);
0438:                propertyMapping.setAnalyzer(resourcePropConf.getAttribute(
0439:                        "analyzer", aliasMapping.getAnalyzer()));
0440:                propertyMapping.setNullValue(resourcePropConf.getAttribute(
0441:                        "null-value", null));
0442:                String excludeFromAll = resourcePropConf.getAttribute(
0443:                        "exclude-from-all", "no");
0444:                propertyMapping
0445:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0446:                                .fromString(excludeFromAll));
0447:                boolean override = resourcePropConf.getAttributeAsBoolean(
0448:                        "override", true);
0449:                propertyMapping.setOverrideByName(override);
0450:
0451:                bindSpellCheck(resourcePropConf, propertyMapping);
0452:            }
0453:
0454:            private void bindContract(ConfigurationHelper contractConf,
0455:                    ContractMapping contractMapping)
0456:                    throws ConfigurationException {
0457:                String aliasValue = contractConf.getAttribute("alias");
0458:                Alias alias = valueLookup.lookupAlias(aliasValue);
0459:                if (alias == null) {
0460:                    contractMapping.setAlias(aliasValue);
0461:                } else {
0462:                    contractMapping.setAlias(alias.getName());
0463:                }
0464:                bindExtends(contractConf, contractMapping);
0465:
0466:                bindClassMappingChildren(contractConf, contractMapping);
0467:            }
0468:
0469:            private void bindClass(ConfigurationHelper classConf,
0470:                    ClassMapping classMapping, String defaultPackage)
0471:                    throws ConfigurationException {
0472:                String className = classConf.getAttribute("name");
0473:                classMapping.setName(defaultPackage + className);
0474:                try {
0475:                    Class clazz = ClassUtils.forName(classMapping.getName(),
0476:                            settings.getClassLoader());
0477:                    classMapping.setClazz(clazz);
0478:                } catch (ClassNotFoundException e) {
0479:                    throw new ConfigurationException("Failed to find class ["
0480:                            + defaultPackage + classMapping.getName() + "]");
0481:                }
0482:
0483:                String aliasValue = classConf.getAttribute("alias");
0484:                Alias alias = valueLookup.lookupAlias(aliasValue);
0485:                if (alias == null) {
0486:                    classMapping.setAlias(aliasValue);
0487:                } else {
0488:                    classMapping.setAlias(alias.getName());
0489:                }
0490:
0491:                bindExtends(classConf, classMapping);
0492:
0493:                bindSubIndexHash(classConf, classMapping);
0494:
0495:                String analyzer = classConf.getAttribute("analyzer", null);
0496:                classMapping.setAnalyzer(analyzer);
0497:
0498:                bindAll(classConf, classMapping);
0499:                bindSpellCheck(classConf, classMapping);
0500:
0501:                boolean poly = classConf.getAttributeAsBoolean("poly", false);
0502:                classMapping.setPoly(poly);
0503:
0504:                String managedId = classConf.getAttribute("managed-id", null);
0505:                if (managedId != null) {
0506:                    classMapping.setManagedId(ClassPropertyMapping.ManagedId
0507:                            .fromString(managedId));
0508:                }
0509:
0510:                String polyClassName = classConf.getAttribute("poly-class",
0511:                        null);
0512:                if (polyClassName != null) {
0513:                    try {
0514:                        classMapping.setPolyClass(ClassUtils.forName(
0515:                                polyClassName, settings.getClassLoader()));
0516:                    } catch (ClassNotFoundException e) {
0517:                        throw new ConfigurationException(
0518:                                "Failed to load polyClass [" + polyClassName
0519:                                        + "]", e);
0520:                    }
0521:                }
0522:
0523:                boolean root = classConf.getAttributeAsBoolean("root", true);
0524:                classMapping.setRoot(root);
0525:                classMapping.setBoost(getBoost(classConf));
0526:
0527:                // don't set support unmarshall unless it is set, since it might be globally set
0528:                String supportUnmarshall = classConf.getAttribute(
0529:                        "support-unmarshall", null);
0530:                if (supportUnmarshall != null) {
0531:                    if (supportUnmarshall.equalsIgnoreCase("true")) {
0532:                        classMapping.setSupportUnmarshall(true);
0533:                    } else {
0534:                        classMapping.setSupportUnmarshall(false);
0535:                    }
0536:                }
0537:
0538:                bindConverter(classConf, classMapping);
0539:
0540:                bindClassMappingChildren(classConf, classMapping);
0541:            }
0542:
0543:            private void bindClassMappingChildren(
0544:                    ConfigurationHelper classConf, AliasMapping classMapping) {
0545:                ConfigurationHelper[] ids = classConf.getChildren("id");
0546:                for (ConfigurationHelper id : ids) {
0547:                    ClassIdPropertyMapping idMapping = new ClassIdPropertyMapping();
0548:                    bindClassProperty(id, classMapping, idMapping);
0549:                    classMapping.addMapping(idMapping);
0550:                }
0551:                ConfigurationHelper[] idComponents = classConf
0552:                        .getChildren("id-component");
0553:                for (ConfigurationHelper idComponent : idComponents) {
0554:                    IdComponentMapping idMapping = new IdComponentMapping();
0555:                    bindComponent(idComponent, classMapping, idMapping);
0556:                    classMapping.addMapping(idMapping);
0557:                }
0558:                ConfigurationHelper[] properties = classConf
0559:                        .getChildren("property");
0560:                for (ConfigurationHelper property : properties) {
0561:                    ClassPropertyMapping classPropertyMapping = new ClassPropertyMapping();
0562:                    bindClassProperty(property, classMapping,
0563:                            classPropertyMapping);
0564:                    classMapping.addMapping(classPropertyMapping);
0565:                }
0566:                ConfigurationHelper[] components = classConf
0567:                        .getChildren("component");
0568:                for (ConfigurationHelper component : components) {
0569:                    ComponentMapping compMapping = new ComponentMapping();
0570:                    bindComponent(component, classMapping, compMapping);
0571:                    classMapping.addMapping(compMapping);
0572:                }
0573:                ConfigurationHelper[] references = classConf
0574:                        .getChildren("reference");
0575:                for (ConfigurationHelper reference : references) {
0576:                    ReferenceMapping referenceMapping = new ReferenceMapping();
0577:                    bindReference(reference, classMapping, referenceMapping);
0578:                    classMapping.addMapping(referenceMapping);
0579:                }
0580:                ConfigurationHelper[] constants = classConf
0581:                        .getChildren("constant");
0582:                for (ConfigurationHelper constant : constants) {
0583:                    ConstantMetaDataMapping constantMapping = new ConstantMetaDataMapping();
0584:                    bindConstant(constant, classMapping, constantMapping);
0585:                    classMapping.addMapping(constantMapping);
0586:                }
0587:                ConfigurationHelper parentConf = classConf.getChild("parent",
0588:                        false);
0589:                if (parentConf != null) {
0590:                    ParentMapping parentMapping = new ParentMapping();
0591:                    bindParent(parentConf, classMapping, parentMapping);
0592:                    classMapping.addMapping(parentMapping);
0593:                }
0594:
0595:                ConfigurationHelper analyzerConf = classConf.getChild(
0596:                        "analyzer", false);
0597:                if (analyzerConf != null) {
0598:                    ClassPropertyAnalyzerController analyzerController = new ClassPropertyAnalyzerController();
0599:                    bindClassProperty(analyzerConf, classMapping,
0600:                            analyzerController);
0601:                    analyzerController.setNullAnalyzer(analyzerConf
0602:                            .getAttribute("null-analyzer", null));
0603:                    classMapping.addMapping(analyzerController);
0604:                }
0605:
0606:                ConfigurationHelper boostConf = classConf.getChild("boost",
0607:                        false);
0608:                if (boostConf != null) {
0609:                    ClassBoostPropertyMapping boostPropertyMapping = new ClassBoostPropertyMapping();
0610:                    bindClassProperty(boostConf, classMapping,
0611:                            boostPropertyMapping);
0612:                    String defaultBoost = boostConf.getAttribute("default",
0613:                            null);
0614:                    if (defaultBoost != null) {
0615:                        boostPropertyMapping.setDefaultBoost(Float
0616:                                .parseFloat(defaultBoost));
0617:                    }
0618:                    classMapping.addMapping(boostPropertyMapping);
0619:                }
0620:
0621:                ConfigurationHelper[] dynamicConfs = classConf
0622:                        .getChildren("dynamic-meta-data");
0623:                for (ConfigurationHelper dynamicConf : dynamicConfs) {
0624:                    DynamicMetaDataMapping dynamicMetaDataMapping = new DynamicMetaDataMapping();
0625:                    bindDynamicMetaData(dynamicConf, classMapping,
0626:                            dynamicMetaDataMapping);
0627:                    classMapping.addMapping(dynamicMetaDataMapping);
0628:                }
0629:
0630:                ConfigurationHelper[] cascadeConfs = classConf
0631:                        .getChildren("cascade");
0632:                for (ConfigurationHelper cascadeConf : cascadeConfs) {
0633:                    PlainCascadeMapping cascadeMapping = new PlainCascadeMapping();
0634:                    bindPlainCascading(cascadeConf, cascadeMapping);
0635:                    classMapping.addMapping(cascadeMapping);
0636:                }
0637:            }
0638:
0639:            private void bindPlainCascading(ConfigurationHelper conf,
0640:                    PlainCascadeMapping cascadeMapping) {
0641:                String name = conf.getAttribute("name");
0642:                cascadeMapping.setName(name);
0643:
0644:                cascadeMapping.setAccessor(conf.getAttribute("accessor", null));
0645:                cascadeMapping.setPropertyName(name);
0646:
0647:                bindConverter(conf, cascadeMapping);
0648:                bindCascade(conf, cascadeMapping);
0649:            }
0650:
0651:            private void bindDynamicMetaData(ConfigurationHelper dynamicConf,
0652:                    AliasMapping aliasMapping,
0653:                    DynamicMetaDataMapping dynamicMetaDataMapping) {
0654:                String name = valueLookup.lookupMetaDataName(dynamicConf
0655:                        .getAttribute("name"));
0656:                dynamicMetaDataMapping.setBoost(getBoost(dynamicConf));
0657:                dynamicMetaDataMapping.setName(name);
0658:                dynamicMetaDataMapping.setPath(new StaticPropertyPath(name));
0659:
0660:                dynamicMetaDataMapping.setExpression(dynamicConf.getValue()
0661:                        .trim());
0662:
0663:                dynamicMetaDataMapping.setFormat(dynamicConf.getAttribute(
0664:                        "format", null));
0665:                String type = dynamicConf.getAttribute("type", null);
0666:                if (type != null) {
0667:                    try {
0668:                        dynamicMetaDataMapping.setType(ClassUtils.forName(type,
0669:                                settings.getClassLoader()));
0670:                    } catch (ClassNotFoundException e) {
0671:                        throw new MappingException("Failed to find class ["
0672:                                + type + "]", e);
0673:                    }
0674:                }
0675:
0676:                bindConverter(dynamicConf, dynamicMetaDataMapping);
0677:                bindSpellCheck(dynamicConf, dynamicMetaDataMapping);
0678:
0679:                boolean override = dynamicConf.getAttributeAsBoolean(
0680:                        "override", true);
0681:                dynamicMetaDataMapping.setOverrideByName(override);
0682:
0683:                String storeType = dynamicConf.getAttribute("store", "yes");
0684:                dynamicMetaDataMapping.setStore(Property.Store
0685:                        .fromString(storeType));
0686:                String indexType = dynamicConf.getAttribute("index",
0687:                        "tokenized");
0688:                dynamicMetaDataMapping.setIndex(Property.Index
0689:                        .fromString(indexType));
0690:                String termVectorType = dynamicConf.getAttribute("term-vector",
0691:                        "no");
0692:                dynamicMetaDataMapping.setTermVector(Property.TermVector
0693:                        .fromString(termVectorType));
0694:                boolean omitNorms = dynamicConf.getAttributeAsBoolean(
0695:                        "omit-norms", false);
0696:                dynamicMetaDataMapping.setOmitNorms(omitNorms);
0697:                String reverseType = dynamicConf.getAttribute("reverse", "no");
0698:                dynamicMetaDataMapping
0699:                        .setReverse(ResourcePropertyMapping.ReverseType
0700:                                .fromString(reverseType));
0701:                dynamicMetaDataMapping.setInternal(false);
0702:                dynamicMetaDataMapping.setAnalyzer(dynamicConf.getAttribute(
0703:                        "analyzer", aliasMapping.getAnalyzer()));
0704:                dynamicMetaDataMapping.setNullValue(dynamicConf.getAttribute(
0705:                        "null-value", null));
0706:                String excludeFromAll = dynamicConf.getAttribute(
0707:                        "exclude-from-all", "no");
0708:                dynamicMetaDataMapping
0709:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0710:                                .fromString(excludeFromAll));
0711:            }
0712:
0713:            private void bindReference(ConfigurationHelper referenceConf,
0714:                    AliasMapping aliasMapping, ReferenceMapping referenceMapping) {
0715:                String name = referenceConf.getAttribute("name");
0716:                referenceMapping.setName(name);
0717:
0718:                String refAlias = referenceConf.getAttribute("ref-alias", null);
0719:                referenceMapping.setRefAliases(getAliases(refAlias));
0720:                referenceMapping.setDefinedInAlias(aliasMapping.getAlias());
0721:
0722:                String refCompAlias = referenceConf.getAttribute(
0723:                        "ref-comp-alias", null);
0724:                if (refCompAlias != null) {
0725:                    referenceMapping.setRefCompAlias(valueLookup
0726:                            .lookupAliasName(refCompAlias));
0727:                }
0728:
0729:                bindConverter(referenceConf, referenceMapping);
0730:
0731:                referenceMapping.setAccessor(referenceConf.getAttribute(
0732:                        "accessor", null));
0733:                referenceMapping.setPropertyName(name);
0734:
0735:                bindCascade(referenceConf, referenceMapping);
0736:            }
0737:
0738:            private void bindComponent(ConfigurationHelper componentConf,
0739:                    AliasMapping aliasMapping, ComponentMapping compMapping) {
0740:                String name = componentConf.getAttribute("name");
0741:                compMapping.setName(name);
0742:                String refAlias = componentConf.getAttribute("ref-alias", null);
0743:                compMapping.setRefAliases(getAliases(refAlias));
0744:                compMapping.setDefinedInAlias(aliasMapping.getAlias());
0745:
0746:                int maxDepth = componentConf.getAttributeAsInteger("max-depth",
0747:                        1);
0748:                compMapping.setMaxDepth(maxDepth);
0749:
0750:                bindConverter(componentConf, compMapping);
0751:
0752:                compMapping.setAccessor(componentConf.getAttribute("accessor",
0753:                        null));
0754:                compMapping.setPropertyName(name);
0755:
0756:                boolean override = componentConf.getAttributeAsBoolean(
0757:                        "override", true);
0758:                compMapping.setOverrideByName(override);
0759:
0760:                bindCascade(componentConf, compMapping);
0761:            }
0762:
0763:            private void bindCascade(ConfigurationHelper refConf,
0764:                    CascadeMapping cascadeMapping) {
0765:                String commaSeparatedCascades = refConf.getAttribute("cascade",
0766:                        null);
0767:                if (commaSeparatedCascades == null) {
0768:                    return;
0769:                }
0770:                ArrayList<CascadeMapping.Cascade> cascades = new ArrayList<CascadeMapping.Cascade>();
0771:                StringTokenizer st = new StringTokenizer(
0772:                        commaSeparatedCascades, ",");
0773:                while (st.hasMoreTokens()) {
0774:                    String cascade = st.nextToken().trim();
0775:                    cascades.add(CascadeMapping.Cascade.fromString(cascade));
0776:                }
0777:                if (cascades.size() > 0) {
0778:                    cascadeMapping
0779:                            .setCascades(cascades
0780:                                    .toArray(new CascadeMapping.Cascade[cascades
0781:                                            .size()]));
0782:                }
0783:            }
0784:
0785:            private void bindParent(ConfigurationHelper parentConf,
0786:                    AliasMapping aliasMapping, ParentMapping parentMapping) {
0787:                String name = parentConf.getAttribute("name");
0788:                parentMapping.setName(name);
0789:                bindConverter(parentConf, parentMapping);
0790:
0791:                parentMapping.setAccessor(parentConf.getAttribute("accessor",
0792:                        null));
0793:                parentMapping.setPropertyName(name);
0794:                parentMapping.setDefinedInAlias(aliasMapping.getAlias());
0795:
0796:                bindCascade(parentConf, parentMapping);
0797:            }
0798:
0799:            private void bindClassProperty(
0800:                    ConfigurationHelper classPropertyConf,
0801:                    AliasMapping aliasMapping,
0802:                    ClassPropertyMapping classPropertyMapping) {
0803:                String name = classPropertyConf.getAttribute("name");
0804:                classPropertyMapping.setName(name);
0805:
0806:                String sClass = classPropertyConf.getAttribute("class", null);
0807:                classPropertyMapping.setClassName(sClass);
0808:                classPropertyMapping.setDefinedInAlias(aliasMapping.getAlias());
0809:
0810:                classPropertyMapping.setBoost(getBoost(classPropertyConf));
0811:
0812:                classPropertyMapping.setColClassName(classPropertyConf
0813:                        .getAttribute("col-class", null));
0814:
0815:                classPropertyMapping.setAccessor(classPropertyConf
0816:                        .getAttribute("accessor", null));
0817:                classPropertyMapping.setPropertyName(name);
0818:
0819:                classPropertyMapping.setAnalyzer(classPropertyConf
0820:                        .getAttribute("analyzer", aliasMapping.getAnalyzer()));
0821:
0822:                String excludeFromAll = classPropertyConf.getAttribute(
0823:                        "exclude-from-all", "no");
0824:                classPropertyMapping
0825:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0826:                                .fromString(excludeFromAll));
0827:
0828:                String managedId = classPropertyConf.getAttribute("managed-id",
0829:                        null);
0830:                if (managedId != null) {
0831:                    classPropertyMapping
0832:                            .setManagedId(ClassPropertyMapping.ManagedId
0833:                                    .fromString(managedId));
0834:                }
0835:
0836:                String managedIdIndex = classPropertyConf.getAttribute(
0837:                        "managed-id-index", null);
0838:                if (managedIdIndex != null) {
0839:                    classPropertyMapping.setManagedIdIndex(Property.Index
0840:                            .fromString(managedIdIndex));
0841:                }
0842:                classPropertyMapping
0843:                        .setManagedIdConverterName(classPropertyConf
0844:                                .getAttribute("managed-id-converter", null));
0845:
0846:                boolean override = classPropertyConf.getAttributeAsBoolean(
0847:                        "override", true);
0848:                classPropertyMapping.setOverrideByName(override);
0849:
0850:                bindConverter(classPropertyConf, classPropertyMapping);
0851:
0852:                ConfigurationHelper[] metadatas = classPropertyConf
0853:                        .getChildren("meta-data");
0854:                for (ConfigurationHelper metadata : metadatas) {
0855:                    ClassPropertyMetaDataMapping mdMapping = new ClassPropertyMetaDataMapping();
0856:                    bindMetaData(metadata, aliasMapping, classPropertyMapping,
0857:                            mdMapping);
0858:                    classPropertyMapping.addMapping(mdMapping);
0859:                }
0860:            }
0861:
0862:            private void bindConstant(ConfigurationHelper constantConf,
0863:                    AliasMapping classMapping,
0864:                    ConstantMetaDataMapping constantMapping) {
0865:                ConfigurationHelper metadataConf = constantConf
0866:                        .getChild("meta-data");
0867:                if (!StringUtils.hasText(metadataConf.getValue())) {
0868:                    throw new MappingException(
0869:                            "Alias mapping ["
0870:                                    + classMapping.getAlias()
0871:                                    + "] has a constant mapping with an empty meta-data value");
0872:                }
0873:                String metaDataValue = metadataConf.getValue().trim();
0874:                constantMapping.setName(valueLookup
0875:                        .lookupMetaDataName(metaDataValue));
0876:                constantMapping.setBoost(getBoost(metadataConf, 1.0f));
0877:                String storeType = metadataConf.getAttribute("store", "yes");
0878:                constantMapping.setStore(Property.Store.fromString(storeType));
0879:                String indexType = metadataConf.getAttribute("index",
0880:                        "tokenized");
0881:                constantMapping.setIndex(Property.Index.fromString(indexType));
0882:                String termVectorType = metadataConf.getAttribute(
0883:                        "term-vector", "no");
0884:                constantMapping.setTermVector(Property.TermVector
0885:                        .fromString(termVectorType));
0886:                boolean omitNorms = metadataConf.getAttributeAsBoolean(
0887:                        "omit-norms", false);
0888:                constantMapping.setOmitNorms(omitNorms);
0889:
0890:                constantMapping.setAnalyzer(constantConf.getAttribute(
0891:                        "analyzer", classMapping.getAnalyzer()));
0892:
0893:                String excludeFromAll = constantConf.getAttribute(
0894:                        "exclude-from-all", "no");
0895:                constantMapping
0896:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0897:                                .fromString(excludeFromAll));
0898:
0899:                boolean override = constantConf.getAttributeAsBoolean(
0900:                        "override", true);
0901:                constantMapping.setOverrideByName(override);
0902:
0903:                bindSpellCheck(constantConf, constantMapping);
0904:
0905:                ConfigurationHelper[] values = constantConf
0906:                        .getChildren("meta-data-value");
0907:                for (ConfigurationHelper value : values) {
0908:                    String metaDataValueValue = value.getValue().trim();
0909:                    constantMapping.addMetaDataValue(valueLookup
0910:                            .lookupMetaDataValue(metaDataValueValue));
0911:                }
0912:            }
0913:
0914:            private void bindMetaData(ConfigurationHelper metadataConf,
0915:                    AliasMapping aliasMapping,
0916:                    ClassPropertyMapping classPropertyMapping,
0917:                    ClassPropertyMetaDataMapping mdMapping) {
0918:                if (!StringUtils.hasText(metadataConf.getValue())) {
0919:                    throw new MappingException("Alias mapping ["
0920:                            + aliasMapping.getAlias() + "] and property ["
0921:                            + classPropertyMapping.getName()
0922:                            + "] has a meta-data mapping with no value");
0923:                }
0924:                String name = valueLookup.lookupMetaDataName(metadataConf
0925:                        .getValue().trim());
0926:                mdMapping.setBoost(getBoost(metadataConf, classPropertyMapping
0927:                        .getBoost()));
0928:                mdMapping.setName(name);
0929:                mdMapping.setPath(new StaticPropertyPath(name));
0930:
0931:                mdMapping.setAccessor(classPropertyMapping.getAccessor());
0932:                mdMapping.setPropertyName(classPropertyMapping
0933:                        .getPropertyName());
0934:
0935:                bindConverter(metadataConf, mdMapping);
0936:                String format = metadataConf.getAttribute("format", null);
0937:                if (mdMapping.getConverter() == null) {
0938:                    if (format == null) {
0939:                        format = valueLookup.lookupMetaDataFormat(metadataConf
0940:                                .getValue().trim());
0941:                    }
0942:                    if (format != null) {
0943:                        mdMapping
0944:                                .setConverter(new MetaDataFormatDelegateConverter(
0945:                                        format));
0946:                    }
0947:                } else {
0948:                    // just validate that both are not set, since it makes no sense
0949:                    if (format != null) {
0950:                        throw new ConfigurationException(
0951:                                "Both converter and format are set for property ["
0952:                                        + classPropertyMapping.getName()
0953:                                        + "], you should choose one or the other (since converter will"
0954:                                        + "not use the format defined)");
0955:                    }
0956:                }
0957:
0958:                String storeType = metadataConf.getAttribute("store", "yes");
0959:                mdMapping.setStore(Property.Store.fromString(storeType));
0960:                String indexType = metadataConf.getAttribute("index",
0961:                        "tokenized");
0962:                mdMapping.setIndex(Property.Index.fromString(indexType));
0963:                String termVectorType = metadataConf.getAttribute(
0964:                        "term-vector", "no");
0965:                mdMapping.setTermVector(Property.TermVector
0966:                        .fromString(termVectorType));
0967:                boolean omitNorms = metadataConf.getAttributeAsBoolean(
0968:                        "omit-norms", false);
0969:                mdMapping.setOmitNorms(omitNorms);
0970:                String reverseType = metadataConf.getAttribute("reverse", "no");
0971:                mdMapping.setReverse(ResourcePropertyMapping.ReverseType
0972:                        .fromString(reverseType));
0973:                mdMapping.setInternal(false);
0974:                mdMapping.setAnalyzer(metadataConf.getAttribute("analyzer",
0975:                        classPropertyMapping.getAnalyzer()));
0976:                mdMapping.setNullValue(metadataConf.getAttribute("null-value",
0977:                        null));
0978:                String excludeFromAll = metadataConf.getAttribute(
0979:                        "exclude-from-all",
0980:                        ResourcePropertyMapping.ExcludeFromAllType
0981:                                .toString(classPropertyMapping
0982:                                        .getExcludeFromAll()));
0983:                mdMapping
0984:                        .setExcludeFromAll(ResourcePropertyMapping.ExcludeFromAllType
0985:                                .fromString(excludeFromAll));
0986:
0987:                bindSpellCheck(metadataConf, mdMapping);
0988:            }
0989:
0990:            private void bindExtends(ConfigurationHelper conf,
0991:                    AliasMapping mapping) throws ConfigurationException {
0992:                String extendsAliases = conf.getAttribute("extends", null);
0993:                if (extendsAliases != null) {
0994:                    mapping.setExtendedAliases(getAliases(extendsAliases));
0995:                }
0996:            }
0997:
0998:            /**
0999:             * Returns a string array of aliases from a comma separated string
1000:             */
1001:            private String[] getAliases(String commaSeparatedAliases) {
1002:                if (commaSeparatedAliases == null) {
1003:                    return null;
1004:                }
1005:                ArrayList<String> aliases = new ArrayList<String>();
1006:                StringTokenizer st = new StringTokenizer(commaSeparatedAliases,
1007:                        ",");
1008:                while (st.hasMoreTokens()) {
1009:                    String extendedAlias = st.nextToken().trim();
1010:                    Alias alias = valueLookup.lookupAlias(extendedAlias);
1011:                    if (alias == null) {
1012:                        aliases.add(extendedAlias);
1013:                    } else {
1014:                        aliases.add(alias.getName());
1015:                    }
1016:                }
1017:                return aliases.toArray(new String[aliases.size()]);
1018:            }
1019:
1020:            private void bindConverter(ConfigurationHelper conf, Mapping mapping) {
1021:                String converterName = conf.getAttribute("converter", null);
1022:                mapping.setConverterName(converterName);
1023:            }
1024:
1025:            private void bindAll(ConfigurationHelper conf,
1026:                    AbstractResourceMapping resourceMapping) {
1027:                ConfigurationHelper allConf = conf.getChild("all", false);
1028:                DefaultAllMapping allMapping = new DefaultAllMapping();
1029:                if (allConf != null) {
1030:                    String sAllSupported = allConf.getAttribute("enable", null);
1031:                    if (sAllSupported != null) {
1032:                        allMapping.setSupported(sAllSupported
1033:                                .equalsIgnoreCase("true"));
1034:                    }
1035:                    String termVectorType = allConf.getAttribute("term-vector",
1036:                            null);
1037:                    if (termVectorType != null) {
1038:                        allMapping.setTermVector(Property.TermVector
1039:                                .fromString(termVectorType));
1040:                    }
1041:                    String sOmitNorms = allConf
1042:                            .getAttribute("omit-norms", null);
1043:                    if (sOmitNorms != null) {
1044:                        allMapping.setOmitNorms(sOmitNorms
1045:                                .equalsIgnoreCase("true"));
1046:                    }
1047:                    String sExcludeAlias = allConf.getAttribute(
1048:                            "exclude-alias", null);
1049:                    if (sExcludeAlias != null) {
1050:                        allMapping.setExcludeAlias(sExcludeAlias
1051:                                .equalsIgnoreCase("true"));
1052:                    }
1053:                    allMapping.setProperty(allConf.getAttribute("name", null));
1054:                    allMapping.setSpellCheck(SpellCheckType.fromString(allConf
1055:                            .getAttribute("spell-check", "na")));
1056:                }
1057:                resourceMapping.setAllMapping(allMapping);
1058:            }
1059:
1060:            private void bindSpellCheck(ConfigurationHelper conf,
1061:                    InternalResourcePropertyMapping mapping) {
1062:                mapping.setSpellCheck(SpellCheckType.fromString(conf
1063:                        .getAttribute("spell-check", "na")));
1064:            }
1065:
1066:            private void bindSpellCheck(ConfigurationHelper conf,
1067:                    InternalResourceMapping mapping) {
1068:                mapping.setSpellCheck(SpellCheckType.fromString(conf
1069:                        .getAttribute("spell-check", "na")));
1070:            }
1071:
1072:            private void bindSubIndexHash(ConfigurationHelper conf,
1073:                    AbstractResourceMapping resourceMapping) {
1074:                ConfigurationHelper subIndexHashConf = conf.getChild(
1075:                        "sub-index-hash", false);
1076:                if (subIndexHashConf == null) {
1077:                    String subIndex = conf.getAttribute("sub-index",
1078:                            resourceMapping.getAlias());
1079:                    resourceMapping.setSubIndexHash(new ConstantSubIndexHash(
1080:                            subIndex));
1081:                    if (log.isTraceEnabled()) {
1082:                        log.trace("Alias [" + resourceMapping.getAlias()
1083:                                + "] is mapped to sub index hash ["
1084:                                + resourceMapping.getSubIndexHash() + "]");
1085:                    }
1086:                    return;
1087:                }
1088:
1089:                String type = subIndexHashConf.getAttribute("type", null);
1090:                SubIndexHash subIndexHash;
1091:                try {
1092:                    subIndexHash = (SubIndexHash) ClassUtils.forName(type,
1093:                            settings.getClassLoader()).newInstance();
1094:                } catch (Exception e) {
1095:                    throw new ConfigurationException(
1096:                            "Failed to create sub index hash of type [" + type
1097:                                    + "]", e);
1098:                }
1099:                CompassSettings settings = this .settings.copy().clear();
1100:                ConfigurationHelper[] settingsConf = subIndexHashConf
1101:                        .getChildren("setting");
1102:                if (subIndexHash instanceof  CompassConfigurable) {
1103:                    for (ConfigurationHelper aSettingsConf : settingsConf) {
1104:                        settings.setSetting(aSettingsConf.getAttribute("name"),
1105:                                aSettingsConf.getAttribute("value"));
1106:                    }
1107:                    ((CompassConfigurable) subIndexHash).configure(settings);
1108:                } else {
1109:                    if (settingsConf.length < 0) {
1110:                        throw new ConfigurationException(
1111:                                "Sub index hash ["
1112:                                        + subIndexHash
1113:                                        + "] does not implement "
1114:                                        + "CompassConfigurable, but settings have been set for it");
1115:                    }
1116:                }
1117:                resourceMapping.setSubIndexHash(subIndexHash);
1118:                if (log.isTraceEnabled()) {
1119:                    log.trace("Alias [" + resourceMapping.getAlias()
1120:                            + "] is mapped to sub index hash ["
1121:                            + resourceMapping.getSubIndexHash() + "]");
1122:                }
1123:            }
1124:
1125:            private static float getBoost(ConfigurationHelper conf) {
1126:                return getBoost(conf, 1.0f);
1127:            }
1128:
1129:            private static float getBoost(ConfigurationHelper conf,
1130:                    float defaultBoost) {
1131:                return conf.getAttributeAsFloat("boost", defaultBoost);
1132:            }
1133:
1134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.