-
Notifications
You must be signed in to change notification settings - Fork 53
/
OSGiFactoryImpl.java
executable file
·72 lines (62 loc) · 2.4 KB
/
OSGiFactoryImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 Payara Services Ltd.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.jvnet.hk2.osgiadapter;
import static org.jvnet.hk2.osgiadapter.Logger.logger;
import com.sun.enterprise.module.common_impl.AbstractFactory;
import com.sun.enterprise.module.common_impl.ModuleId;
import com.sun.enterprise.module.ModuleDefinition;
import org.osgi.framework.BundleContext;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
/**
* @author Sanjeeb.Sahoo@Sun.COM
*/
public class OSGiFactoryImpl extends AbstractFactory {
private static final ReentrantLock slock = new ReentrantLock();
private BundleContext ctx;
public static void initialize(BundleContext ctx) {
slock.lock();
try {
if (Instance != null) {
// TODO : this is somehow invoked twice during gf startup, we need to investigate.
logger.logp(Level.FINE, "OSGiFactoryImpl", "initialize",
"Singleton already initialized as {0}", getInstance());
}
Instance = new OSGiFactoryImpl(ctx);
} finally {
slock.unlock();
}
}
private OSGiFactoryImpl(BundleContext ctx) {
this.ctx = ctx;
}
@Override
public AbstractOSGiModulesRegistryImpl createModulesRegistry() {
String val = ctx.getProperty(Constants.OBR_ENABLED);
return (val != null && Boolean.valueOf(val)) ? new OSGiObrModulesRegistryImpl(ctx) : new OSGiModulesRegistryImpl(ctx);
}
@Override
public ModuleId createModuleId(String name, String version)
{
return new OSGiModuleId(name, version);
}
@Override
public ModuleId createModuleId(ModuleDefinition md)
{
return new OSGiModuleId(md);
}
}