KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > AbstractStore


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.vfs;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 import com.sslexplorer.policyframework.LaunchSession;
33 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException;
34 import com.sslexplorer.vfs.webdav.DAVException;
35 import com.sslexplorer.vfs.webdav.DAVStatus;
36 import com.sslexplorer.vfs.webdav.DAVUtilities;
37
38 /**
39  * Abstract {@link VFSStore} implementation.
40  *
41  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
42  */

43 public abstract class AbstractStore implements VFSStore {
44     final static Log log = LogFactory.getLog(AbstractStore.class);
45
46     // Privaet instance variables
47

48     private VFSRepository repository;
49     private VFSProvider provider;
50     private String JavaDoc name;
51     private String JavaDoc charset;
52
53
54     /**
55      * Constructor.
56      *
57      * @param name name
58      * @param charset encoding
59      */

60     public AbstractStore(String JavaDoc name, String JavaDoc charset) {
61         super();
62         this.name = name;
63         this.charset = charset;
64     }
65
66     /* (non-Javadoc)
67      * @see com.sslexplorer.vfs.VFSStore#getMountPath(java.lang.String)
68      */

69     public String JavaDoc getMountPath(String JavaDoc mountName) {
70         return getName() + "/" + mountName;
71     }
72
73     /* (non-Javadoc)
74      * @see com.sslexplorer.vfs.VFSStore#getEncoding()
75      */

76     public String JavaDoc getEncoding() {
77         return charset;
78     }
79
80     /* (non-Javadoc)
81      * @see com.sslexplorer.vfs.VFSStore#getName()
82      */

83     public String JavaDoc getName() {
84         return name;
85     }
86
87     /* (non-Javadoc)
88      * @see com.sslexplorer.vfs.VFSStore#getGuestUsername()
89      */

90     public String JavaDoc getGuestUsername() {
91         return null;
92     }
93
94     /* (non-Javadoc)
95      * @see com.sslexplorer.vfs.VFSStore#getGuestPassword()
96      */

97     public char[] getGuestPassword() {
98         return null;
99     }
100
101     /* (non-Javadoc)
102      * @see com.sslexplorer.vfs.VFSStore#init(com.sslexplorer.vfs.VFSRepository, com.sslexplorer.vfs.VFSProvider)
103      */

104     public void init(VFSRepository repository, VFSProvider provider) {
105         this.repository = repository;
106         this.provider = provider;
107     }
108     
109     /* (non-Javadoc)
110      * @see com.sslexplorer.vfs.VFSStore#getProvider()
111      */

112     public VFSProvider getProvider() {
113         return provider;
114     }
115
116     /* (non-Javadoc)
117      * @see com.sslexplorer.vfs.VFSStore#getRepository()
118      */

119     public VFSRepository getRepository() {
120         return repository;
121     }
122
123     /* (non-Javadoc)
124      * @see com.sslexplorer.vfs.VFSStore#getStoreResource()
125      */

126     public VFSResource getStoreResource() throws DAVException {
127         try {
128             return new AbstractStoreResource(getName(), repository);
129         } catch (URISyntaxException JavaDoc e) {
130             throw new DAVException(DAVStatus.SC_INTERNAL_SERVER_ERROR, "Failed to create store resource.", e);
131         }
132     }
133
134     class AbstractStoreResource extends AbstractVFSResource {
135
136         AbstractStoreResource(String JavaDoc name, VFSRepository repository) throws URISyntaxException JavaDoc {
137             super(new LaunchSession(getRepository().getSession()), new URI JavaDoc(name), true, name, repository.getRepositoryResource(), AbstractStore.this.repository);
138         }
139
140         public Iterator JavaDoc getChildren() throws IOException JavaDoc, DAVAuthenticationRequiredException {
141             List JavaDoc<VFSResource> l = new ArrayList JavaDoc<VFSResource>();
142             try {
143                 for (String JavaDoc mountName : getMountNames()) {
144                     l.add(new MountVFSResource(mountName, this));
145                 }
146             } catch (DAVAuthenticationRequiredException dare) {
147             } catch (Exception JavaDoc e) {
148                 log.error("Failed to get store resources.", e);
149             }
150             return l.iterator();
151         }
152
153     }
154     
155     class MountVFSResource extends AbstractVFSResource {
156
157         MountVFSResource(String JavaDoc mountName, VFSResource parent) throws URISyntaxException JavaDoc {
158             super(new LaunchSession(getRepository().getSession()), new URI JavaDoc(DAVUtilities.encodePath(mountName)), true, mountName, parent, AbstractStore.this.repository);
159         }
160
161         
162     }
163 }
Popular Tags