001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.services.config;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.common.tagging.RootConceptTagHolder;
015: import org.jfolder.common.utils.xml.LinearXPath;
016: import org.jfolder.config.instance.ConfigInstance;
017: import org.jfolder.config.instance.ConfigInstanceConfig;
018: import org.jfolder.services.base.BaseService;
019:
020: //other classes
021:
022: public class ApplicationStoreSet {
023:
024: //
025: private final static String DATABASES = "databases";
026: private final static String DATABASE = "database";
027: private final static String DISPLAY_NAME = "display-name";
028: private final static String ACTUAL_NAME = "actual-name";
029: private final static String REFERENCE_HANDLE = "reference-handle";
030:
031: //
032: private final static LinearXPath XPATH_DATABASES = LinearXPath
033: .r(DATABASES);
034: private final static LinearXPath XPATH_DATABASES_DATABASE = XPATH_DATABASES
035: .b(DATABASE);
036: //
037: private final static LinearXPath XPATH_DISPLAY_NAME = XPATH_DATABASES_DATABASE
038: .b(DISPLAY_NAME);
039: private final static LinearXPath XPATH_ACTUAL_NAME = XPATH_DATABASES_DATABASE
040: .b(ACTUAL_NAME);
041: private final static LinearXPath XPATH_REFERENCE_HANDLE = XPATH_DATABASES_DATABASE
042: .b(REFERENCE_HANDLE);
043:
044: //
045: private ArrayList displayNames = null;
046: private ArrayList actualNames = null;
047: private ArrayList referenceHandles = null;
048:
049: private ApplicationStoreSet() {
050: this .displayNames = new ArrayList();
051: this .actualNames = new ArrayList();
052: this .referenceHandles = new ArrayList();
053: }
054:
055: public final static ApplicationStoreSet newInstance(
056: ConfigService inCs) {
057:
058: ApplicationStoreSet outValue = new ApplicationStoreSet();
059:
060: ConfigInstanceConfig cic = inCs
061: .accessConfig(ConfigInstance.DATABASE);
062:
063: int icount = cic.getMandatoryPropertyCount(false,
064: XPATH_DATABASES, DATABASE);
065: for (int i = 1; i <= icount; i++) {
066: LinearXPath nextDatabaseXpath = XPATH_DATABASES.b(DATABASE,
067: i);
068: //
069: LinearXPath nextDisplayNameXpath = nextDatabaseXpath
070: .b(DISPLAY_NAME);
071: LinearXPath nextActualNameXpath = nextDatabaseXpath
072: .b(ACTUAL_NAME);
073: LinearXPath nextReferenceHandleXpath = nextDatabaseXpath
074: .b(REFERENCE_HANDLE);
075: //
076: String nextDisplayName = cic.getMandatoryProperty(false,
077: nextDisplayNameXpath);
078: String nextActualName = cic.getMandatoryProperty(false,
079: nextActualNameXpath);
080: String nextReferenceHandle = cic.getMandatoryProperty(
081: false, nextReferenceHandleXpath);
082: //
083: outValue.addDataSource(nextDisplayName, nextActualName,
084: nextReferenceHandle);
085:
086: }
087:
088: return outValue;
089: }
090:
091: //
092: private void addDataSource(String inDisplayName,
093: String inActualName, String inReferenceHandle) {
094: //
095: this .displayNames.add(inDisplayName);
096: this .actualNames.add(inActualName);
097: this .referenceHandles.add(inReferenceHandle);
098: }
099:
100: //
101: public int getDataSourceCount() {
102: return this .displayNames.size();
103: }
104:
105: public String getDisplayName(int inIndex) {
106: return ((String) this .displayNames.get(inIndex));
107: }
108:
109: public String getActualName(int inIndex) {
110: return ((String) this .actualNames.get(inIndex));
111: }
112:
113: public String getReferenceHandle(int inIndex) {
114: return ((String) this .referenceHandles.get(inIndex));
115: }
116:
117: //
118: public int getIndexOfDisplayName(String inDisplayName) {
119: return this .displayNames.indexOf(inDisplayName);
120: }
121:
122: public int getIndexOfActualName(String inActualName) {
123: return this .actualNames.indexOf(inActualName);
124: }
125:
126: public int getIndexOfReferenceHandle(String inReferenceHandle) {
127: return this.referenceHandles.indexOf(inReferenceHandle);
128: }
129: }
|