KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > property > ranges > DAVBooleanRange


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.dav.server.property.ranges;
21
22 import org.openharmonise.commons.dsi.*;
23 import org.openharmonise.commons.xml.*;
24 import org.openharmonise.commons.xml.namespace.*;
25 import org.openharmonise.rm.resources.metadata.properties.ranges.*;
26 import org.w3c.dom.*;
27
28 import com.ibm.webdav.*;
29
30 /**
31  * Class to handle the mapping between Harmonise BooleanRange and how it will be
32  * representing in DAV.
33  *
34  * @author Michael Bell
35  * @version $Revision: 1.2 $
36  * @since November 20, 2003
37  */

38 public class DAVBooleanRange extends DAVRange {
39
40     private static final String JavaDoc ATTRIB_FALSELABEL = "falseLabel";
41     private static final String JavaDoc ATTRIB_TRUELABEL = "trueLabel";
42     
43     /**
44      * @param dsi
45      */

46     public DAVBooleanRange(AbstractDataStoreInterface dsi) {
47         super(dsi,new BooleanRange());
48     }
49
50     /**
51      * @param dsi
52      * @param range
53      */

54     public DAVBooleanRange(AbstractDataStoreInterface dsi, Range range) {
55         super(dsi, range);
56     }
57
58     /**
59      * @param dsi
60      * @param davPropEl
61      */

62     public DAVBooleanRange(AbstractDataStoreInterface dsi, Element davPropEl) throws WebDAVException {
63         super(dsi,new BooleanRange(), davPropEl);
64     }
65     
66     /**
67      * Adds range details for to the given range element for boolean ranges
68      *
69      * @param rangeEl
70      * @param range
71      * @param doc
72      * @throws WebDAVException
73      */

74     protected void addRangeDetails(
75         Element rangeEl,
76         Range range,
77         Document doc) {
78         BooleanRange brange = (BooleanRange) range;
79         Element restrEl =
80             doc.createElementNS(
81                 NamespaceType.XML_SCHEMA.getURI(),
82                 TAG_RESTRICTION);
83         restrEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
84         
85         restrEl.setAttributeNS(NamespaceType.XML_SCHEMA.getURI(), ATTRIB_PREFIXED_BASE, TYPE_BOOLEAN);
86
87         restrEl.setAttribute("xmlns:" + NamespaceType.XML_SCHEMA.getPrefix(), NamespaceType.XML_SCHEMA.getURI());
88
89         Element labelsEl = doc.createElementNS(
90                 NamespaceType.OHRM.getURI(),
91                 TAG_LABELS);
92         
93         labelsEl.setAttribute("xmlns:" + NamespaceType.OHRM.getPrefix(), NamespaceType.OHRM.getURI());
94         
95         labelsEl.setPrefix(NamespaceType.OHRM.getPrefix());
96         
97         labelsEl.setAttributeNS(NamespaceType.OHRM.getURI(),NamespaceType.OHRM.getPrefix() + ":" + ATTRIB_TRUELABEL, brange.getTrueLabel());
98         labelsEl.setAttributeNS(NamespaceType.OHRM.getURI(),NamespaceType.OHRM.getPrefix() + ":" + ATTRIB_FALSELABEL, brange.getFalseLabel());
99         
100         restrEl.appendChild(labelsEl);
101         
102         rangeEl.appendChild(restrEl);
103     }
104
105     /* (non-Javadoc)
106      * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
107      */

108     public void populate(Element propEl) throws WebDAVException {
109         BooleanRange range = (BooleanRange) m_range;
110         
111         Element restrEl = XMLUtils.getFirstNamedChild(propEl, TAG_RESTRICTION);
112
113         String JavaDoc base = restrEl.getAttributeNS(NamespaceType.XML_SCHEMA.getURI(), "base");
114         
115         if(base.equals(restrEl.getPrefix() + ":boolean") == false) {
116             throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Invalid base type for this range");
117         }
118         
119         Element labelsEl = XMLUtils.getFirstNamedChild(restrEl, TAG_LABELS);
120
121         if(labelsEl != null) {
122             String JavaDoc sTrueVal = labelsEl.getAttributeNS(NamespaceType.OHRM.getURI(), ATTRIB_TRUELABEL);
123             
124             range.setTrueLabel(sTrueVal);
125             String JavaDoc sFalseVal = labelsEl.getAttributeNS(NamespaceType.OHRM.getURI(), ATTRIB_FALSELABEL);
126             
127             range.setFalseLabel(sFalseVal);
128         }
129         
130     }
131
132 }
133
Popular Tags