KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > CollectionMember


1 package com.ibm.webdav;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * IBM will not be liable for any damages suffered by you as a result
10  * of using the Program. In no event will IBM be liable for any
11  * special, indirect or consequential damages or lost profits even if
12  * IBM has been advised of the possibility of their occurrence. IBM
13  * will not be liable for any third party claims against you.
14  */

15
16 /** A CollectionMember encapsulates a Resource in a collection along with
17  * a number of live properties that might be useful to client applications.
18  * Since WebDAV requires the use of a Collection's properties to determine
19  * the members of a collection, we might as well make use of the properties returned
20  * so that clients don't have to make a lot of unnecessary server requests. The
21  * properties collected in the CollectionMember are those used by the WebDAV
22  * Explorer.
23  * @author Jim Amsden <jamsden@us.ibm.com>
24  */

25 public class CollectionMember implements java.io.Serializable JavaDoc
26 {
27    private Collection parent = null;
28    private Resource resource = null;
29    private MultiStatus properties = null;
30    private String JavaDoc name = null; // the name relative to the parent
31
/** Create a CollectionMember for a resource. Include it parent and some
32  * convenient DAV properties.
33  * @param parent the parent collection
34  * @param resource the member resource of the parent
35  * @param initialProperties a MultiStatus containing some useful DAV properties
36  */

37 public CollectionMember(Collection parent, Resource resource, MultiStatus initialProperties) throws WebDAVException {
38     this.parent = parent;
39     this.resource = resource;
40     this.properties = initialProperties;
41     String JavaDoc parentURI = parent.getURL().getFile();
42     String JavaDoc memberURI = resource.getURL().getFile();
43     name = memberURI.substring(parentURI.length());
44     // in case the parent collection didn't end with a /
45
if (name.startsWith("/")) {
46         name = name.substring(1);
47     }
48 }
49 /** Create a CollectionMember for a resource. The resource is
50  * a root collection that has no parent or properties
51  * @param resource the member resource
52  */

53 public CollectionMember(Resource resource) throws WebDAVException {
54     this.parent = null;
55     this.properties = null;
56     this.resource = resource;
57     name = resource.getURL().toString();
58 }
59 /** Return the name of the Resource in this CollectionMember relative to its parent. Use
60  * getResource().getURL().toString() to get the full URL.
61  * @return the name of this member relative to its parent collection
62  */

63 public String JavaDoc getName() {
64     return name;
65 }
66 /** Return the parent of this CollectionMember. i.e., the Collection
67  * it's associated Resource is contained in.
68  * @return the parent collection
69  */

70 public Collection getParent() {
71     return parent;
72 }
73 /** Return the properties of the Resource in this CollectionMember. These
74  * properties are retained only for convenience of client applications. The
75  * properties can always be obtained using getProperties().
76  * @return A PropertyResponse containing some useful DAV properties
77  * @see com.ibm.webdav.Resource#getProperties
78  */

79 public PropertyResponse getProperties() {
80     PropertyResponse response = (PropertyResponse) properties.getResponses().nextElement();
81     return response;
82 }
83 /** Return the Resource represented by this CollectionMember.
84  * @return the resource associted with this CollectionMember
85  */

86 public Resource getResource() {
87     return resource;
88 }
89 /** Return a String representation of this CollectionMember.
90  * @return the name of the CollectionMember
91  * @see com.ibm.webdav.CollectionMember#getName
92  */

93 public String JavaDoc toString() {
94     return getName();
95 }
96 }
97
Popular Tags