-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates an abstract extension registry
* Factors out the common functionality of the Teiid Runtime Registry into an abstract class that can be extended by similar registry implementations
- Loading branch information
Paul Richardson
committed
Jun 10, 2013
1 parent
3a65537
commit 1165869
Showing
3 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ins/org.teiid.designer.spi/src/org/teiid/designer/registry/AbstractExtensionRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.designer.registry; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.eclipse.core.runtime.IConfigurationElement; | ||
import org.eclipse.core.runtime.IExtensionRegistry; | ||
import org.eclipse.core.runtime.Platform; | ||
|
||
/** | ||
* @param <K> | ||
* @param <V> | ||
*/ | ||
public abstract class AbstractExtensionRegistry<K, V> { | ||
|
||
private static final String CLASS_ATTRIBUTE_ID = "class"; //$NON-NLS-1$ | ||
|
||
private Map<K, V> extensions = new HashMap<K, V>(); | ||
|
||
private String extPointId; | ||
|
||
private String elementId; | ||
|
||
protected AbstractExtensionRegistry(String extPointId, String elementId) throws Exception { | ||
this.extPointId = extPointId; | ||
this.elementId = elementId; | ||
load(); | ||
} | ||
|
||
private void load() throws Exception { | ||
IExtensionRegistry extRegistry = Platform.getExtensionRegistry(); | ||
IConfigurationElement[] extensions = extRegistry.getConfigurationElementsFor(extPointId); | ||
|
||
for (IConfigurationElement element : extensions) { | ||
if (elementId != null && !elementId.equals(element.getName())) | ||
continue; | ||
|
||
V extension = (V) element.createExecutableExtension(CLASS_ATTRIBUTE_ID); | ||
register(element, extension); | ||
} | ||
} | ||
|
||
protected abstract void register(IConfigurationElement configurationElement, V extension); | ||
|
||
protected void register(K key, V value) { | ||
extensions.put(key, value); | ||
} | ||
|
||
/** | ||
* Get a register value applicable for the given key | ||
* | ||
* @param key | ||
* | ||
* @return instance of V | ||
*/ | ||
public V getRegistered(K key) { | ||
return extensions.get(key); | ||
} | ||
|
||
/** | ||
* @return all the registered keys | ||
*/ | ||
public Collection<K> getRegisteredKeys() { | ||
return Collections.unmodifiableCollection(extensions.keySet()); | ||
} | ||
|
||
/** | ||
* @return all the registered extensions | ||
*/ | ||
public Collection<V> getRegistered() { | ||
return Collections.unmodifiableCollection(extensions.values()); | ||
} | ||
|
||
protected Collection<Map.Entry<K, V>> getRegisteredEntries() { | ||
return Collections.unmodifiableCollection(extensions.entrySet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters