blob: 3285857b7e81fce62b1b11b8d0b6030a00c29f56 (
plain) (
blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*******************************************************************************
* Copyright (c) 2009, 2019 IBM Corporation and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.common.internal.pde;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jst.jsf.common.JSFCommonPlugin;
/**
* A utility base class that simplifies the reading and caching of extension
* point information.
*
* @author cbateman
* @param <T>
*
*/
public abstract class AbstractRegistryReader<T>
{
private final String _extPtNamespace;
private final String _extPtId;
private List<T> _extensions;
private final AtomicBoolean _isInitialized = new AtomicBoolean(false);
/**
* @param extPtNamespace
* @param extPtId
*/
protected AbstractRegistryReader(final String extPtNamespace,
final String extPtId)
{
_extPtNamespace = extPtNamespace;
_extPtId = extPtId;
}
/**
* @return the extensions
*/
public final List<T> getExtensions()
{
synchronized (_isInitialized)
{
if (_isInitialized.compareAndSet(false, true))
{
SafeRunner.run(new ISafeRunnable()
{
public void run() throws Exception
{
initialize();
}
public void handleException(Throwable exception)
{
// This is expected during testing if there running as JUnit test (non-plugin)
JSFCommonPlugin.log(exception, "Loading extension point"); //$NON-NLS-1$
}
});
}
return _extensions;
}
}
/**
* @param extensions
*/
protected final void internalSetExtensions(List<T> extensions)
{
if (_extensions != null)
{
throw new IllegalStateException(
"internalSetExtensions should be called exactly once"); //$NON-NLS-1$
}
_extensions = Collections.unmodifiableList(extensions);
}
/**
* Called exactly once to initialize the registry.
*/
protected abstract void initialize();
/**
* @return the extension point id. see IConfigurationElement.getName
*/
protected final String getExtPtId()
{
return _extPtId;
}
/**
* @return the namespace of the extension point. see Bundle.getSymbolicName
*/
protected final String getExtPtNamespace()
{
return _extPtNamespace;
}
}
|