01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
23: import java.util.GregorianCalendar;
24:
25: public class LockInfoImpl implements LockInfo {
26: private boolean hasLock;
27: private long userId;
28: private Date 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 timeAcquired, long duration,
37: LockType lockType) {
38: this .hasLock = true;
39: this .userId = userId;
40: this .timeAcquired = timeAcquired;
41: this .duration = duration;
42: this .lockType = lockType;
43: }
44:
45: public long getUserId() {
46: return userId;
47: }
48:
49: public Date getTimeAcquired() {
50: return timeAcquired;
51: }
52:
53: public long getDuration() {
54: return duration;
55: }
56:
57: public LockType getType() {
58: return lockType;
59: }
60:
61: public boolean hasLock() {
62: return hasLock;
63: }
64:
65: public LockInfoDocument getXml() {
66: LockInfoDocument lockInfoDocument = LockInfoDocument.Factory
67: .newInstance();
68: LockInfoDocument.LockInfo lockInfoXml = lockInfoDocument
69: .addNewLockInfo();
70:
71: if (!hasLock) {
72: lockInfoXml.setHasLock(false);
73: } else {
74: lockInfoXml.setHasLock(true);
75: lockInfoXml.setUserId(userId);
76: GregorianCalendar timeAcquiredCalendar = new GregorianCalendar();
77: timeAcquiredCalendar.setTime(timeAcquired);
78: lockInfoXml.setTimeAcquired(timeAcquiredCalendar);
79: lockInfoXml.setDuration(duration);
80: lockInfoXml.setType(LockInfoDocument.LockInfo.Type.Enum
81: .forString(lockType.toString()));
82: }
83:
84: return lockInfoDocument;
85: }
86: }
|