01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.conf;
20:
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: import org.apache.openjpa.kernel.AutoDetach;
25: import org.apache.openjpa.lib.conf.StringListValue;
26:
27: /**
28: * Value type used to represent auto detach flags. Separate to
29: * optimize translation of Strings to bit flags.
30: *
31: * @author Steve Kim
32: * @nojavadoc
33: */
34: class AutoDetachValue extends StringListValue {
35:
36: public static final String DETACH_CLOSE = "close";
37: public static final String DETACH_COMMIT = "commit";
38: public static final String DETACH_ROLLBACK = "rollback";
39: public static final String DETACH_NONTXREAD = "nontx-read";
40:
41: private static String[] ALIASES = new String[] { DETACH_CLOSE,
42: String.valueOf(AutoDetach.DETACH_CLOSE), DETACH_COMMIT,
43: String.valueOf(AutoDetach.DETACH_COMMIT), DETACH_NONTXREAD,
44: String.valueOf(AutoDetach.DETACH_NONTXREAD),
45: DETACH_ROLLBACK,
46: String.valueOf(AutoDetach.DETACH_ROLLBACK),
47: // for compatibility with JDO DetachAllOnCommit
48: "true", String.valueOf(AutoDetach.DETACH_COMMIT), "false",
49: "0", };
50:
51: private int _flags;
52: private boolean _flagsSet;
53:
54: public AutoDetachValue() {
55: super ("AutoDetach");
56: setAliases(ALIASES);
57: setAliasListComprehensive(true);
58: }
59:
60: public Class getValueType() {
61: return String[].class;
62: }
63:
64: public void setConstant(int flags) {
65: _flags = flags;
66: }
67:
68: public int getConstant() {
69: if (!_flagsSet) {
70: String[] vals = get();
71: for (int i = 0; i < vals.length; i++)
72: _flags |= Integer.parseInt(unalias(vals[i]));
73: _flagsSet = true;
74: }
75:
76: return _flags;
77: }
78:
79: protected List getAliasList() {
80: // We do not document the numeric values and they are not
81: // helpful to someone trying to understand the error message
82: ArrayList list = new ArrayList();
83: for (int x = 0; x < ALIASES.length; x += 2)
84: list.add(ALIASES[x]);
85: return list;
86: }
87: }
|