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.persistence;
20:
21: import org.apache.openjpa.conf.OpenJPAConfiguration;
22: import org.apache.openjpa.kernel.BrokerFactory;
23: import org.apache.openjpa.lib.conf.PluginValue;
24:
25: /**
26: * Plugin type used to represent the {@link EntityManagerFactory}.
27: *
28: * @since 0.4.1
29: * @nojavadoc
30: */
31: public class EntityManagerFactoryValue extends PluginValue {
32:
33: /**
34: * Configuration property key.
35: */
36: public static final String KEY = "EntityManagerFactory";
37:
38: public static final String[] ALIASES = { "default",
39: EntityManagerFactoryImpl.class.getName(), };
40:
41: /**
42: * Create a new factory of the configured type.
43: */
44: public static OpenJPAEntityManagerFactory newFactory(
45: BrokerFactory bf) {
46: OpenJPAConfiguration conf = bf.getConfiguration();
47: PluginValue val = (PluginValue) conf.getValue(KEY);
48: if (val == null)
49: return null;
50: EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) val
51: .instantiate(EntityManagerFactoryImpl.class, conf, true);
52: emf.setBrokerFactory(bf);
53: return emf;
54: }
55:
56: public EntityManagerFactoryValue() {
57: super (KEY, false);
58: setAliases(ALIASES);
59: setDefault(ALIASES[0]);
60: setClassName(ALIASES[1]);
61: setScope(getClass());
62: }
63: }
|