KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > util > ResourceWithProvidedProperties


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ResourceWithProvidedProperties.java,v 1.5 2004/07/28 09:32:07 ib Exp $
3  * $Revision: 1.5 $
4  * $Date: 2004/07/28 09:32:07 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.util;
25
26 import java.util.Enumeration;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.Set;
30
31 import org.apache.slide.common.PropertyName;
32 import org.apache.slide.common.SlideException;
33 import org.apache.slide.content.NodeProperty;
34 import org.apache.slide.content.NodeRevisionDescriptor;
35 import org.apache.slide.content.NodeRevisionDescriptors;
36 import org.apache.slide.search.PropertyProvider;
37 import org.apache.slide.search.RequestedResource;
38
39 /**
40  * This is an adapter that creates a RequestedResource from a given
41  * NodeRevisionDescriptor(s). Additionally to the properties provided
42  * by the descriptor also the properties of the given PropertyProvider
43  * are provided by this resource.
44  *
45  * @version $Revision: 1.5 $
46  *
47  */

48 public class ResourceWithProvidedProperties implements RequestedResource {
49     
50     /**
51      * The NodeRevisionDescriptors this resource is based on.
52      */

53     protected NodeRevisionDescriptors revisionDescriptors = null;
54     
55     /**
56      * The NodeRevisionDescriptor this resource is based on.
57      */

58     protected NodeRevisionDescriptor revisionDescriptor = null;
59     
60     /**
61      * The PropertyProvider that provides the additional properties.
62      */

63     protected PropertyProvider propertyProvider = null;
64     
65     /**
66      * Creates a ResourceWithProvidedProperties.
67      *
68      * @param revisionDescriptors the NodeRevisionDescriptors this resource
69      * is based on.
70      * @param revisionDescriptor the NodeRevisionDescriptor this resource
71      * is based on.
72      * @param propertyProvider the PropertyProvider that provides the
73      * additional properties (may be <code>null</code>).
74      */

75     public ResourceWithProvidedProperties(NodeRevisionDescriptors revisionDescriptors,
76                                           NodeRevisionDescriptor revisionDescriptor,
77                                           PropertyProvider propertyProvider) {
78         
79         this.revisionDescriptors = revisionDescriptors;
80         this.revisionDescriptor = revisionDescriptor;
81         this.propertyProvider = propertyProvider;
82     }
83     
84     /**
85      * Returns the URI of the resource.
86      *
87      * @return the URI of the resource.
88      */

89     public String getUri() {
90         return revisionDescriptors.getOriginalUri();
91     }
92     
93     /**
94      * Returns the property with the given <code>propertyName</code>.
95      *
96      * @param propertyName the PropertyName of the property.
97      *
98      * @return the property with the given <code>npropertyNameame</code>.
99      *
100      * @throws SlideException
101      */

102     public NodeProperty getProperty(PropertyName propertyName) throws SlideException {
103         return getProperty(propertyName.getName(), propertyName.getNamespace());
104     }
105     
106     /**
107      * Returns the property with the given <code>name</code> and
108      * <code>namespace</code>.
109      *
110      * @param name the name of the property.
111      * @param namespace the namespace URI of the property.
112      *
113      * @return the property with the given <code>name</code> and
114      * <code>namespace</code>.
115      *
116      * @throws SlideException
117      */

118     public NodeProperty getProperty(String name, String namespace) throws SlideException {
119         
120         if ( (propertyProvider != null) &&
121             propertyProvider.isSupportedProperty(getUri(), name, namespace) ) {
122             return propertyProvider.getProperty(getUri(), name, namespace);
123         }
124         else {
125             return revisionDescriptor.getProperty(name, namespace);
126         }
127     }
128     
129     /**
130      * Returns an Iterator of PropertyName of all properties.
131      *
132      * @return an Iterator of PropertyName.
133      *
134      * @throws SlideException
135      */

136     public Iterator getAllPropertiesNames() throws SlideException {
137         
138         Set propertyNamesList = new HashSet();
139         Enumeration enum = revisionDescriptor.enumerateProperties();
140         NodeProperty property = null;
141         if (enum != null) {
142             while (enum.hasMoreElements()) {
143                 property = (NodeProperty)enum.nextElement();
144                 propertyNamesList.add(new PropertyName(property.getName(),
145                                                        property.getNamespace()));
146             }
147         }
148         
149         if (propertyProvider != null) {
150         Iterator iterator = propertyProvider.getSupportedPropertiesNames(getUri());
151         while (iterator.hasNext()) {
152             propertyNamesList.add(iterator.next());
153         }
154         }
155         
156         return propertyNamesList.iterator();
157     }
158     
159     /**
160      * Returns all properties as an Iterator of NodeProperty objects.
161      *
162      * @return all properties as an Iterator of NodeProperty objects.
163      *
164      * @throws SlideException
165      */

166     public Iterator getAllProperties() throws SlideException {
167         
168         Set propertyList = new HashSet();
169         Enumeration enum = revisionDescriptor.enumerateProperties();
170         if (enum != null) {
171             while (enum.hasMoreElements()) {
172                 propertyList.add(enum.nextElement());
173             }
174         }
175         
176         if (propertyProvider != null) {
177         Iterator iterator = propertyProvider.getSupportedProperties(getUri());
178         while (iterator.hasNext()) {
179             propertyList.add(iterator.next());
180             }
181         }
182         
183         return propertyList.iterator();
184     }
185     
186 }
187
188
Popular Tags