001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020: package org.openharmonise.dav.server.property.ranges;
021:
022: import org.openharmonise.commons.dsi.*;
023: import org.openharmonise.commons.xml.namespace.*;
024: import org.openharmonise.rm.resources.metadata.properties.ranges.*;
025: import org.w3c.dom.*;
026:
027: import com.ibm.webdav.*;
028:
029: /**
030: * This class wraps up the functionality for publishing Harmonise ranges to DAV XML and
031: * vice versa.
032: *
033: * @author Michael Bell
034: * @version $Revision: 1.1 $
035: * @since November 19, 2003
036: */
037: abstract public class DAVRange {
038:
039: public static final String TYPE_STRING = NamespaceType.XML_SCHEMA
040: .getPrefix()
041: + ":string";
042: public static final String TYPE_DATE = NamespaceType.XML_SCHEMA
043: .getPrefix()
044: + ":date";
045: public static final String TYPE_DATETIME = NamespaceType.XML_SCHEMA
046: .getPrefix()
047: + ":dateTime";
048: public static final String TYPE_INTEGER = NamespaceType.XML_SCHEMA
049: .getPrefix()
050: + ":integer";
051: public static final String TYPE_FLOAT = NamespaceType.XML_SCHEMA
052: .getPrefix()
053: + ":float";
054: public static final String TYPE_BOOLEAN = NamespaceType.XML_SCHEMA
055: .getPrefix()
056: + ":boolean";
057: public static final String TYPE_URI = NamespaceType.XML_SCHEMA
058: .getPrefix()
059: + ":anyURI";
060:
061: protected AbstractDataStoreInterface m_dsi = null;
062: public static final String TAG_RANGE = "range";
063: public static final String TAG_VALUE = "value";
064: public static final String TAG_MINLENGTH = "minLength";
065: public static final String TAG_MAXLENGTH = "maxLength";
066: public static final String TAG_MININCLUSIVE = "minInclusive";
067: public static final String TAG_MAXINCLUSIVE = "maxInclusive";
068: public static final String TAG_MINEXCLUSIVE = "minExclusive";
069: public static final String TAG_MAXEXCLUSIVE = "maxExclusive";
070: public static final String TAG_RESTRICTION = "restriction";
071: public static final String TAG_LABELS = "labels";
072: public static final String ATTRIB_PREFIXED_BASE = NamespaceType.XML_SCHEMA
073: .getPrefix()
074: + ":base";
075:
076: protected Range m_range = null;
077:
078: /**
079: * Creates an object with an interface to the data store.
080: */
081: public DAVRange(AbstractDataStoreInterface dsi) {
082: m_dsi = dsi;
083: }
084:
085: /**
086: * Creates an object with an interface to the data store and a Harmonise range
087: * to be published.
088: */
089: public DAVRange(AbstractDataStoreInterface dsi, Range range) {
090: m_range = range;
091: m_dsi = dsi;
092: }
093:
094: /**
095: * @param dsi
096: * @param range
097: * @param davPropEl
098: */
099: public DAVRange(AbstractDataStoreInterface dsi, Range range,
100: Element davPropEl) throws WebDAVException {
101:
102: m_range = range;
103: m_dsi = dsi;
104: populate(davPropEl);
105: }
106:
107: /**
108: * Returns this range representation as DAV XML.
109: *
110: * @param doc
111: * @return
112: * @throws WebDAVException
113: */
114: public Element asXML(Document doc) throws WebDAVException {
115: Element rangeEl = doc.createElementNS(NamespaceType.DAV
116: .getURI(), TAG_RANGE);
117: rangeEl.setPrefix(NamespaceType.DAV.getPrefix());
118:
119: addRangeDetails(rangeEl, m_range, doc);
120:
121: return rangeEl;
122:
123: }
124:
125: /**
126: * Adds range details to the given range element.
127: *
128: * <p>Note: should never get called as this method is overridden by methods
129: * dealing with specific Harmonise ranges.</p>
130: *
131: * @param rangeEl
132: * @param range
133: * @param doc
134: * @throws WebDAVException
135: */
136: abstract protected void addRangeDetails(Element rangeEl,
137: Range range, Document doc) throws WebDAVException;
138:
139: /**
140: * Returns the Harmonise range for this DAV range.
141: *
142: * @return
143: */
144: public Range getHarmoniseRange() {
145: return m_range;
146: }
147:
148: /**
149: * Populates this range object from the given XML element.
150: *
151: * @param propEl
152: * @throws WebDAVException
153: */
154: abstract public void populate(Element propEl)
155: throws WebDAVException;
156:
157: }
|