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: import org.w3c.dom.Attr;
014: import org.w3c.dom.CharacterData;
015: import org.w3c.dom.Element;
016: import org.w3c.dom.NamedNodeMap;
017: import org.w3c.dom.Node;
018: import org.w3c.dom.NodeList;
019:
020: //project specific classes
021: import org.jfolder.common.UnexpectedSystemException;
022: import org.jfolder.common.files.VirtualFileSystemDirectory;
023: import org.jfolder.common.web.template.CreationResultParameterContext;
024:
025: //other classes
026:
027: public class ConceptTagCharacteristicHolder {
028:
029: private final static String DIR_PREFIX = RootConceptTagHolder.DIR_PREFIX;
030: private final static String FILE_PREFIX = RootConceptTagHolder.FILE_PREFIX;
031: //
032: private boolean initialized = false;
033: //
034: private ConceptTag ct = null;
035: private boolean ctPresent = false;
036: //
037: private ConceptTagPreferences ctp = null;
038: //private ConceptTagMessageHolder ctmh = null;
039: //
040: private HashMap ctcharMap = null;
041: private ArrayList ctcharArray = null;
042: //
043: private ConceptTagMessageHolder parentCtmh = null;
044: //private HashMap ctmhMap = null;
045: //
046: private ConceptTagCharacteristicHolder attrsCtcharh = null;
047: private ConceptTagCharacteristicHolder styleCtcharh = null;
048: //
049: private boolean attrsType = false;
050: private boolean styleType = false;
051: //
052: private ConceptTagCharacteristic undefinedCtchar = null;
053: //
054: private ConceptTagCharacteristicHolder parentCtcharh = null;
055: private ConceptTagCharacteristic parentCtchar = null;
056: private int parentIndex = 0;
057: //
058: private VirtualFileSystemDirectory vsd = null;
059: //
060: private boolean markedAsDeleted = false;
061: //
062: private CreationResultParameterContext initCrpc = null;
063: private String initCrpcId[] = null;
064:
065: //
066: //private ConceptTagFlags ctf = null;
067:
068: private ConceptTagCharacteristicHolder(ConceptTagPreferences inCtp,
069: boolean inStyles, boolean inAttributes,
070: VirtualFileSystemDirectory inVsd) {
071:
072: //
073: this .ct = null;
074: this .ctPresent = false;
075: //
076: //this.ctmh = new ConceptTagMessageHolder();
077: this .ctp = inCtp;
078: //
079: this .ctcharMap = new HashMap();
080: this .ctcharArray = new ArrayList();
081: //
082: this .parentCtmh = new ConceptTagMessageHolder();
083: //this.ctmhMap = new HashMap();
084: //
085: if (inStyles) {
086: this .attrsCtcharh = null;
087: this .styleCtcharh = null;
088: //
089: this .attrsType = false;
090: this .styleType = true;
091: //
092: this .undefinedCtchar = null;
093: } else if (inAttributes) {
094: this .attrsCtcharh = null;
095: this .styleCtcharh = null;
096: //
097: this .attrsType = true;
098: this .styleType = false;
099: //
100: this .undefinedCtchar = null;
101: } else {
102: this .attrsCtcharh = new ConceptTagCharacteristicHolder(
103: inCtp, false, true, null);
104: this .attrsCtcharh.setParentCharacteristicHolder(this );
105: this .styleCtcharh = new ConceptTagCharacteristicHolder(
106: inCtp, true, false, null);
107: this .styleCtcharh.setParentCharacteristicHolder(this );
108: //
109: this .attrsType = false;
110: this .styleType = false;
111: //
112: this .undefinedCtchar = ConceptTagCharacteristic
113: .newInstance(inCtp, inCtp.getUnconstrainedSymbol(),
114: this );
115: }
116: //
117: this .vsd = inVsd;
118: //
119: //this.ctf = new ConceptTagFlags();
120: }
121:
122: protected final static ConceptTagCharacteristicHolder newInstance(
123: ConceptTag inCt, ConceptTagPreferences inCtp,
124: ConceptTagCharacteristic inParentCtchar, int inParentIndex) {
125:
126: ConceptTagCharacteristicHolder outValue = null;
127:
128: outValue = new ConceptTagCharacteristicHolder(inCtp, false,
129: false, inParentCtchar
130: .createDirectoryOrNull(inParentIndex));
131: outValue.setConceptTag(inCt);
132: outValue.setParentCharacteristic(inParentCtchar, inParentIndex);
133:
134: return outValue;
135: }
136:
137: public void copyTo(ConceptTagCharacteristicHolder inDestCtcharh) {
138:
139: //
140: if (this .isAttributesType() && inDestCtcharh.isAttributesType()) {
141: } else if (this .isStylesType() && inDestCtcharh.isStylesType()) {
142: } else if (this .isNeitherAttributesNorStylesType()
143: && inDestCtcharh.isNeitherAttributesNorStylesType()) {
144: //
145: this .getAttributes().copyTo(inDestCtcharh.getAttributes());
146: this .getStyles().copyTo(inDestCtcharh.getStyles());
147: this .getUndefinedCharacteristic().copyTo(
148: inDestCtcharh.getUndefinedCharacteristic());
149: } else {
150: throw UnexpectedSystemException.unknownState();
151: }
152:
153: //
154: for (int i = 0; i < getCharacteristicCount(); i++) {
155: ConceptTagCharacteristic nextSourCtchar = getCharacteristic(i);
156: ConceptTagCharacteristic nextDestCtchar = inDestCtcharh
157: .registerCharacteristic(nextSourCtchar
158: .getConstraintName());
159: nextSourCtchar.copyTo(nextDestCtchar);
160: }
161: }
162:
163: protected final static ConceptTagCharacteristicHolder createRoot(
164: ConceptTagPreferences inCtp, RootConceptTagHolder inRcth) {
165:
166: ConceptTagCharacteristicHolder outValue = null;
167:
168: VirtualFileSystemDirectory localVsd = null;
169: if (inCtp.isFileSystemPresent()) {
170: localVsd = inRcth.getLocalFilesDirectory();
171: }
172: outValue = new ConceptTagCharacteristicHolder(inCtp, false,
173: false, localVsd);
174: outValue.setParentCharacteristic(null, 0);
175:
176: return outValue;
177: }
178:
179: protected final static ConceptTagCharacteristicHolder newInstance(
180: ConceptTagPreferences inCtp,
181: ConceptTagCharacteristic inParentCtchar, int inParentIndex) {
182:
183: ConceptTagCharacteristicHolder outValue = null;
184:
185: outValue = new ConceptTagCharacteristicHolder(inCtp, false,
186: false, inParentCtchar
187: .createDirectoryOrNull(inParentIndex));
188: outValue.setParentCharacteristic(inParentCtchar, inParentIndex);
189:
190: return outValue;
191: }
192:
193: //
194: private boolean isLocalFilesDirectoryPresent() {
195: return (!this .attrsType && !this .styleType && this .ctp
196: .isFileSystemPresent());
197: }
198:
199: protected void setLocalFileDirectory(
200: VirtualFileSystemDirectory inVsd) {
201: this .vsd = inVsd;
202: }
203:
204: protected void recalibrateLocalFileDirectories() {
205: if (isLocalFilesDirectoryPresent()) {
206: for (int i = 0; i < getCharacteristicCount(); i++) {
207: ConceptTagCharacteristic nextCtchar = getCharacteristic(i);
208: //
209: VirtualFileSystemDirectory nextVsd = this .vsd
210: .getDirectory(DIR_PREFIX
211: + nextCtchar.getConstraintName());
212: nextCtchar.setLocalFileDirectory(nextVsd);
213: //
214: nextCtchar.recalibrateLocalFileDirectories(0);
215: }
216: }
217: }
218:
219: protected VirtualFileSystemDirectory createDirectoryOrNull(
220: String inName) {
221:
222: VirtualFileSystemDirectory outValue = null;
223:
224: if (isLocalFilesDirectoryPresent()
225: && !this .ctp.getUnconstrainedSymbol().equals(inName)) {
226:
227: outValue = this .vsd.getOrCreateLocalDirectory(DIR_PREFIX
228: + inName);
229: }
230:
231: return outValue;
232: }
233:
234: //
235: public String getHandle() {
236:
237: StringBuffer outValue = new StringBuffer();
238:
239: ArrayList handleList = getHandleAsArrayList();
240: for (int i = 0; i < handleList.size(); i++) {
241: if (i > 0) {
242: outValue.append(this .ctp.getHandleConjunction());
243: }
244: outValue.append(handleList.get(i));
245: }
246: //getHandle(outValue);
247:
248: return outValue.toString();
249: }
250:
251: //private void getHandle(StringBuffer inSb) {
252: //
253: // if (this.parentCtcharh != null) {
254: // this.parentCtcharh.getHandle(inSb);
255: // inSb.append(this.ctp.getHandleConjunction());
256: // }
257: // inSb.append(this.parentCtchar.getConstraintName());
258: // inSb.append(this.ctp.getHandleConjunction());
259: // inSb.append(this.parentIndex);
260: //}
261: //
262: public ArrayList getHandleAsArrayList() {
263:
264: ArrayList outValue = new ArrayList();
265:
266: getHandleAsArrayList(outValue);
267:
268: return outValue;
269: }
270:
271: protected void getHandleAsArrayList(ArrayList inList) {
272: if (this .attrsType) {
273: this .parentCtcharh.getHandleAsArrayList(inList);
274: inList.add(this .ctp.getAttributeConstraintName());
275: } else if (this .styleType) {
276: this .parentCtcharh.getHandleAsArrayList(inList);
277: inList.add(this .ctp.getStyleConstraintName());
278: } else if (this .parentCtchar != null) {
279: this .parentCtchar.getHandleAsArrayListWithoutIndex(inList);
280: //inList.add(this.parentCtchar.getConstraintName());
281: inList.add(this .parentIndex + "");
282: } else {
283: //do nothing, main ctcharh
284: }
285: }
286:
287: //
288: public ConceptTagMessageHolder getParentMessageHolder() {
289: return this .parentCtmh;
290: }
291:
292: //protected ConceptTagMessageHolder getMessageHolder(String inHandle) {
293: // return (ConceptTagMessageHolder)this.ctmhMap.get(inHandle);
294: //}
295: //
296:
297: private void setConceptTag(ConceptTag inCt) {
298: this .ct = inCt;
299: this .ctPresent = true;
300: }
301:
302: private void setParentCharacteristicHolder(
303: ConceptTagCharacteristicHolder inCtcharh) {
304:
305: this .parentCtcharh = inCtcharh;
306: }
307:
308: protected ConceptTagCharacteristicHolder getParentCharacteristicHolder() {
309: return this .parentCtcharh;
310: }
311:
312: //
313: protected void setParentCharacteristic(
314: ConceptTagCharacteristic inCtchar, int inIndex) {
315:
316: this .parentCtchar = inCtchar;
317: this .parentIndex = inIndex;
318: }
319:
320: public ConceptTagCharacteristic getParentCharacteristic() {
321: return this .parentCtchar;
322: }
323:
324: public int getParentCharacteristicIndex() {
325: return this .parentIndex;
326: }
327:
328: public ConceptTagCharacteristic registerCharacteristic(String inName) {
329:
330: ConceptTagCharacteristic outValue = null;
331:
332: if (inName.equals(this .ctp.getUnconstrainedSymbol())) {
333: throw new UnexpectedSystemException(
334: ("'" + inName + "' reserved for unconstrained"));
335: } else if (inName.equals(this .ctp.getAttributeConstraintName())) {
336: throw new UnexpectedSystemException(
337: ("'" + inName + "' reserved for attributes"));
338: } else if (inName.equals(this .ctp.getStyleConstraintName())) {
339: throw new UnexpectedSystemException(
340: ("'" + inName + "' reserved for styles"));
341: } else if (!this .ctcharMap.containsKey(inName)) {
342: outValue = ConceptTagCharacteristic.newInstance(this .ctp,
343: inName, this );
344: this .ctcharMap.put(inName, outValue);
345: this .ctcharArray.add(inName);
346: //this.ctmhMap.put(inName, new ConceptTagMessageHolder());
347: } else {
348: throw new UnexpectedSystemException(
349: ("'" + inName + "' already registered"));
350: }
351:
352: return outValue;
353: }
354:
355: //
356: public boolean isConceptTagPresent() {
357: return this .ctPresent;
358: }
359:
360: public ConceptTag getConceptTag() {
361: return this .ct;
362: }
363:
364: //
365: //protected ConceptTagMessageHolder getMessageHolder() {
366: // return this.ctmh;
367: //}
368:
369: //
370: public ConceptTagPreferences getPreferences() {
371: return this .ctp;
372: }
373:
374: //
375: public boolean isCharacteristicPresent(String inName) {
376: return this .ctcharMap.containsKey(inName);
377: }
378:
379: public ConceptTagCharacteristic getCharacteristic(String inName) {
380:
381: ConceptTagCharacteristic outValue = null;
382:
383: if (this .ctcharMap.containsKey(inName)) {
384: outValue = (ConceptTagCharacteristic) this .ctcharMap
385: .get(inName);
386: } else {
387: throw new UnexpectedSystemException("Characteristic '"
388: + inName + "' does not exist");
389: }
390:
391: return outValue;
392: }
393:
394: public int getCharacteristicCount() {
395: return this .ctcharArray.size();
396: }
397:
398: public ConceptTagCharacteristic getCharacteristic(int inIndex) {
399:
400: ConceptTagCharacteristic outValue = null;
401:
402: String ctcharName = (String) this .ctcharArray.get(inIndex);
403: if (this .ctcharMap.containsKey(ctcharName)) {
404: outValue = (ConceptTagCharacteristic) this .ctcharMap
405: .get(ctcharName);
406: } else {
407: throw new UnexpectedSystemException("Characteristic '"
408: + ctcharName + "' does not exist");
409: }
410:
411: return outValue;
412: }
413:
414: //
415: public boolean isStylesType() {
416: return this .styleType;
417: }
418:
419: public ConceptTagCharacteristicHolder getAttributes() {
420: return this .attrsCtcharh;
421: }
422:
423: //
424: public boolean isAttributesType() {
425: return this .attrsType;
426: }
427:
428: public ConceptTagCharacteristicHolder getStyles() {
429: return this .styleCtcharh;
430: }
431:
432: //
433: private boolean isNeitherAttributesNorStylesType() {
434: return (!isAttributesType() && !isStylesType());
435: }
436:
437: //
438: public ConceptTagCharacteristic getUndefinedCharacteristic() {
439: return this .undefinedCtchar;
440: }
441:
442: //
443: protected void setInitialized(boolean inInitialized) {
444: this .initialized = inInitialized;
445: }
446:
447: protected boolean isInitialized() {
448: return this .initialized;
449: }
450:
451: //
452: public boolean isMarkedAsDeleted() {
453: return this .markedAsDeleted;
454: }
455:
456: protected void signalMarkedAsDeleted() {
457:
458: this .markedAsDeleted = true;
459:
460: if (isAttributesType()) {
461: } else if (isStylesType()) {
462: } else if (this .isNeitherAttributesNorStylesType()) {
463: //
464: getAttributes().signalMarkedAsDeleted();
465: getStyles().signalMarkedAsDeleted();
466: getUndefinedCharacteristic().signalMarkedAsDeleted();
467: } else {
468: throw UnexpectedSystemException.unknownState();
469: }
470:
471: for (int i = 0; i < getCharacteristicCount(); i++) {
472: ConceptTagCharacteristic nextCtchar = getCharacteristic(i);
473: nextCtchar.signalMarkedAsDeleted();
474: }
475: }
476:
477: //
478: protected boolean isInitCreationResultPresent() {
479: return (this .initCrpc != null && this .initCrpcId != null);
480: }
481:
482: protected Object[] extractInitCreationResult() {
483:
484: Object outValue[] = new Object[2];
485:
486: outValue[0] = this .initCrpc;
487: outValue[1] = this .initCrpcId;
488: //
489: this .initCrpc = null;
490: this .initCrpcId = null;
491:
492: return outValue;
493: }
494:
495: protected void insertInitCreationResult(
496: CreationResultParameterContext inCrpc, String inCrpcId[]) {
497: //
498: if (!isConceptTagPresent()) {
499: throw new UnexpectedSystemException(
500: "Can only put CreationResults when Concept Tag is present");
501: }
502: //
503: this .initCrpc = inCrpc;
504: this .initCrpcId = inCrpcId;
505: }
506:
507: //
508: //public ConceptTagFlags getFlags() {
509: // return this.ctf;
510: //}
511: //protected void setFlags(ConceptTagFlags inCtf) {
512: // this.ctf = inCtf;
513: //}
514: //
515: protected void process(NodeList inNl, NamedNodeMap inNnm) {
516:
517: //
518: this .initialized = true;
519: //
520: if (isNeitherAttributesNorStylesType()) {
521: getAttributes().setInitialized(true);
522: getStyles().setInitialized(true);
523: }
524: //
525: String conUri = ctp.getConstraintNamespace();
526: String conLocal = ctp.getConstraintName();
527: //
528: if (inNnm != null) {
529: //
530: //
531: for (int i = 0; i < inNnm.getLength(); i++) {
532: //
533: Attr nextAttr = (Attr) inNnm.item(i);
534: String nextNs = nextAttr.getNamespaceURI();
535: String nextName = nextAttr.getLocalName();
536: String nextValue = nextAttr.getValue();
537: //
538: String styleUri = ctp.getStyleNamespace();
539: String styleLocal = ctp.getStyleName();
540: //
541: boolean attrStyle = false;
542: if (styleUri != null && nextNs != null) {
543: attrStyle = (styleUri.equals(nextNs) && styleLocal
544: .equals(nextName));
545: } else if (styleUri == null && nextNs == null) {
546: attrStyle = (styleLocal.equals(nextName));
547: }
548: //
549: boolean attrNotConstraint = true;
550: if (conUri != null && nextNs != null) {
551: attrNotConstraint = !(conUri.equals(nextNs) && conLocal
552: .equals(nextName));
553: } else if (conUri == null && nextNs == null) {
554: attrNotConstraint = !(conLocal.equals(nextName));
555: }
556: //
557: if (attrStyle) {
558: processStyleAttributes(nextValue);
559: } else if (attrNotConstraint) {
560: if (nextNs != null) {
561: if (!nextAttr.getPrefix().equals("xmlns")) {
562: throw new UnexpectedSystemException(
563: "Not Implemented - "
564: + nextAttr.getPrefix());
565: } else {
566: //ignore, it's a namespace definition
567: }
568: } else {
569: ConceptTagCharacteristic nextCtchar = this .attrsCtcharh
570: .registerCharacteristic(nextName);
571: nextCtchar.addValue(0, nextValue);
572: }
573: } else {
574: //attribute is constraint, already handled, not here
575: }
576: }
577: }
578:
579: for (int i = 0; i < inNl.getLength(); i++) {
580: Node nextNode = inNl.item(i);
581: if (nextNode instanceof Element) {
582: Element nextEle = (Element) nextNode;
583: if (getPreferences().isConstraintUsed()) {
584: Attr conAttr = null;
585:
586: if (conUri != null) {
587: conAttr = nextEle.getAttributeNodeNS(conUri,
588: conLocal);
589: } else {
590: conAttr = nextEle.getAttributeNode(conLocal);
591: }
592:
593: if (conAttr != null) {
594: String conName = conAttr.getValue();
595:
596: ConceptTagCharacteristic nextCtchar = null;
597: if (isCharacteristicPresent(conName)) {
598: nextCtchar = getCharacteristic(conName);
599: } else {
600: //if (this.ctp.isFileSystemPresent()
601: // && !this.attrsType && !this.styleType) {
602: // VirtualSystemDirectory nextVsd =
603: // this.vsd.createDirectory(
604: // DIR_PREFIX + conName);
605: // nextCtchar = registerCharacteristic(
606: // conName, nextVsd);
607: //}
608: //else {
609: nextCtchar = registerCharacteristic(conName);
610: //}
611: }
612:
613: nextCtchar.processData(nextEle);
614: } else {
615: this .undefinedCtchar.processData(nextEle);
616: }
617: } else {
618: this .undefinedCtchar.processData(nextEle);
619: }
620: } else if (nextNode instanceof CharacterData) {
621: this .undefinedCtchar.processData(nextNode);
622: } else {
623: throw new UnexpectedSystemException(("Unknown Node - "
624: + nextNode + "," + nextNode.getClass()));
625: }
626: //
627: }
628: }
629:
630: //
631: private void processStyleAttributes(String inValue) {
632: //the goal of this function is to parse name/value information
633: //and assign it to WebStyleAttribute and UndefinedWebStyleAttribute
634:
635: int currentSingleQuoteCount = 0;
636: int lastSemiColon = -1;
637:
638: for (int i = 0; i < inValue.length(); i++) {
639:
640: char nextChar = inValue.charAt(i);
641:
642: //TO DO: how can you express backslash? maybe with escape char?
643: if (nextChar == '\'') {
644: currentSingleQuoteCount++;
645: } else if (nextChar == ';'
646: && (currentSingleQuoteCount % 2) != 1) {
647:
648: String nextValue = inValue.substring(lastSemiColon + 1,
649: i);
650: processStyleInstance(nextValue);
651: lastSemiColon = i;
652: }
653: }
654: String nextValue = inValue.substring(lastSemiColon + 1);
655: processStyleInstance(nextValue);
656: }
657:
658: private void processStyleInstance(String inValue) {
659:
660: //
661: final String COLON = ":";
662:
663: String trimValue = inValue.trim();
664: if (trimValue.length() > 0) {
665:
666: int firstColon = -1;
667:
668: for (int i = 0; i < trimValue.length(); i++) {
669: if ((trimValue.charAt(i) + "").equals(COLON)) {
670: firstColon = i;
671: break;
672: }
673: }
674:
675: String nextName = "";
676: String nextValue = "";
677:
678: if (firstColon != -1) {
679: int firstNonColon = firstColon + COLON.length();
680: nextName = trimValue.substring(0, firstNonColon);
681: nextValue = trimValue.substring(firstNonColon).trim();
682: } else {
683: nextName = trimValue;
684: }
685:
686: if (nextName.endsWith(COLON)) {
687: nextName = nextName.substring(0, nextName.length()
688: - COLON.length());
689: }
690:
691: //
692: ConceptTagCharacteristic nextCtchar = this .styleCtcharh
693: .registerCharacteristic(nextName);
694: nextCtchar.addValue(0, nextValue);
695:
696: }
697: }
698:
699: //
700: public int hashCode() {
701:
702: int outValue = 0;
703:
704: //
705: if (this .ct != null) {
706: outValue = outValue
707: + this .ct.getClass().getName().hashCode();
708: }
709:
710: //
711: if (this .attrsCtcharh != null) {
712: outValue = outValue + this .attrsCtcharh.hashCode();
713: }
714:
715: //
716: if (this .styleCtcharh != null) {
717: outValue = outValue + this .styleCtcharh.hashCode();
718: }
719:
720: //
721: if (this .undefinedCtchar != null) {
722: for (int i = 0; i < this .undefinedCtchar.getValueLength(); i++) {
723: if (this .undefinedCtchar.isStatic(i, null)) {
724: outValue = outValue
725: + this .undefinedCtchar.getValueAsString(i,
726: null).hashCode();
727: } else if (this .undefinedCtchar.isHolder(i, null)) {
728: outValue = outValue
729: + this .undefinedCtchar.getValueAsHolder(i,
730: null).hashCode();
731: } else {
732: throw UnexpectedSystemException.unknownState();
733: }
734: }
735: }
736:
737: //
738: for (int i = 0; i < this .ctcharArray.size(); i++) {
739: String nextCtcharName = ((String) this .ctcharArray.get(i));
740: ConceptTagCharacteristic nextCtchar = (ConceptTagCharacteristic) this .ctcharMap
741: .get(nextCtcharName);
742: //
743: for (int j = 0; j < nextCtchar.getValueLength(); j++) {
744: if (nextCtchar.isStatic(j, null)) {
745: outValue = outValue
746: + nextCtchar.getValueAsString(j, null)
747: .hashCode();
748: } else if (nextCtchar.isHolder(j, null)) {
749: outValue = outValue
750: + nextCtchar.getValueAsHolder(j, null)
751: .hashCode();
752: } else {
753: throw UnexpectedSystemException.unknownState();
754: }
755: }
756: }
757:
758: return outValue;
759: }
760:
761: public boolean equals(Object inObject) {
762:
763: boolean outValue = false;
764:
765: if (inObject instanceof ConceptTagCharacteristicHolder) {
766:
767: outValue = true;
768:
769: ConceptTagCharacteristicHolder ctcharh2 = (ConceptTagCharacteristicHolder) inObject;
770:
771: //
772: if (this .isConceptTagPresent()
773: && ctcharh2.isConceptTagPresent()) {
774: String ct1 = this .getConceptTag().getClass().getName();
775: String ct2 = ctcharh2.getConceptTag().getClass()
776: .getName();
777: outValue &= ct1.equals(ct2);
778: } else if (!this .isConceptTagPresent()
779: && !ctcharh2.isConceptTagPresent()) {
780: //
781: //both do not have ConceptTag, no further processing
782: } else {
783: outValue = false;
784: }
785:
786: //
787: if (this .attrsCtcharh != null
788: && ctcharh2.attrsCtcharh != null) {
789: outValue &= this .attrsCtcharh
790: .equals(ctcharh2.attrsCtcharh);
791: } else if (this .attrsCtcharh == null
792: && ctcharh2.attrsCtcharh == null) {
793: //
794: //both do not have attributes, no further processing
795: } else {
796: outValue = false;
797: }
798:
799: //
800: if (this .styleCtcharh != null
801: && ctcharh2.styleCtcharh != null) {
802: outValue &= this .styleCtcharh
803: .equals(ctcharh2.styleCtcharh);
804: } else if (this .styleCtcharh == null
805: && ctcharh2.styleCtcharh == null) {
806: //
807: //both do not have styles, no further processing
808: } else {
809: outValue = false;
810: }
811:
812: //
813: outValue &= compare(this .undefinedCtchar,
814: ctcharh2.undefinedCtchar);
815:
816: //
817: for (int i = 0; i < this .getCharacteristicCount(); i++) {
818: ConceptTagCharacteristic ctchar1 = this
819: .getCharacteristic(i);
820: String ctchar1Name = ctchar1.getConstraintName();
821: if (ctcharh2.isCharacteristicPresent(ctchar1Name)) {
822: //
823: ConceptTagCharacteristic ctchar2 = ctcharh2
824: .getCharacteristic(ctchar1Name);
825: //
826: outValue &= compare(ctchar1, ctchar2);
827: } else {
828: outValue &= compare(ctchar1, null);
829: }
830: }
831: //
832: for (int i = 0; i < ctcharh2.getCharacteristicCount(); i++) {
833: ConceptTagCharacteristic ctchar2 = ctcharh2
834: .getCharacteristic(i);
835: String ctchar2Name = ctchar2.getConstraintName();
836: if (this .isCharacteristicPresent(ctchar2Name)) {
837: //
838: //ConceptTagCharacteristic ctchar1 =
839: // this.getCharacteristic(ctchar2Name);
840: //
841: //outValue &= compare(ctchar1, ctchar2);
842: //comparison already done above, no need to repeat
843: } else {
844: outValue &= compare(null, ctchar2);
845: }
846: }
847: } else {
848: outValue = false;
849: }
850:
851: return outValue;
852: }
853:
854: private final static boolean compare(
855: ConceptTagCharacteristic inCtchar1,
856: ConceptTagCharacteristic inCtchar2) {
857:
858: boolean outValue = true;
859:
860: if (inCtchar1 != null && inCtchar2 != null) {
861: if (inCtchar1.getValueLength() == inCtchar2
862: .getValueLength()) {
863: for (int i = 0; i < inCtchar1.getValueLength(); i++) {
864: if (inCtchar1.isStatic(i, null)
865: && inCtchar2.isStatic(i, null)) {
866: //
867: outValue &= inCtchar1.getValueAsString(i, null)
868: .equals(
869: inCtchar2.getValueAsString(i,
870: null));
871: } else if (inCtchar1.isHolder(i, null)
872: && inCtchar2.isHolder(i, null)) {
873: //
874: outValue &= inCtchar1.getValueAsHolder(i, null)
875: .equals(
876: inCtchar2.getValueAsHolder(i,
877: null));
878: } else if (inCtchar1.isStatic(i, null)
879: && inCtchar2.isHolder(i, null)) {
880: //
881: outValue = false;
882: } else if (inCtchar1.isHolder(i, null)
883: && inCtchar2.isStatic(i, null)) {
884: //
885: outValue = false;
886: } else {
887: throw UnexpectedSystemException.unknownState();
888: }
889: }
890: } else {
891: outValue = false;
892: }
893: } else if (inCtchar1 == null && inCtchar2 == null) {
894: outValue = true;
895: } else {
896: if (inCtchar1 != null) {
897: outValue = (inCtchar1.getValueLength() == 0);
898: } else {
899: outValue = (inCtchar2.getValueLength() == 0);
900: }
901: }
902:
903: return outValue;
904: }
905:
906: //private void explore(int inHashCode[], boolean inElementPresent[]) {
907: //
908: // //
909: // if (this.ct != null) {
910: // inHashCode
911: // }
912: //
913: // //
914: // if (this.attrsCtcharh != null) {
915: // this.attrsCtcharh.explore(inHashCode, inElementPresent);
916: // }
917: // //
918: // if (this.styleCtcharh != null) {
919: // this.styleCtcharh.explore(inHashCode, inElementPresent);
920: // }
921: // //
922: // if (this.undefinedCtchar != null) {
923: // }
924: //}
925: }
|