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.builder;
0018:
0019: import java.io.File;
0020: import java.io.InputStream;
0021: import java.lang.reflect.InvocationTargetException;
0022: import java.lang.reflect.Method;
0023: import java.util.ArrayList;
0024: import java.util.Iterator;
0025: import java.util.List;
0026: import javax.xml.parsers.DocumentBuilderFactory;
0027: import javax.xml.parsers.ParserConfigurationException;
0028:
0029: import org.compass.core.config.CompassConfiguration;
0030: import org.compass.core.config.CompassEnvironment;
0031: import org.compass.core.config.CompassSettings;
0032: import org.compass.core.config.ConfigurationException;
0033: import org.compass.core.lucene.LuceneEnvironment;
0034: import org.compass.core.util.ClassUtils;
0035: import org.compass.core.util.DomUtils;
0036: import org.compass.core.util.SystemPropertyUtils;
0037: import org.w3c.dom.Document;
0038: import org.w3c.dom.Element;
0039: import org.w3c.dom.Node;
0040: import org.w3c.dom.NodeList;
0041: import org.xml.sax.EntityResolver;
0042: import org.xml.sax.InputSource;
0043:
0044: /**
0045: * @author kimchy
0046: */
0047: public class SchemaConfigurationBuilder extends
0048: AbstractXmlConfigurationBuilder {
0049:
0050: protected void doProcess(Document doc, CompassConfiguration config)
0051: throws ConfigurationException {
0052: Element root = doc.getDocumentElement();
0053: // the root is the compass element
0054: NodeList nl = root.getChildNodes();
0055: for (int i = 0; i < nl.getLength(); i++) {
0056: Node node = nl.item(i);
0057: if (node instanceof Element) {
0058: if ("compass".equals(node.getLocalName())) {
0059: processCompass((Element) node, config);
0060: }
0061: }
0062: }
0063: }
0064:
0065: public void processCompass(Element compassElement,
0066: CompassConfiguration config) {
0067:
0068: config.getSettings().setSetting(CompassEnvironment.NAME,
0069: DomUtils.getElementAttribute(compassElement, "name"));
0070:
0071: NodeList nl = compassElement.getChildNodes();
0072: for (int i = 0; i < nl.getLength(); i++) {
0073: Node node = nl.item(i);
0074: if (node instanceof Element) {
0075: Element ele = (Element) node;
0076: String nodeName = ele.getLocalName();
0077: String methodName = "bind"
0078: + Character.toUpperCase(nodeName.charAt(0))
0079: + nodeName.substring(1, nodeName.length());
0080: Method method;
0081: try {
0082: method = SchemaConfigurationBuilder.class
0083: .getMethod(methodName, new Class[] {
0084: Element.class,
0085: CompassConfiguration.class });
0086: } catch (NoSuchMethodException e) {
0087: throw new ConfigurationException(
0088: "Compass failed to process node ["
0089: + nodeName
0090: + "], this is "
0091: + "either a mailformed xml configuration (not validated against the xsd), or an internal"
0092: + " bug in compass");
0093: }
0094: try {
0095: method.invoke(this , new Object[] { ele, config });
0096: } catch (InvocationTargetException e) {
0097: throw new ConfigurationException(
0098: "Failed to invoke binding metod for node ["
0099: + nodeName + "]", e
0100: .getTargetException());
0101: } catch (IllegalAccessException e) {
0102: throw new ConfigurationException(
0103: "Failed to access binding metod for node ["
0104: + nodeName + "]", e);
0105: }
0106: }
0107: }
0108: }
0109:
0110: private String getElementAttribute(Element ele, String name) {
0111: return SystemPropertyUtils.resolvePlaceholders(DomUtils
0112: .getElementAttribute(ele, name));
0113: }
0114:
0115: private String getElementAttribute(Element ele, String name,
0116: String defaultValue) {
0117: return SystemPropertyUtils.resolvePlaceholders(DomUtils
0118: .getElementAttribute(ele, name, defaultValue));
0119: }
0120:
0121: private boolean getElementAttributeAsBoolean(Element ele,
0122: String name, boolean defaultValue) {
0123: String sValue = getElementAttribute(ele, name);
0124: if (sValue == null) {
0125: return defaultValue;
0126: }
0127: return Boolean.valueOf(sValue).booleanValue();
0128: }
0129:
0130: public void bindOsem(Element ele, CompassConfiguration config) {
0131: CompassSettings settings = config.getSettings();
0132: settings.setSetting(CompassEnvironment.Osem.MANAGED_ID_INDEX,
0133: getElementAttribute(ele, "managedIdIndex"));
0134: settings.setSetting(CompassEnvironment.Osem.SUPPORT_UNMARSHALL,
0135: getElementAttribute(ele, "supportUnmarshall"));
0136: }
0137:
0138: public void bindConverters(Element ele, CompassConfiguration config) {
0139: CompassSettings settings = config.getSettings();
0140: List convertersEle = DomUtils.getChildElementsByTagName(ele,
0141: "converter", true);
0142: for (Iterator it = convertersEle.iterator(); it.hasNext();) {
0143: Element converterEle = (Element) it.next();
0144: SettingsHolder settingsHolder = processSettings(converterEle);
0145: settingsHolder.names.add(CompassEnvironment.Converter.TYPE);
0146: settingsHolder.values.add(getElementAttribute(converterEle,
0147: "type"));
0148: settings.setGroupSettings(
0149: CompassEnvironment.Converter.PREFIX,
0150: getElementAttribute(converterEle, "name"),
0151: settingsHolder.names(), settingsHolder.values());
0152: }
0153: }
0154:
0155: public void bindPropertyAccessors(Element ele,
0156: CompassConfiguration config) {
0157: CompassSettings settings = config.getSettings();
0158: List propertyAccessorsEle = DomUtils.getChildElementsByTagName(
0159: ele, "propertyAccessor", true);
0160: for (Iterator it = propertyAccessorsEle.iterator(); it
0161: .hasNext();) {
0162: Element propertyAccessorEle = (Element) it.next();
0163: SettingsHolder settingsHolder = processSettings(propertyAccessorEle);
0164: settingsHolder.names
0165: .add(CompassEnvironment.PropertyAccessor.TYPE);
0166: settingsHolder.values.add(getElementAttribute(
0167: propertyAccessorEle, "type"));
0168: settings.setGroupSettings(
0169: CompassEnvironment.PropertyAccessor.PREFIX,
0170: getElementAttribute(propertyAccessorEle, "name"),
0171: settingsHolder.names(), settingsHolder.values());
0172: }
0173: }
0174:
0175: public void bindPropertyNamingStrategy(Element ele,
0176: CompassConfiguration config) {
0177: CompassSettings settings = config.getSettings();
0178: String type = getElementAttribute(ele, "type");
0179: if (type == null) {
0180: type = getElementAttribute(ele, "typeClass");
0181: }
0182: settings.setSetting(CompassEnvironment.NamingStrategy.TYPE,
0183: type);
0184: }
0185:
0186: public void bindSearchEngine(Element ele,
0187: CompassConfiguration config) {
0188: CompassSettings settings = config.getSettings();
0189: settings.setSetting(
0190: LuceneEnvironment.SearchEngineIndex.USE_COMPOUND_FILE,
0191: getElementAttribute(ele, "useCompoundFile"));
0192: settings.setSetting(
0193: LuceneEnvironment.SearchEngineIndex.MAX_FIELD_LENGTH,
0194: getElementAttribute(ele, "maxFieldLength"));
0195: settings
0196: .setSetting(
0197: LuceneEnvironment.SearchEngineIndex.CACHE_INTERVAL_INVALIDATION,
0198: getElementAttribute(ele,
0199: "cacheInvalidationInterval"));
0200: settings
0201: .setSetting(
0202: LuceneEnvironment.SearchEngineIndex.INDEX_MANAGER_SCHEDULE_INTERVAL,
0203: getElementAttribute(ele,
0204: "indexManagerScheduleInterval"));
0205: settings
0206: .setSetting(
0207: LuceneEnvironment.SearchEngineIndex.WAIT_FOR_CACHE_INVALIDATION_ON_INDEX_OPERATION,
0208: getElementAttribute(ele,
0209: "waitForCacheInvalidationOnIndexOperation"));
0210: settings.setSetting(LuceneEnvironment.DEFAULT_SEARCH,
0211: getElementAttribute(ele, "defaultSearch"));
0212: List child = DomUtils.getChildElementsByTagName(ele,
0213: "aliasProperty", true);
0214: if (child.size() == 1) {
0215: Element aliasPropertyEle = (Element) child.get(0);
0216: settings.setSetting(CompassEnvironment.Alias.NAME,
0217: getElementAttribute(aliasPropertyEle, "name"));
0218: }
0219: child = DomUtils.getChildElementsByTagName(ele, "allProperty",
0220: true);
0221: if (child.size() == 1) {
0222: Element allPropertyEle = (Element) child.get(0);
0223: settings.setSetting(CompassEnvironment.All.NAME,
0224: getElementAttribute(allPropertyEle, "name"));
0225: settings.setSetting(CompassEnvironment.All.TERM_VECTOR,
0226: getElementAttribute(allPropertyEle, "termVector"));
0227: settings.setSetting(CompassEnvironment.All.ENABLED,
0228: getElementAttribute(allPropertyEle, "enabled"));
0229: settings
0230: .setSetting(CompassEnvironment.All.BOOST_SUPPORT,
0231: getElementAttribute(allPropertyEle,
0232: "boostSupport"));
0233: }
0234: child = DomUtils.getChildElementsByTagName(ele, "optimizer",
0235: true);
0236: if (child.size() == 1) {
0237: Element optimizerEle = (Element) child.get(0);
0238: settings.setSetting(LuceneEnvironment.Optimizer.TYPE,
0239: getElementAttribute(optimizerEle, "type"));
0240: settings.setSetting(LuceneEnvironment.Optimizer.SCHEDULE,
0241: getElementAttribute(optimizerEle, "schedule"));
0242: settings.setSetting(
0243: LuceneEnvironment.Optimizer.SCHEDULE_PERIOD,
0244: getElementAttribute(optimizerEle,
0245: "scheduleInterval"));
0246: settings.setSetting(
0247: LuceneEnvironment.Optimizer.Adaptive.MERGE_FACTOR,
0248: getElementAttribute(optimizerEle, "mergeFactor"));
0249: settings
0250: .setSetting(
0251: LuceneEnvironment.Optimizer.Aggressive.MERGE_FACTOR,
0252: getElementAttribute(optimizerEle,
0253: "mergeFactor"));
0254: }
0255: child = DomUtils.getChildElementsByTagName(ele, "highlighter",
0256: true);
0257: for (Iterator it = child.iterator(); it.hasNext();) {
0258: Element highlighterEle = (Element) it.next();
0259: String highlighterName = getElementAttribute(
0260: highlighterEle, "name");
0261: SettingsHolder settingsHolder = processSettings(highlighterEle);
0262:
0263: settingsHolder.names
0264: .add(LuceneEnvironment.Highlighter.TEXT_TOKENIZER);
0265: settingsHolder.values.add(getElementAttribute(
0266: highlighterEle, "textTokenizer"));
0267:
0268: settingsHolder.names
0269: .add(LuceneEnvironment.Highlighter.REWRITE_QUERY);
0270: settingsHolder.values.add(getElementAttribute(
0271: highlighterEle, "rewriteQuery"));
0272:
0273: settingsHolder.names
0274: .add(LuceneEnvironment.Highlighter.COMPUTE_IDF);
0275: settingsHolder.values.add(getElementAttribute(
0276: highlighterEle, "computeIdf"));
0277:
0278: settingsHolder.names
0279: .add(LuceneEnvironment.Highlighter.MAX_NUM_FRAGMENTS);
0280: settingsHolder.values.add(getElementAttribute(
0281: highlighterEle, "maxNumFragments"));
0282:
0283: settingsHolder.names
0284: .add(LuceneEnvironment.Highlighter.SEPARATOR);
0285: settingsHolder.values.add(getElementAttribute(
0286: highlighterEle, "separator"));
0287:
0288: settingsHolder.names
0289: .add(LuceneEnvironment.Highlighter.MAX_BYTES_TO_ANALYZE);
0290: settingsHolder.values.add(getElementAttribute(
0291: highlighterEle, "maxBytesToAnalyze"));
0292:
0293: List fragmenterList = DomUtils.getChildElementsByTagName(
0294: highlighterEle, "fragmenter", true);
0295: if (fragmenterList.size() == 1) {
0296: Element fragmenterEle = (Element) fragmenterList.get(0);
0297: String type = getElementAttribute(fragmenterEle, "type");
0298: if ("custom".equals(type)) {
0299: type = getElementAttribute(fragmenterEle, "class");
0300: }
0301: settingsHolder.names
0302: .add(LuceneEnvironment.Highlighter.Fragmenter.TYPE);
0303: settingsHolder.values.add(type);
0304: settingsHolder.names
0305: .add(LuceneEnvironment.Highlighter.Fragmenter.SIMPLE_SIZE);
0306: settingsHolder.values.add(getElementAttribute(
0307: fragmenterEle, "size"));
0308: }
0309:
0310: List encoderList = DomUtils.getChildElementsByTagName(
0311: highlighterEle, "encoder", true);
0312: if (encoderList.size() == 1) {
0313: Element encoderEle = (Element) encoderList.get(0);
0314: String type = getElementAttribute(encoderEle, "type");
0315: if ("custom".equals(type)) {
0316: type = getElementAttribute(encoderEle, "class");
0317: }
0318: settingsHolder.names
0319: .add(LuceneEnvironment.Highlighter.Encoder.TYPE);
0320: settingsHolder.values.add(type);
0321: }
0322:
0323: List formatterList = DomUtils.getChildElementsByTagName(
0324: highlighterEle, "simpleFormatter", true);
0325: if (formatterList.size() == 1) {
0326: Element formatterEle = (Element) formatterList.get(0);
0327: settingsHolder.names
0328: .add(LuceneEnvironment.Highlighter.Formatter.TYPE);
0329: settingsHolder.values
0330: .add(LuceneEnvironment.Highlighter.Formatter.SIMPLE);
0331:
0332: settingsHolder.names
0333: .add(LuceneEnvironment.Highlighter.Formatter.SIMPLE_PRE_HIGHLIGHT);
0334: settingsHolder.values.add(getElementAttribute(
0335: formatterEle, "pre"));
0336:
0337: settingsHolder.names
0338: .add(LuceneEnvironment.Highlighter.Formatter.SIMPLE_POST_HIGHLIGHT);
0339: settingsHolder.values.add(getElementAttribute(
0340: formatterEle, "post"));
0341: }
0342:
0343: formatterList = DomUtils.getChildElementsByTagName(
0344: highlighterEle, "htmlSpanGradientFormatter", true);
0345: if (formatterList.size() == 1) {
0346: Element formatterEle = (Element) formatterList.get(0);
0347: settingsHolder.names
0348: .add(LuceneEnvironment.Highlighter.Formatter.TYPE);
0349: settingsHolder.values
0350: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT);
0351:
0352: settingsHolder.names
0353: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT_MAX_SCORE);
0354: settingsHolder.values.add(getElementAttribute(
0355: formatterEle, "maxScore"));
0356:
0357: settingsHolder.names
0358: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT_MIN_FOREGROUND_COLOR);
0359: settingsHolder.values.add(getElementAttribute(
0360: formatterEle, "minForegroundColor"));
0361:
0362: settingsHolder.names
0363: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT_MAX_FOREGROUND_COLOR);
0364: settingsHolder.values.add(getElementAttribute(
0365: formatterEle, "maxForegroundColor"));
0366:
0367: settingsHolder.names
0368: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT_MIN_BACKGROUND_COLOR);
0369: settingsHolder.values.add(getElementAttribute(
0370: formatterEle, "minBackgroundColor"));
0371:
0372: settingsHolder.names
0373: .add(LuceneEnvironment.Highlighter.Formatter.HTML_SPAN_GRADIENT_MAX_BACKGROUND_COLOR);
0374: settingsHolder.values.add(getElementAttribute(
0375: formatterEle, "maxBackgroundColor"));
0376: }
0377:
0378: formatterList = DomUtils.getChildElementsByTagName(
0379: highlighterEle, "customFormatter", true);
0380: if (formatterList.size() == 1) {
0381: Element formatterEle = (Element) formatterList.get(0);
0382: settingsHolder.names
0383: .add(LuceneEnvironment.Highlighter.Formatter.TYPE);
0384: settingsHolder.values.add(getElementAttribute(
0385: formatterEle, "class"));
0386: }
0387:
0388: settings.setGroupSettings(
0389: LuceneEnvironment.Highlighter.PREFIX,
0390: highlighterName, settingsHolder.names(),
0391: settingsHolder.values());
0392: }
0393: child = DomUtils.getChildElementsByTagName(ele, "analyzer",
0394: true);
0395: for (Iterator it = child.iterator(); it.hasNext();) {
0396: Element analyzerEle = (Element) it.next();
0397: String analyzerName = getElementAttribute(analyzerEle,
0398: "name");
0399: SettingsHolder settingsHolder = processSettings(analyzerEle);
0400: String analyzerType = getElementAttribute(analyzerEle,
0401: "type");
0402: if (analyzerType != null) {
0403: if (analyzerType.equals("CustomAnalyzer")) {
0404: analyzerType = getElementAttribute(analyzerEle,
0405: "analyzerClass");
0406: if (analyzerType == null) {
0407: throw new ConfigurationException(
0408: "Analyzer ["
0409: + analyzerName
0410: + "] has "
0411: + "type of [CustomAnalyzer] but does not set analyzerClass");
0412: }
0413: }
0414: settingsHolder.names
0415: .add(LuceneEnvironment.Analyzer.TYPE);
0416: settingsHolder.values.add(analyzerType);
0417:
0418: if (analyzerType.equals("Snowball")) {
0419: settingsHolder.names
0420: .add(LuceneEnvironment.Analyzer.Snowball.NAME_TYPE);
0421: settingsHolder.values.add(getElementAttribute(
0422: analyzerEle, "snowballType"));
0423: }
0424: }
0425: settingsHolder.names
0426: .add(LuceneEnvironment.Analyzer.FILTERS);
0427: settingsHolder.values.add(getElementAttribute(analyzerEle,
0428: "filters"));
0429:
0430: List stopWordsList = DomUtils.getChildElementsByTagName(
0431: analyzerEle, "stopWords", true);
0432: if (stopWordsList.size() == 1) {
0433: Element stopWordsEle = (Element) stopWordsList.get(0);
0434: StringBuffer sb = new StringBuffer();
0435: boolean replace = getElementAttributeAsBoolean(
0436: stopWordsEle, "replace", false);
0437: if (!replace) {
0438: sb.append("+");
0439: }
0440: List stopWords = DomUtils.getChildElementsByTagName(
0441: stopWordsEle, "stopWord", true);
0442: for (Iterator swIt = stopWords.iterator(); swIt
0443: .hasNext();) {
0444: Element stopWordEle = (Element) swIt.next();
0445: sb
0446: .append(
0447: getElementAttribute(stopWordEle,
0448: "value")).append(",");
0449: }
0450: settingsHolder.names
0451: .add(LuceneEnvironment.Analyzer.STOPWORDS);
0452: settingsHolder.values.add(sb.toString());
0453: }
0454: settings.setGroupSettings(
0455: LuceneEnvironment.Analyzer.PREFIX, analyzerName,
0456: settingsHolder.names(), settingsHolder.values());
0457: }
0458: child = DomUtils.getChildElementsByTagName(ele,
0459: "analyzerFilter", true);
0460: for (Iterator it = child.iterator(); it.hasNext();) {
0461: Element analyzerFilterEle = (Element) it.next();
0462: SettingsHolder settingsHolder = processSettings(analyzerFilterEle);
0463: settingsHolder.names
0464: .add(LuceneEnvironment.AnalyzerFilter.TYPE);
0465: settingsHolder.values.add(getElementAttribute(
0466: analyzerFilterEle, "type"));
0467: settings.setGroupSettings(
0468: LuceneEnvironment.AnalyzerFilter.PREFIX,
0469: getElementAttribute(analyzerFilterEle, "name"),
0470: settingsHolder.names(), settingsHolder.values());
0471: }
0472: child = DomUtils.getChildElementsByTagName(ele, "queryParser",
0473: true);
0474: for (Iterator it = child.iterator(); it.hasNext();) {
0475: Element queryParserEle = (Element) it.next();
0476: SettingsHolder settingsHolder = processSettings(queryParserEle);
0477: settingsHolder.names
0478: .add(LuceneEnvironment.QueryParser.TYPE);
0479: settingsHolder.values.add(getElementAttribute(
0480: queryParserEle, "type"));
0481: settings.setGroupSettings(
0482: LuceneEnvironment.QueryParser.PREFIX,
0483: getElementAttribute(queryParserEle, "name"),
0484: settingsHolder.names(), settingsHolder.values());
0485: }
0486: child = DomUtils.getChildElementsByTagName(ele,
0487: "indexDeletionPolicy", true);
0488: if (child.size() == 1) {
0489: Element indexDeletionPolicyEle = (Element) child.get(0);
0490: child = DomUtils.getChildElementsByTagName(
0491: indexDeletionPolicyEle, "keepLastCommit", true);
0492: if (child.size() == 1) {
0493: settings
0494: .setSetting(
0495: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0496: LuceneEnvironment.IndexDeletionPolicy.KeepLastCommit.NAME);
0497: }
0498: child = DomUtils.getChildElementsByTagName(
0499: indexDeletionPolicyEle, "keepAll", true);
0500: if (child.size() == 1) {
0501: settings
0502: .setSetting(
0503: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0504: LuceneEnvironment.IndexDeletionPolicy.KeepAll.NAME);
0505: }
0506: child = DomUtils.getChildElementsByTagName(
0507: indexDeletionPolicyEle, "keepLastN", true);
0508: if (child.size() == 1) {
0509: settings
0510: .setSetting(
0511: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0512: LuceneEnvironment.IndexDeletionPolicy.KeepLastN.NAME);
0513: settings
0514: .setSetting(
0515: LuceneEnvironment.IndexDeletionPolicy.KeepLastN.NUM_TO_KEEP,
0516: ((Element) child.get(0))
0517: .getAttribute("numToKeep"));
0518: }
0519: child = DomUtils.getChildElementsByTagName(
0520: indexDeletionPolicyEle, "keepNoneOnInit", true);
0521: if (child.size() == 1) {
0522: settings
0523: .setSetting(
0524: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0525: LuceneEnvironment.IndexDeletionPolicy.KeepNoneOnInit.NAME);
0526: }
0527: child = DomUtils.getChildElementsByTagName(
0528: indexDeletionPolicyEle, "expirationTime", true);
0529: if (child.size() == 1) {
0530: settings
0531: .setSetting(
0532: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0533: LuceneEnvironment.IndexDeletionPolicy.ExpirationTime.NAME);
0534: settings
0535: .setSetting(
0536: LuceneEnvironment.IndexDeletionPolicy.ExpirationTime.EXPIRATION_TIME_IN_SECONDS,
0537: ((Element) child.get(0))
0538: .getAttribute("expirationTimeSeconds"));
0539: }
0540: child = DomUtils.getChildElementsByTagName(
0541: indexDeletionPolicyEle, "custom", true);
0542: if (child.size() == 1) {
0543: Element customEle = ((Element) child.get(0));
0544: settings.setSetting(
0545: LuceneEnvironment.IndexDeletionPolicy.TYPE,
0546: customEle.getAttribute("type"));
0547: bindSettings(customEle, config);
0548: }
0549: }
0550: }
0551:
0552: public void bindCache(Element ele, CompassConfiguration config) {
0553: CompassSettings settings = config.getSettings();
0554: List child = DomUtils.getChildElementsByTagName(ele,
0555: "firstLevel", true);
0556: if (child.size() == 1) {
0557: Element firstLevelCacheEle = (Element) child.get(0);
0558: settings.setSetting(
0559: CompassEnvironment.Cache.FirstLevel.TYPE,
0560: getElementAttribute(firstLevelCacheEle, "type"));
0561: }
0562: }
0563:
0564: public void bindTransaction(Element ele, CompassConfiguration config) {
0565: CompassSettings settings = config.getSettings();
0566: settings.setSetting(CompassEnvironment.Transaction.ISOLATION,
0567: getElementAttribute(ele, "isolation"));
0568: settings.setSetting(CompassEnvironment.Transaction.FACTORY,
0569: getElementAttribute(ele, "factory"));
0570: settings
0571: .setSetting(
0572: CompassEnvironment.Transaction.COMMIT_BEFORE_COMPLETION,
0573: getElementAttribute(ele,
0574: "commitBeforeCompletion"));
0575: settings.setSetting(LuceneEnvironment.Transaction.LOCK_TIMEOUT,
0576: getElementAttribute(ele, "lockTimeout"));
0577: settings.setSetting(
0578: LuceneEnvironment.Transaction.LOCK_POLL_INTERVAL,
0579: getElementAttribute(ele, "lockPollInterval"));
0580: settings
0581: .setSetting(
0582: CompassEnvironment.Transaction.DISABLE_AUTO_JOIN_SESSION,
0583: getElementAttribute(ele,
0584: "disableAutoJoinSession"));
0585: List child = DomUtils.getChildElementsByTagName(ele,
0586: "jtaSettings", true);
0587: if (child.size() == 1) {
0588: Element jtaSettingsEle = (Element) child.get(0);
0589: settings.setSetting(
0590: CompassEnvironment.Transaction.USER_TRANSACTION,
0591: getElementAttribute(jtaSettingsEle,
0592: "userTransactionName"));
0593: settings
0594: .setSetting(
0595: CompassEnvironment.Transaction.CACHE_USER_TRANSACTION,
0596: getElementAttribute(jtaSettingsEle,
0597: "cacheUserTransaction"));
0598: settings
0599: .setSetting(
0600: CompassEnvironment.Transaction.MANAGER_LOOKUP,
0601: getElementAttribute(jtaSettingsEle,
0602: "managerLookup"));
0603: settings.setSetting(
0604: CompassEnvironment.Transaction.MANAGER_LOOKUP,
0605: getElementAttribute(jtaSettingsEle,
0606: "managerLookupClass"));
0607: }
0608: child = DomUtils.getChildElementsByTagName(ele,
0609: "readCommittedSettings", true);
0610: if (child.size() == 1) {
0611: Element readCommittedSettingsEle = (Element) child.get(0);
0612: settings
0613: .setSetting(
0614: LuceneEnvironment.Transaction.ReadCommittedTransLog.CONNECTION,
0615: getElementAttribute(
0616: readCommittedSettingsEle,
0617: "transLog"));
0618: settings
0619: .setSetting(
0620: LuceneEnvironment.Transaction.ReadCommittedTransLog.OPTIMIZE_TRANS_LOG,
0621: getElementAttribute(
0622: readCommittedSettingsEle,
0623: "optimizeTransLog"));
0624: }
0625: }
0626:
0627: public void bindConnection(Element ele, CompassConfiguration config) {
0628: CompassSettings settings = config.getSettings();
0629:
0630: // directory wrapper providers
0631: List child = DomUtils.getChildElementsByTagName(ele,
0632: "directoryWrapperProvider", true);
0633: for (Iterator it = child.iterator(); it.hasNext();) {
0634: Element dwEle = (Element) it.next();
0635: SettingsHolder settingsHolder = processSettings(dwEle);
0636: settingsHolder.names
0637: .add(LuceneEnvironment.DirectoryWrapper.TYPE);
0638: settingsHolder.values
0639: .add(getElementAttribute(dwEle, "type"));
0640: settings.setGroupSettings(
0641: LuceneEnvironment.DirectoryWrapper.PREFIX,
0642: getElementAttribute(dwEle, "name"), settingsHolder
0643: .names(), settingsHolder.values());
0644: }
0645:
0646: child = DomUtils.getChildElementsByTagName(ele, "localCache",
0647: true);
0648: for (Iterator it = child.iterator(); it.hasNext();) {
0649: Element localCacheEle = (Element) it.next();
0650: String subIndex = localCacheEle.getAttribute("subIndex");
0651: String connection = localCacheEle
0652: .getAttribute("connection");
0653: settings
0654: .setGroupSettings(
0655: LuceneEnvironment.LocalCache.PREFIX,
0656: subIndex,
0657: new String[] { LuceneEnvironment.LocalCache.CONNECTION },
0658: new String[] { connection });
0659: }
0660:
0661: child = DomUtils.getChildElementsByTagName(ele, "lockFactory",
0662: true);
0663: if (child.size() == 1) {
0664: Element lockFactoryEle = (Element) child.get(0);
0665: settings.setSetting(LuceneEnvironment.LockFactory.TYPE,
0666: getElementAttribute(lockFactoryEle, "type"));
0667: settings.setSetting(LuceneEnvironment.LockFactory.PATH,
0668: getElementAttribute(lockFactoryEle, "path"));
0669: }
0670:
0671: child = DomUtils.getChildElementsByTagName(ele, "file", true);
0672: if (child.size() == 1) {
0673: Element connEle = (Element) child.get(0);
0674: String path = getElementAttribute(connEle, "path");
0675: if (!path.startsWith("file://")) {
0676: path = "file://" + path;
0677: }
0678: settings.setSetting(CompassEnvironment.CONNECTION, path);
0679: return;
0680: }
0681: child = DomUtils.getChildElementsByTagName(ele, "mmap", true);
0682: if (child.size() == 1) {
0683: Element connEle = (Element) child.get(0);
0684: String path = getElementAttribute(connEle, "path");
0685: if (!path.startsWith("mmap://")) {
0686: path = "mmap://" + path;
0687: }
0688: settings.setSetting(CompassEnvironment.CONNECTION, path);
0689: return;
0690: }
0691: // --- RAM Connection ---
0692: child = DomUtils.getChildElementsByTagName(ele, "ram", true);
0693: if (child.size() == 1) {
0694: Element connEle = (Element) child.get(0);
0695: String path = getElementAttribute(connEle, "path");
0696: if (!path.startsWith("ram://")) {
0697: path = "ram://" + path;
0698: }
0699: settings.setSetting(CompassEnvironment.CONNECTION, path);
0700: return;
0701: }
0702: // --- Space Connection ---
0703: child = DomUtils.getChildElementsByTagName(ele, "space", true);
0704: if (child.size() == 1) {
0705: Element connEle = (Element) child.get(0);
0706: String url = getElementAttribute(connEle, "url");
0707: String indexName = getElementAttribute(connEle, "indexName");
0708: settings.setSetting(CompassEnvironment.CONNECTION,
0709: "space://" + indexName + ":" + url);
0710: // we don't use the static constant so we don't create dependency on GigaSpaces
0711: settings.setSetting(
0712: "compass.engine.store.space.bucketSize",
0713: getElementAttribute(connEle, "bucketSize"));
0714: return;
0715: }
0716: // --- Coherence Connection ---
0717: child = DomUtils.getChildElementsByTagName(ele, "coherence",
0718: true);
0719: if (child.size() == 1) {
0720: Element connEle = (Element) child.get(0);
0721: String indexName = getElementAttribute(connEle, "indexName");
0722: String cacheName = getElementAttribute(connEle, "cacheName");
0723: String type = getElementAttribute(connEle, "type",
0724: "invocable");
0725: if ("invocable".equals(type)) {
0726: settings.setSetting(CompassEnvironment.CONNECTION,
0727: "coherence://" + indexName + ":" + cacheName);
0728: } else {
0729: settings
0730: .setSetting(CompassEnvironment.CONNECTION,
0731: "coherence-dg://" + indexName + ":"
0732: + cacheName);
0733: }
0734: // we don't use the static constant so we don't create dependency on GigaSpaces
0735: settings.setSetting(
0736: "compass.engine.store.coherence.bucketSize",
0737: getElementAttribute(connEle, "bucketSize"));
0738: return;
0739: }
0740: // --- Custom Connection ---
0741: child = DomUtils.getChildElementsByTagName(ele, "custom", true);
0742: if (child.size() == 1) {
0743: Element connEle = (Element) child.get(0);
0744: String url = getElementAttribute(connEle, "url");
0745: settings.setSetting(CompassEnvironment.CONNECTION, url);
0746: return;
0747: }
0748: // --- JDBC Connection --
0749: child = DomUtils.getChildElementsByTagName(ele, "jdbc", true);
0750: Element connEle = (Element) child.get(0);
0751: // managed
0752: settings.setSetting(LuceneEnvironment.JdbcStore.MANAGED,
0753: getElementAttribute(connEle, "managed", "false"));
0754: // disable schema operations
0755: settings.setSetting(
0756: LuceneEnvironment.JdbcStore.DISABLE_SCHEMA_OPERATIONS,
0757: getElementAttribute(connEle, "disableSchemaOperations",
0758: "false"));
0759: // dialect
0760: settings.setSetting(LuceneEnvironment.JdbcStore.DIALECT,
0761: getElementAttribute(connEle, "dialect"));
0762: settings.setSetting(LuceneEnvironment.JdbcStore.DIALECT,
0763: getElementAttribute(connEle, "dialectClass"));
0764: // delete mark deleted
0765: settings.setSetting(
0766: LuceneEnvironment.JdbcStore.DELETE_MARK_DELETED_DELTA,
0767: getElementAttribute(connEle, "deleteMarkDeletedDelta"));
0768: // lock
0769: settings.setSetting(LuceneEnvironment.JdbcStore.LOCK_TYPE,
0770: getElementAttribute(connEle, "lock"));
0771: settings.setSetting(LuceneEnvironment.JdbcStore.LOCK_TYPE,
0772: getElementAttribute(connEle, "lockClass"));
0773:
0774: // configure file entries
0775: child = DomUtils.getChildElementsByTagName(connEle,
0776: "fileEntries", true);
0777: if (child.size() == 1) {
0778: Element fileEntriesEle = (Element) child.get(0);
0779: child = DomUtils.getChildElementsByTagName(fileEntriesEle,
0780: "fileEntry", true);
0781: for (Iterator it = child.iterator(); it.hasNext();) {
0782: Element fileEntryEle = (Element) it.next();
0783: SettingsHolder settingsHolder = processSettings(fileEntryEle);
0784: // --- File Entry Index Input ---
0785: child = DomUtils.getChildElementsByTagName(
0786: fileEntryEle, "indexInput", true);
0787: if (child.size() == 1) {
0788: Element indexInputEle = (Element) child.get(0);
0789: settingsHolder.names
0790: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_INPUT_TYPE);
0791: settingsHolder.values.add(getElementAttribute(
0792: indexInputEle, "type"));
0793: settingsHolder.names
0794: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_INPUT_TYPE);
0795: settingsHolder.values.add(getElementAttribute(
0796: indexInputEle, "typeClass"));
0797: settingsHolder.names
0798: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_INPUT_BUFFER_SIZE);
0799: settingsHolder.values.add(getElementAttribute(
0800: indexInputEle, "bufferSize"));
0801: }
0802: // --- File Entry Index Input ---
0803: child = DomUtils.getChildElementsByTagName(
0804: fileEntryEle, "indexOutput", true);
0805: if (child.size() == 1) {
0806: Element indexOutputEle = (Element) child.get(0);
0807: settingsHolder.names
0808: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_OUTPUT_TYPE);
0809: settingsHolder.values.add(getElementAttribute(
0810: indexOutputEle, "type"));
0811: settingsHolder.names
0812: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_OUTPUT_TYPE);
0813: settingsHolder.values.add(getElementAttribute(
0814: indexOutputEle, "typeClass"));
0815: settingsHolder.names
0816: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_OUTPUT_BUFFER_SIZE);
0817: settingsHolder.values.add(getElementAttribute(
0818: indexOutputEle, "bufferSize"));
0819: settingsHolder.names
0820: .add(LuceneEnvironment.JdbcStore.FileEntry.INDEX_OUTPUT_THRESHOLD);
0821: settingsHolder.values.add(getElementAttribute(
0822: indexOutputEle, "threshold"));
0823: }
0824: settings
0825: .setGroupSettings(
0826: LuceneEnvironment.JdbcStore.FileEntry.PREFIX,
0827: getElementAttribute(fileEntryEle,
0828: "name"),
0829: settingsHolder.names(), settingsHolder
0830: .values());
0831: }
0832: }
0833:
0834: // configure ddl
0835: child = DomUtils
0836: .getChildElementsByTagName(connEle, "ddl", true);
0837: if (child.size() == 1) {
0838: Element ddlEle = (Element) child.get(0);
0839: child = DomUtils.getChildElementsByTagName(ddlEle,
0840: "nameColumn", true);
0841: if (child.size() == 1) {
0842: Element nameColumnEle = (Element) child.get(0);
0843: settings.setSetting(
0844: LuceneEnvironment.JdbcStore.DDL.NAME_NAME,
0845: getElementAttribute(nameColumnEle, "name"));
0846: settings.setSetting(
0847: LuceneEnvironment.JdbcStore.DDL.NAME_LENGTH,
0848: getElementAttribute(nameColumnEle, "length"));
0849: }
0850: child = DomUtils.getChildElementsByTagName(ddlEle,
0851: "valueColumn", true);
0852: if (child.size() == 1) {
0853: Element valueColumnEle = (Element) child.get(0);
0854: settings.setSetting(
0855: LuceneEnvironment.JdbcStore.DDL.VALUE_NAME,
0856: getElementAttribute(valueColumnEle, "name"));
0857: settings.setSetting(
0858: LuceneEnvironment.JdbcStore.DDL.VALUE_LENGTH,
0859: getElementAttribute(valueColumnEle, "length"));
0860: }
0861: child = DomUtils.getChildElementsByTagName(ddlEle,
0862: "sizeColumn", true);
0863: if (child.size() == 1) {
0864: Element sizeColumnEle = (Element) child.get(0);
0865: settings.setSetting(
0866: LuceneEnvironment.JdbcStore.DDL.SIZE_NAME,
0867: getElementAttribute(sizeColumnEle, "name"));
0868: }
0869: child = DomUtils.getChildElementsByTagName(ddlEle,
0870: "lastModifiedColumn", true);
0871: if (child.size() == 1) {
0872: Element lastModifiedEle = (Element) child.get(0);
0873: settings
0874: .setSetting(
0875: LuceneEnvironment.JdbcStore.DDL.LAST_MODIFIED_NAME,
0876: getElementAttribute(lastModifiedEle,
0877: "name"));
0878: }
0879: child = DomUtils.getChildElementsByTagName(ddlEle,
0880: "deletedColumn", true);
0881: if (child.size() == 1) {
0882: Element deletedEle = (Element) child.get(0);
0883: settings.setSetting(
0884: LuceneEnvironment.JdbcStore.DDL.DELETED_NAME,
0885: getElementAttribute(deletedEle, "name"));
0886: }
0887: }
0888:
0889: // configure the data source provider
0890: child = DomUtils.getChildElementsByTagName(connEle,
0891: "dataSourceProvider", true);
0892: Element dataSourceProviderEle = (Element) child.get(0);
0893: // --- driverManager
0894: child = DomUtils.getChildElementsByTagName(
0895: dataSourceProviderEle, "driverManager", true);
0896: if (child.size() == 1) {
0897: Element driverManagerEle = (Element) child.get(0);
0898: settings
0899: .setSetting(
0900: LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
0901: "org.compass.core.lucene.engine.store.jdbc.DriverManagerDataSourceProvider");
0902: settings.setSetting(CompassEnvironment.CONNECTION,
0903: "jdbc://"
0904: + getElementAttribute(driverManagerEle,
0905: "url"));
0906: settings.setSetting(
0907: LuceneEnvironment.JdbcStore.Connection.USERNAME,
0908: getElementAttribute(driverManagerEle, "username"));
0909: settings.setSetting(
0910: LuceneEnvironment.JdbcStore.Connection.PASSWORD,
0911: getElementAttribute(driverManagerEle, "password"));
0912: settings
0913: .setSetting(
0914: LuceneEnvironment.JdbcStore.Connection.DRIVER_CLASS,
0915: getElementAttribute(driverManagerEle,
0916: "driverClass"));
0917: settings.setSetting(
0918: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
0919: getElementAttribute(driverManagerEle, "autoCommit",
0920: "false"));
0921: }
0922: child = DomUtils.getChildElementsByTagName(
0923: dataSourceProviderEle, "c3p0", true);
0924: if (child.size() == 1) {
0925: Element driverManagerEle = (Element) child.get(0);
0926: settings
0927: .setSetting(
0928: LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
0929: "org.compass.core.lucene.engine.store.jdbc.C3P0DataSourceProvider");
0930: settings.setSetting(CompassEnvironment.CONNECTION,
0931: "jdbc://"
0932: + getElementAttribute(driverManagerEle,
0933: "url"));
0934: settings.setSetting(
0935: LuceneEnvironment.JdbcStore.Connection.USERNAME,
0936: getElementAttribute(driverManagerEle, "username"));
0937: settings.setSetting(
0938: LuceneEnvironment.JdbcStore.Connection.PASSWORD,
0939: getElementAttribute(driverManagerEle, "password"));
0940: settings
0941: .setSetting(
0942: LuceneEnvironment.JdbcStore.Connection.DRIVER_CLASS,
0943: getElementAttribute(driverManagerEle,
0944: "driverClass"));
0945: settings.setSetting(
0946: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
0947: getElementAttribute(driverManagerEle, "autoCommit",
0948: "false"));
0949: }
0950: child = DomUtils.getChildElementsByTagName(
0951: dataSourceProviderEle, "jndi", true);
0952: if (child.size() == 1) {
0953: Element jndiEle = (Element) child.get(0);
0954: settings
0955: .setSetting(
0956: LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
0957: "org.compass.core.lucene.engine.store.jdbc.JndiDataSourceProvider");
0958: settings.setSetting(CompassEnvironment.CONNECTION,
0959: "jdbc://" + getElementAttribute(jndiEle, "lookup"));
0960: settings.setSetting(
0961: LuceneEnvironment.JdbcStore.Connection.USERNAME,
0962: getElementAttribute(jndiEle, "username"));
0963: settings.setSetting(
0964: LuceneEnvironment.JdbcStore.Connection.PASSWORD,
0965: getElementAttribute(jndiEle, "password"));
0966: settings
0967: .setSetting(
0968: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
0969: getElementAttribute(jndiEle, "autoCommit",
0970: "false"));
0971: }
0972: child = DomUtils.getChildElementsByTagName(
0973: dataSourceProviderEle, "dbcp", true);
0974: if (child.size() == 1) {
0975: Element dbcpEle = (Element) child.get(0);
0976: settings
0977: .setSetting(
0978: LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
0979: "org.compass.core.lucene.engine.store.jdbc.DbcpDataSourceProvider");
0980: settings.setSetting(CompassEnvironment.CONNECTION,
0981: "jdbc://" + getElementAttribute(dbcpEle, "url"));
0982: settings.setSetting(
0983: LuceneEnvironment.JdbcStore.Connection.USERNAME,
0984: getElementAttribute(dbcpEle, "username"));
0985: settings.setSetting(
0986: LuceneEnvironment.JdbcStore.Connection.PASSWORD,
0987: getElementAttribute(dbcpEle, "password"));
0988: settings
0989: .setSetting(
0990: LuceneEnvironment.JdbcStore.Connection.DRIVER_CLASS,
0991: getElementAttribute(dbcpEle, "driverClass"));
0992: settings
0993: .setSetting(
0994: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
0995: getElementAttribute(dbcpEle, "autoCommit",
0996: "false"));
0997: settings
0998: .setSetting(
0999: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.DEFAULT_TRANSACTION_ISOLATION,
1000: getElementAttribute(dbcpEle,
1001: "defaultTransacitonIsolation"));
1002: settings
1003: .setSetting(
1004: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.INITIAL_SIZE,
1005: getElementAttribute(dbcpEle, "initialSize"));
1006: settings
1007: .setSetting(
1008: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_ACTIVE,
1009: getElementAttribute(dbcpEle, "maxActive"));
1010: settings
1011: .setSetting(
1012: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_IDLE,
1013: getElementAttribute(dbcpEle, "maxIdle"));
1014: settings
1015: .setSetting(
1016: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MIN_IDLE,
1017: getElementAttribute(dbcpEle, "minIdle"));
1018: settings
1019: .setSetting(
1020: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_WAIT,
1021: getElementAttribute(dbcpEle, "maxWait"));
1022: settings
1023: .setSetting(
1024: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_OPEN_PREPARED_STATEMENTS,
1025: getElementAttribute(dbcpEle,
1026: "maxOpenPreparedStatements"));
1027: settings
1028: .setSetting(
1029: LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.POOL_PREPARED_STATEMENTS,
1030: getElementAttribute(dbcpEle,
1031: "poolPreparedStatements"));
1032: }
1033: child = DomUtils.getChildElementsByTagName(
1034: dataSourceProviderEle, "external", true);
1035: if (child.size() == 1) {
1036: Element externalEle = (Element) child.get(0);
1037: settings
1038: .setSetting(
1039: LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
1040: "org.compass.core.lucene.engine.store.jdbc.ExternalDataSourceProvider");
1041: settings.setSetting(CompassEnvironment.CONNECTION,
1042: "jdbc://");
1043: settings.setSetting(
1044: LuceneEnvironment.JdbcStore.Connection.USERNAME,
1045: getElementAttribute(externalEle, "username"));
1046: settings.setSetting(
1047: LuceneEnvironment.JdbcStore.Connection.PASSWORD,
1048: getElementAttribute(externalEle, "password"));
1049: settings.setSetting(
1050: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
1051: getElementAttribute(externalEle, "autoCommit",
1052: "false"));
1053: }
1054: }
1055:
1056: public void bindJndi(Element ele, CompassConfiguration config) {
1057: CompassSettings settings = config.getSettings();
1058: settings.setSetting(CompassEnvironment.Jndi.ENABLE,
1059: getElementAttribute(ele, "register", "false"));
1060: settings.setSetting(CompassEnvironment.Jndi.CLASS,
1061: getElementAttribute(ele, "class"));
1062: settings.setSetting(CompassEnvironment.Jndi.URL,
1063: getElementAttribute(ele, "url"));
1064: List environments = DomUtils.getChildElementsByTagName(ele,
1065: "environment", true);
1066: if (environments.size() == 1) {
1067: Element environment = (Element) environments.get(0);
1068: List properties = DomUtils.getChildElementsByTagName(
1069: environment, "property", true);
1070: for (Iterator it = properties.iterator(); it.hasNext();) {
1071: Element property = (Element) it.next();
1072: String propertyName = CompassEnvironment.Jndi.PREFIX
1073: + "." + getElementAttribute(property, "name");
1074: String propertyValue = getElementAttribute(property,
1075: "value");
1076: settings.setSetting(propertyName, propertyValue);
1077: }
1078: }
1079: }
1080:
1081: public void bindSettings(Element ele, CompassConfiguration config) {
1082: CompassSettings settings = config.getSettings();
1083: List domSettings = DomUtils.getChildElementsByTagName(ele,
1084: "setting", true);
1085: for (Iterator it = domSettings.iterator(); it.hasNext();) {
1086: Element eleSetting = (Element) it.next();
1087: settings.setSetting(
1088: getElementAttribute(eleSetting, "name"),
1089: getElementAttribute(eleSetting, "value"));
1090: }
1091: }
1092:
1093: public void bindMappings(Element ele, CompassConfiguration config)
1094: throws Exception {
1095: NodeList nl = ele.getChildNodes();
1096: for (int i = 0; i < nl.getLength(); i++) {
1097: Node node = nl.item(i);
1098: if (node instanceof Element) {
1099: Element mappingEle = (Element) node;
1100: String nodeName = mappingEle.getLocalName();
1101: if ("resource".equals(nodeName)) {
1102: config.addResource(getElementAttribute(mappingEle,
1103: "location"));
1104: } else if ("class".equals(nodeName)) {
1105: config.addClass(ClassUtils.forName(
1106: getElementAttribute(mappingEle, "name"),
1107: config.getClassLoader()));
1108: } else if ("jar".equals(nodeName)) {
1109: config.addJar(new File(getElementAttribute(
1110: mappingEle, "path")));
1111: } else if ("file".equals(nodeName)) {
1112: config.addFile(new File(getElementAttribute(
1113: mappingEle, "path")));
1114: } else if ("dir".equals(nodeName)) {
1115: config.addDirectory(new File(getElementAttribute(
1116: mappingEle, "path")));
1117: } else if ("package".equals(nodeName)) {
1118: config.addPackage(getElementAttribute(mappingEle,
1119: "name"));
1120: }
1121: }
1122: }
1123: }
1124:
1125: private SettingsHolder processSettings(Element ele) {
1126: SettingsHolder settingsHolder = new SettingsHolder();
1127: List settings = DomUtils.getChildElementsByTagName(ele,
1128: "setting", true);
1129: for (Iterator it = settings.iterator(); it.hasNext();) {
1130: Element settingEle = (Element) it.next();
1131: settingsHolder.names.add(getElementAttribute(settingEle,
1132: "name"));
1133: settingsHolder.values.add(getElementAttribute(settingEle,
1134: "value"));
1135: }
1136: return settingsHolder;
1137: }
1138:
1139: private class SettingsHolder {
1140: public ArrayList names = new ArrayList();
1141: public ArrayList values = new ArrayList();
1142:
1143: public String[] names() {
1144: return (String[]) names.toArray(new String[names.size()]);
1145: }
1146:
1147: public String[] values() {
1148: return (String[]) values.toArray(new String[values.size()]);
1149: }
1150: }
1151:
1152: protected EntityResolver doGetEntityResolver() {
1153: return new EntityResolver() {
1154:
1155: private static final String URL = "http://www.opensymphony.com/compass/schema/";
1156:
1157: public InputSource resolveEntity(String publicId,
1158: String systemId) {
1159: if (systemId != null && systemId.startsWith(URL)) {
1160: // Search for DTD
1161: String location = "/org/compass/core/"
1162: + systemId.substring(URL.length());
1163: InputStream is = getClass().getResourceAsStream(
1164: location);
1165: if (is == null) {
1166: throw new ConfigurationException(
1167: "Schema system id ["
1168: + systemId
1169: + "] not found at ["
1170: + location
1171: + "], "
1172: + "please check it has the correct location. Have you included compass in your class path?");
1173: }
1174: InputSource source = new InputSource(is);
1175: source.setPublicId(publicId);
1176: source.setSystemId(systemId);
1177: return source;
1178: } else {
1179: throw new ConfigurationException(
1180: "Schema system id ["
1181: + systemId
1182: + "] not found, please check it has the "
1183: + "correct location");
1184: }
1185: }
1186: };
1187: }
1188:
1189: protected DocumentBuilderFactory createDocumentBuilderFactory()
1190: throws ParserConfigurationException {
1191: DocumentBuilderFactory factory = super
1192: .createDocumentBuilderFactory();
1193: factory.setNamespaceAware(true);
1194: try {
1195: factory
1196: .setAttribute(
1197: "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
1198: "http://www.w3.org/2001/XMLSchema");
1199: } catch (IllegalArgumentException ex) {
1200: throw new ConfigurationException(
1201: "Unable to validate using XSD: Your JAXP provider ["
1202: + factory
1203: + "] does not support XML Schema. "
1204: + "Are you running on Java 1.4 or below with Apache Crimson? "
1205: + "Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
1206: }
1207: return factory;
1208: }
1209: }
|