KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > commonimpl > LockInfoImpl


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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.outerj.daisy.repository.commonimpl;
17
18 import org.outerj.daisy.repository.LockInfo;
19 import org.outerj.daisy.repository.LockType;
20 import org.outerx.daisy.x10.LockInfoDocument;
21
22 import java.util.Date JavaDoc;
23 import java.util.GregorianCalendar JavaDoc;
24
25 public class LockInfoImpl implements LockInfo {
26     private boolean hasLock;
27     private long userId;
28     private Date JavaDoc timeAcquired;
29     private long duration;
30     private LockType lockType;
31
32     public LockInfoImpl() {
33         this.hasLock = false;
34     }
35
36     public LockInfoImpl(long userId, Date JavaDoc timeAcquired, long duration, LockType lockType) {
37         this.hasLock = true;
38         this.userId = userId;
39         this.timeAcquired = timeAcquired;
40         this.duration = duration;
41         this.lockType = lockType;
42     }
43
44     public long getUserId() {
45         return userId;
46     }
47
48     public Date JavaDoc getTimeAcquired() {
49         return timeAcquired;
50     }
51
52     public long getDuration() {
53         return duration;
54     }
55
56     public LockType getType() {
57         return lockType;
58     }
59
60     public boolean hasLock() {
61         return hasLock;
62     }
63
64     public LockInfoDocument getXml() {
65         LockInfoDocument lockInfoDocument = LockInfoDocument.Factory.newInstance();
66         LockInfoDocument.LockInfo lockInfoXml = lockInfoDocument.addNewLockInfo();
67
68         if (!hasLock) {
69             lockInfoXml.setHasLock(false);
70         } else {
71             lockInfoXml.setHasLock(true);
72             lockInfoXml.setUserId(userId);
73             GregorianCalendar JavaDoc timeAcquiredCalendar = new GregorianCalendar JavaDoc();
74             timeAcquiredCalendar.setTime(timeAcquired);
75             lockInfoXml.setTimeAcquired(timeAcquiredCalendar);
76             lockInfoXml.setDuration(duration);
77             lockInfoXml.setType(LockInfoDocument.LockInfo.Type.Enum.forString(lockType.toString()));
78         }
79
80         return lockInfoDocument;
81     }
82 }
83
Popular Tags