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.common.tagging;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.web.template.CreationParameterContext;
017:
018: //other classes
019:
020: public class StudioConceptTagCreParInfoContextHolder {
021:
022: //
023: private ArrayList scpcList = null;
024: private HashMap scpchForNamespace = null;
025: private HashMap scpchForClass = null;
026:
027: //
028: private StudioConceptTagCreParInfoContextHolder() {
029: this .scpcList = new ArrayList();
030: this .scpchForNamespace = new HashMap();
031: this .scpchForClass = new HashMap();
032: }
033:
034: //
035: public final static StudioConceptTagCreParInfoContextHolder newInstance(
036: ConceptTagSetHolder inCtsh) {
037: //
038: StudioConceptTagCreParInfoContextHolder outValue = new StudioConceptTagCreParInfoContextHolder();
039:
040: ArrayList namespaces = inCtsh.getRegisteredNameSpaces();
041: for (int i = 0; i < namespaces.size(); i++) {
042:
043: String nextNamespace = ((String) namespaces.get(i));
044: ArrayList names = inCtsh.getRegisteredNames(nextNamespace);
045: for (int j = 0; j < names.size(); j++) {
046: String nextName = ((String) names.get(j));
047: Class nextClass = inCtsh.getConceptTagClass(
048: nextNamespace, nextName);
049: ConceptTag nextCt = inCtsh
050: .getConceptTagFromClass(nextClass);
051: //
052: StudioConceptTagCreParInfoContext nextScpc = new StudioConceptTagCreParInfoContext(
053: null, null);
054: nextCt.appraise(nextScpc);
055: outValue.registerCreationParameter(nextNamespace,
056: nextName, nextClass, nextScpc);
057: }
058: }
059:
060: return outValue;
061: }
062:
063: //
064: public int getCreationParameterContextCount() {
065: return this .scpcList.size();
066: }
067:
068: public CreationParameterContext getCreationParameterContext(
069: int inIndex) {
070: //
071: CreationParameterContext outValue = null;
072:
073: Object o = this .scpcList.get(inIndex);
074: outValue = ((CreationParameterContext) o);
075:
076: return outValue;
077: }
078:
079: private void registerCreationParameter(String inNs, String inName,
080: Class inClass, StudioConceptTagCreParInfoContext inScpc) {
081: //
082: //
083: //
084: HashMap names = null;
085: if (isNamespacePresent(inNs)) {
086: names = ((HashMap) this .scpchForNamespace.get(inNs));
087: } else {
088: names = new HashMap();
089: this .scpchForNamespace.put(inNs, names);
090: }
091: //
092: HashMap scpcForName = null;
093: if (isNamePresent(inNs, inName)) {
094: throw new UnexpectedSystemException("Namespace '" + inNs
095: + "' with name '" + inName
096: + "' already has a Creation Parameter registered");
097: } else {
098: scpcForName = new HashMap();
099: names.put(inName, scpcForName);
100: }
101: //
102: //
103: //
104: HashMap scpcForClass = null;
105: if (this .scpchForClass.containsKey(inClass)) {
106: throw new UnexpectedSystemException("Class '" + inClass
107: + "' already has a Creation Parameter registered");
108: } else {
109: scpcForClass = new HashMap();
110: this .scpchForClass.put(inClass.getName(), scpcForClass);
111: }
112: //
113: //
114: //
115: ArrayList constraintHeirarchies = inScpc
116: .getConstraintHeirarchies();
117: for (int i = 0; i < constraintHeirarchies.size(); i++) {
118: ArrayList nextConstraintHeirarchy = ((ArrayList) constraintHeirarchies
119: .get(i));
120: Integer nextIndex = new Integer(this .scpcList.size());
121: //
122: this .scpcList.add(inScpc
123: .getCreationParameter(nextConstraintHeirarchy));
124: //
125: scpcForName.put(nextConstraintHeirarchy, nextIndex);
126: //
127: scpcForClass.put(nextConstraintHeirarchy, nextIndex);
128: }
129: //
130: //
131: //
132: //this.scpchForClass.put(inClass, inScpc);
133: }
134:
135: //
136: public boolean isNamespacePresent(String inNs) {
137: return this .scpchForNamespace.containsKey(inNs);
138: }
139:
140: public boolean isNamePresent(String inNs, String inName) {
141:
142: boolean outValue = false;
143:
144: if (this .scpchForNamespace.containsKey(inNs)) {
145:
146: HashMap names = ((HashMap) this .scpchForNamespace.get(inNs));
147: outValue = names.containsKey(inName);
148: }
149:
150: return outValue;
151: }
152:
153: //
154: public boolean isClassPresent(String inClass) {
155:
156: boolean outValue = true;
157:
158: outValue = this .scpchForClass.containsKey(inClass);
159:
160: return outValue;
161: }
162:
163: public boolean isConstraintHeirarchyPresent(Class inClass,
164: String inConstraintHeirarchy[]) {
165: //
166: return isConstraintHeirarchyPresent(inClass.getName(),
167: inConstraintHeirarchy);
168: }
169:
170: public boolean isConstraintHeirarchyPresent(String inClass,
171: String inConstraintHeirarchy[]) {
172: //
173: boolean outValue = true;
174:
175: if (isClassPresent(inClass)) {
176: HashMap scpcMap = ((HashMap) this .scpchForClass
177: .get(inClass));
178: outValue = scpcMap
179: .containsKey(StudioConceptTagCreParInfoContext
180: .convertArrayToList(inConstraintHeirarchy));
181: } else {
182: outValue = false;
183: }
184:
185: return outValue;
186: }
187:
188: public int getIndex(Class inClass, String inConstraintHeirarchy[]) {
189:
190: int outValue = 0;
191:
192: outValue = getIndex(inClass.getName(), inConstraintHeirarchy);
193:
194: return outValue;
195: }
196:
197: public int getIndex(String inClass, String inConstraintHeirarchy[]) {
198:
199: int outValue = 0;
200:
201: HashMap scpcMap = ((HashMap) this .scpchForClass.get(inClass));
202: ArrayList key = StudioConceptTagCreParInfoContext
203: .convertArrayToList(inConstraintHeirarchy);
204: outValue = ((Integer) scpcMap.get(key)).intValue();
205:
206: return outValue;
207: }
208:
209: //
210: public boolean isConstraintHeirarchyPresent(String inNs,
211: String inName, String inConstraintHeirarchy[]) {
212: //
213: boolean outValue = true;
214:
215: if (isNamePresent(inNs, inName)) {
216: HashMap names = ((HashMap) this .scpchForNamespace.get(inNs));
217: HashMap scpcMap = ((HashMap) names.get(inName));
218: outValue = scpcMap
219: .containsKey(StudioConceptTagCreParInfoContext
220: .convertArrayToList(inConstraintHeirarchy));
221: } else {
222: outValue = false;
223: }
224:
225: return outValue;
226: }
227:
228: public int getIndex(String inNs, String inName,
229: String inConstraintHeirarchy[]) {
230: //
231: int outValue = 0;
232:
233: HashMap names = ((HashMap) this .scpchForNamespace.get(inNs));
234: HashMap scpcMap = ((HashMap) names.get(inName));
235: ArrayList key = StudioConceptTagCreParInfoContext
236: .convertArrayToList(inConstraintHeirarchy);
237: outValue = ((Integer) scpcMap.get(key)).intValue();
238:
239: return outValue;
240: }
241:
242: //
243:
244: //
245: public ArrayList getNamespaces() {
246:
247: ArrayList outValue = null;
248:
249: outValue = new ArrayList(this .scpchForNamespace.keySet());
250:
251: return outValue;
252: }
253:
254: public ArrayList getNames(String inNs) {
255:
256: ArrayList outValue = null;
257:
258: HashMap names = ((HashMap) this .scpchForNamespace.get(inNs));
259: outValue = new ArrayList(names.keySet());
260:
261: return outValue;
262: }
263: }
|