KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > repository > impl > WebDAVRepositoryTransactionHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.repository.impl;
17
18 import java.io.IOException JavaDoc;
19
20 import org.apache.avalon.framework.activity.Disposable;
21 import org.apache.avalon.framework.component.Component;
22 import org.apache.avalon.framework.logger.AbstractLogEnabled;
23 import org.apache.avalon.framework.service.ServiceException;
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.avalon.framework.service.Serviceable;
26 import org.apache.cocoon.components.repository.helpers.CredentialsToken;
27 import org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper;
28 import org.apache.cocoon.components.webdav.WebDAVUtil;
29 import org.apache.commons.httpclient.HttpException;
30
31 /**
32  * A transaction an locking helper class
33  * intended to be used by flowscripts or corresponding wrapper components.
34  */

35 public class WebDAVRepositoryTransactionHelper extends AbstractLogEnabled
36 implements RepositoryTransactionHelper, Serviceable, Disposable, Component {
37     
38     /* The ServiceManager */
39     private ServiceManager manager;
40
41     /* The repository component */
42     private WebDAVRepository repo;
43
44     /* The credentials to be used against the WebDAV repository */
45     private CredentialsToken credentials;
46
47     /* (non-Javadoc)
48      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
49      */

50     public void service(ServiceManager manager) throws ServiceException {
51         this.manager = manager;
52     }
53
54     /* (non-Javadoc)
55      * @see org.apache.avalon.framework.activity.Disposable#dispose()
56      */

57     public void dispose() {
58         this.manager = null;
59     }
60
61     /**
62      * create a WebDAVRepositoryTransactionHelper
63      *
64      * @param credentials the user credentials to be used against the WebDAV repository.
65      * @param repo a reference to the WebDAVRepository object.
66      */

67     public WebDAVRepositoryTransactionHelper(CredentialsToken credentials, WebDAVRepository repo) {
68         this.credentials = credentials;
69         this.repo = repo;
70     }
71
72     /* (non-Javadoc)
73      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#beginTran()
74      */

75     public boolean beginTran() {
76         //may be implemented via DeltaV activities?
77
throw new UnsupportedOperationException JavaDoc();
78     }
79
80     /* (non-Javadoc)
81      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#commitTran()
82      */

83     public boolean commitTran() {
84         //may be implemented via DeltaV activities?
85
throw new UnsupportedOperationException JavaDoc();
86     }
87
88     /* (non-Javadoc)
89      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#rollbackTran()
90      */

91     public boolean rollbackTran() {
92         //may be implemented via DeltaV activities?
93
throw new UnsupportedOperationException JavaDoc();
94     }
95
96     /* (non-Javadoc)
97      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#lock(java.lang.String)
98      */

99     public boolean lock(String JavaDoc uri) {
100
101         try {
102             return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).lockMethod();
103             
104         } catch (HttpException he) {
105             this.getLogger().error("HTTP Error locking " + uri, he);
106         } catch (IOException JavaDoc ioe) {
107             this.getLogger().error("IO Error locking " + uri, ioe);
108         }
109
110         return false;
111     }
112
113     /* (non-Javadoc)
114      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#lock(java.lang.String, int)
115      */

116     public boolean lock(String JavaDoc uri, int timeout) {
117
118         try {
119             return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri))
120                       .lockMethod(this.credentials.getPrincipal().getName(), timeout);
121                       
122         } catch (HttpException he) {
123             this.getLogger().error("HTTP Error locking " + uri, he);
124         } catch (IOException JavaDoc ioe) {
125             this.getLogger().error("IO Error locking " + uri, ioe);
126         }
127
128         return false;
129     }
130
131     /* (non-Javadoc)
132      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#unlock(java.lang.String)
133      */

134     public boolean unlock(String JavaDoc uri) {
135
136         try {
137             return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).unlockMethod();
138
139         } catch (HttpException he) {
140             this.getLogger().error("HTTP Error unlocking " + uri, he);
141         } catch (IOException JavaDoc ioe) {
142             this.getLogger().error("IO Error unlocking " + uri, ioe);
143         }
144
145         return false;
146     }
147
148     /* (non-Javadoc)
149      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#supportsTransactions()
150      */

151     public boolean supportsTransactions() {
152         //may be implemeted via DeltaV activities? --> make configurable
153
return false;
154     }
155
156     /* (non-Javadoc)
157      * @see org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#supportsLocking()
158      */

159     public boolean supportsLocking() {
160         return true;
161     }
162
163 }
Popular Tags