001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package soif;
012:
013: import util.ReportError;
014:
015: /**
016: * Get schema.
017: * <p>
018: * The expected return is SOIF instances, first of an RDM
019: * header then of a schema. The RDM header is checked for
020: * status and, if it exists, the remaining SOIF is converted
021: * into a schema data structure. Once all this is completed,
022: * the thread terminates and the schema can be requested by
023: * calling getSchema().
024: * <p>
025: * An additional bit of prep that can be done by the SchemaGetter
026: * is the "disappear" business. This calls a method that goes
027: * through the schema and sets a flag on each attribute depending
028: * on whether that attribute is <b>searchable</b> or not.
029: * Currently, only indexed attributes are searchable.
030: * <p>
031: * <b><font color="#FF0050">Note:</font></b>
032: * The RDMHeader class is not currently used to formulate requests.
033: * <b>This may change.</b>
034: * Both <i>SchemaGetter</i> and <i>TaxonomyGetter</i> initialize
035: * their RDM header strings with a correct RDM request.
036: * Because there are other schema and taxonomy requests that can be
037: * made which are currently not well (or not at all) documented
038: * the standard request can be changed using <i>setRDMHeader()</i>
039: * which allows you to put in anything but prevents you from changing
040: * the request during processing (the scope of the processing
041: * phase far exceeds the requirement for safe operation).
042: * The <i>setRDMHeader()</i> method should be used with the
043: * understanding that the interface will very likely change.
044: * It is also possible that the constructors will change,
045: * but the most likely scenario is that RDMHeader savvy
046: * constructors will be added.
047: */
048: public class SchemaGetter extends SOIFGetter {
049: /**
050: * Structured version of the schema.
051: */
052: private Schema schema;
053:
054: /**
055: * Constructor.
056: */
057: public SchemaGetter() {
058: super ();
059: }
060:
061: /**
062: * Constructor.
063: * @param CGILocation cgi path
064: * @param exe cgi executable
065: * @param csid compass server id
066: */
067: public SchemaGetter(String CGILocation, String exe, CSID csid) {
068: super (CGILocation, exe, csid);
069: schema = null;
070: setRDMHead("type=schema-description-request&csid="
071: + csid.toString());
072: }
073:
074: /**
075: * Return schema.
076: */
077: public Schema getSchema() {
078: if (schema == null)
079: ReportError
080: .reportError(ReportError.INTERNAL, "SchemaGetter",
081: "getSchema", Messages.NOSCHEMAFOUND);
082: return schema;
083: }
084:
085: /**
086: * Run the thread, obtain the schema.
087: */
088: public void run() {
089: if (getStatus() != PREPARED) {
090: ReportError.reportError(ReportError.INTERNAL,
091: "SchemaGetter", "run", Messages.UNINITIALIZED);
092: System.out.println(Messages.COMPLETESCHEMATHREAD);
093: return;
094: }
095:
096: boolean errors = false;
097:
098: try {
099: getSOIF();
100: if (getStatus() == ABEND) {
101: errors = true;
102: return;
103: }
104:
105: if (sl == null) {
106: ReportError
107: .reportError(ReportError.INTERNAL,
108: "SchemaGetter", "run",
109: Messages.GETSOIFNEXTNULL);
110: System.out.println(slp.toRawSOIFString());
111: errors = true;
112: return;
113: }
114:
115: schema = new Schema(sl);
116: if (!schema.isValid()) {
117: ReportError.reportError(ReportError.INTERNAL,
118: "SchemaGetter", "run", Messages.BADSCHEMA);
119: errors = true;
120: return;
121: }
122: } finally {
123: if (errors)
124: setStatus(ABEND);
125: else
126: setStatus(COMPLETE);
127:
128: System.out.println(Messages.COMPLETESCHEMATHREAD);
129: }
130: }
131:
132: }
|