001: // LookupResult.java
002: // $Id: LookupResult.java,v 1.4 2000/11/09 12:48:15 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.tools.resources;
007:
008: /**
009: * This class is the result of the lookup algorithm.
010: */
011: public class LookupResult {
012: public static final int FILTERS_INIT_SIZE = 8;
013: public static final int FILTERS_INCR = 4;
014:
015: /**
016: * Any reply that can be computed during lookup.
017: */
018: protected ReplyInterface reply = null;
019: /**
020: * The current target of the lookup operation.
021: */
022: protected ResourceReference target = null;
023: /**
024: * The current set of computed filters to be applied on the resource.
025: */
026: protected ResourceFilter filters[] = null;
027: /**
028: * The number of registered filters at this point.
029: */
030: protected int flength = -1;
031:
032: /**
033: * Get the current lookup target of the lookup in progress.
034: * @return An ResourceReference, that may be <strong>null</strong>.
035: */
036:
037: public ResourceReference getTarget() {
038: return target;
039: }
040:
041: /**
042: * Set the current target of the lookup operation.
043: * @param target The new current target of the lookup in progress.
044: */
045: public void setTarget(ResourceReference target) {
046: this .target = target;
047: }
048:
049: /**
050: * Get the reply generated during the lookup.
051: * @return A ReplyInterface instance.
052: */
053: public ReplyInterface getReply() {
054: return reply;
055: }
056:
057: /**
058: * Set the reply generated during the lookup.
059: * @param reply A ReplyInterface instance.
060: */
061: public void setReply(ReplyInterface reply) {
062: this .reply = reply;
063: }
064:
065: /**
066: * Does this LookupResult has a Reply.
067: * @return a boolean.
068: */
069: public boolean hasReply() {
070: return reply != null;
071: }
072:
073: /**
074: * Add a filter, to be invoked by the resource's <code>perform</code>
075: * method.
076: * @param filter The HTTPFIlter to be called.
077: */
078: public void addFilter(ResourceFilter filter) {
079: if (filters == null) {
080: // Create the filters array:
081: filters = new ResourceFilter[FILTERS_INIT_SIZE];
082: flength = 0;
083: filters[flength++] = filter;
084: } else {
085: if (flength >= filters.length) {
086: // Resize the filters array:
087: ResourceFilter nf[] = new ResourceFilter[filters.length
088: + FILTERS_INCR];
089: System.arraycopy(filters, 0, nf, 0, filters.length);
090: filters = nf;
091: }
092: filters[flength++] = filter;
093: }
094: return;
095: }
096:
097: /**
098: * Add a set of filters to be invoked by the resource's <code>
099: * perform</code> method.
100: * @param filters The array of filters to register.
101: */
102:
103: public void addFilters(ResourceFilter fs[]) {
104: if (filters == null) {
105: flength = fs.length;
106: filters = new ResourceFilter[Math.max(FILTERS_INIT_SIZE,
107: flength)];
108: System.arraycopy(fs, 0, filters, 0, flength);
109: } else {
110: int rs = flength + fs.length;
111: if (rs >= filters.length) {
112: int ns = Math.max(rs, filters.length + FILTERS_INCR);
113: ResourceFilter nf[] = new ResourceFilter[ns];
114: System.arraycopy(filters, 0, nf, 0, flength);
115: filters = nf;
116: }
117: System.arraycopy(fs, 0, filters, flength, fs.length);
118: flength += fs.length;
119: }
120: return;
121: }
122:
123: /**
124: * Get the full list of filters to be applied when performing on the
125: * resource.
126: * @return An array of ResourceFilter instances, or <strong>null</strong>
127: * if none is defined.
128: */
129:
130: public ResourceFilter[] getFilters() {
131: if (filters != null) {
132: // Fix the filter array size first:
133: if (filters.length != flength) {
134: ResourceFilter f[] = new ResourceFilter[flength];
135: System.arraycopy(filters, 0, f, 0, flength);
136: filters = f;
137: }
138: }
139: return filters;
140: }
141:
142: /**
143: * Create a new empty lookup result object.
144: * @param target The root target of the lookup operation to run.
145: */
146:
147: public LookupResult(ResourceReference target) {
148: this.target = target;
149: }
150: }
|