01: /**********************************************************************
02: Copyright (c) 2007 Erik Bengtson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: ...
17: **********************************************************************/package org.jpox;
18:
19: import java.io.Serializable;
20:
21: /**
22: * Representation of a resource type. A Resource is a connection to the
23: * datastore. There are two kinds of resources: JTA or RESOURCE_LOCAL
24: * A transaction of a JTA resource is managed by a JTA TransactionManager,
25: * while RESOURCE_LOCAL is managed by JPOX TransactionManager
26: *
27: * @since 1.1
28: * @version $Revision: 1.1 $
29: */
30: public class ResourceType implements Serializable {
31: /** JTA transaction. */
32: public static final ResourceType JTA = new ResourceType(1);
33:
34: /** Local transaction. */
35: public static final ResourceType RESOURCE_LOCAL = new ResourceType(
36: 2);
37:
38: private final int typeId;
39:
40: private ResourceType(int i) {
41: this .typeId = i;
42: }
43:
44: /**
45: * Indicates whether some other object is "equal to" this one.
46: * @param o the reference object with which to compare.
47: * @return true if this object is the same as the obj argument; false otherwise.
48: */
49: public boolean equals(Object o) {
50: if (o instanceof ResourceType) {
51: return ((ResourceType) o).typeId == typeId;
52: }
53: return false;
54: }
55:
56: /**
57: * Returns a string representation of the object.
58: * @return a string representation of the object.
59: */
60: public String toString() {
61: switch (typeId) {
62: case 1:
63: return "JTA";
64: case 2:
65: return "RESOURCE_LOCAL";
66: }
67: return "";
68: }
69:
70: /**
71: * Accessor to the sequence strategy type
72: * @return the type
73: */
74: public int getType() {
75: return typeId;
76: }
77:
78: /**
79: * Return Sequence strategy from String.
80: * @param value sequence strategy
81: * @return Instance of SequenceStrategy. If parse failed, return null.
82: */
83: public static ResourceType getValue(final String value) {
84: if (value == null) {
85: return null;
86: } else if (ResourceType.JTA.toString().equalsIgnoreCase(value)) {
87: return ResourceType.JTA;
88: } else if (ResourceType.RESOURCE_LOCAL.toString()
89: .equalsIgnoreCase(value)) {
90: return ResourceType.RESOURCE_LOCAL;
91: }
92: return null;
93: }
94: }
|