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.HashMap;
22: import java.util.Map;
23: import java.util.Iterator;
24:
25: import org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory;
26: import org.apache.openjpa.kernel.BrokerFactory;
27: import org.apache.openjpa.lib.conf.ConfigurationProvider;
28: import org.apache.openjpa.lib.conf.PluginValue;
29: import org.apache.openjpa.lib.conf.ProductDerivations;
30: import org.apache.openjpa.lib.conf.ProductDerivation;
31:
32: /**
33: * Value type used to represent the {@link BrokerFactory}. This type is
34: * defined separately so that it can be used both in the global configuration
35: * and in {@link org.apache.openjpa.kernel.Bootstrap} with the same
36: * encapsulated configuration.
37: *
38: * @nojavadoc
39: */
40: public class BrokerFactoryValue extends PluginValue {
41:
42: public static final String KEY = "BrokerFactory";
43:
44: private static final String[] _aliases;
45: static {
46: Map aliases = new HashMap();
47: aliases.put("abstractstore", AbstractStoreBrokerFactory.class
48: .getName());
49: ProductDerivation[] ds = ProductDerivations
50: .getProductDerivations();
51: for (int i = 0; i < ds.length; i++) {
52: if (ds[i] instanceof OpenJPAProductDerivation)
53: ((OpenJPAProductDerivation) ds[i])
54: .putBrokerFactoryAliases(aliases);
55: }
56:
57: _aliases = new String[aliases.size() * 2];
58: int i = 0;
59: for (Iterator iter = aliases.entrySet().iterator(); iter
60: .hasNext();) {
61: Map.Entry e = (Map.Entry) iter.next();
62: _aliases[i++] = (String) e.getKey();
63: _aliases[i++] = (String) e.getValue();
64: }
65: }
66:
67: /**
68: * Extract the value of this property if set in the given provider.
69: */
70: public static Object get(ConfigurationProvider cp) {
71: Map props = cp.getProperties();
72: return props.get(ProductDerivations.getConfigurationKey(KEY,
73: props));
74: }
75:
76: /**
77: * Set the value of this property in the given provider.
78: */
79: public static void set(ConfigurationProvider cp, String value) {
80: String key = ProductDerivations.getConfigurationKey(KEY, cp
81: .getProperties());
82: cp.addProperty(key, value);
83: }
84:
85: public BrokerFactoryValue() {
86: super (KEY, false);
87: setAliases(_aliases);
88: }
89: }
|