Author: scabanovich
Date: 2011-03-25 21:51:17 -0400 (Fri, 25 Mar 2011)
New Revision: 30052
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/
trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/cdiextensions.exsd
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
Log:
JBIDE-3120
https://issues.jboss.org/browse/JBIDE-3120
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2011-03-26 00:13:47
UTC (rev 30051)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2011-03-26 01:51:17
UTC (rev 30052)
@@ -28,6 +28,7 @@
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: JBoss by Red Hat
Export-Package: org.jboss.tools.cdi.core,
+ org.jboss.tools.cdi.core.extension,
org.jboss.tools.cdi.core.preferences,
org.jboss.tools.cdi.internal.core.ca,
org.jboss.tools.cdi.internal.core.el,
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2011-03-26 00:13:47 UTC (rev
30051)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2011-03-26 01:51:17 UTC (rev
30052)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
+ <extension-point id="cdiextensions" name="CDI Extensions"
schema="schema/cdiextensions.exsd"/>
<extension
id="cdibuilder"
@@ -175,4 +176,4 @@
</exclude>
</validator>
</extension>
-</plugin>
\ No newline at end of file
+</plugin>
Added: trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/cdiextensions.exsd
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/cdiextensions.exsd
(rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/cdiextensions.exsd 2011-03-26
01:51:17 UTC (rev 30052)
@@ -0,0 +1,116 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.cdi.core"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.jboss.tools.cdi.core"
id="cdiextensions" name="CDI Extensions"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="cdiextension" minOccurs="1"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="cdiextension">
+ <complexType>
+ <attribute name="class" type="string"
use="required">
+ <annotation>
+ <documentation>
+ Fully qualified name of implementation of CDIExtension interface
representing in JBoss Tools CDI model an extension of CDI runtime model.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.cdi.core.extension.ICDIExtension"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="runtime" type="string"
use="required">
+ <annotation>
+ <documentation>
+ Fully qualified name of implementation of CDI runtime extension. The
names are listed in files /META-INF/services/javax.enterprise.inject.spi.Extension
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="features" type="string">
+ <annotation>
+ <documentation>
+ Comma separated list of ids of features supported by this cdi
extension. This is an optimisation parameter that allows to access at a specific feature
request only instances of extensions registered for that feature.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.core/schema/cdiextensions.exsd
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2011-03-26
00:13:47 UTC (rev 30051)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2011-03-26
01:51:17 UTC (rev 30052)
@@ -28,6 +28,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IType;
+import org.jboss.tools.cdi.core.extension.CDIExtensionManager;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
@@ -63,6 +64,8 @@
Set<CDICoreNature> dependsOn = new HashSet<CDICoreNature>();
Set<CDICoreNature> usedBy = new HashSet<CDICoreNature>();
+
+ private CDIExtensionManager extensions = new CDIExtensionManager(this);
public CDICoreNature() {
definitions.setProject(this);
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java 2011-03-26
01:51:17 UTC (rev 30052)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.core.extension;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.osgi.framework.Bundle;
+
+public class CDIExtensionFactory {
+ static CDIExtensionFactory factory = null;
+ public static String POINT_ID = "org.jboss.tools.cdi.core.cdiextensions";
+
+ public static CDIExtensionFactory getInstance() {
+ if(factory == null) {
+ factory = new CDIExtensionFactory();
+ }
+ return factory;
+ }
+
+ /**
+ * Maps CDI runtime fully qualified names of extension implementations to JBoss Tools
CDI Model fully
+ * qualified names of implementations of ICDIExtention.
+ */
+ private Map<String, Set<String>> runtimeToDesign = new HashMap<String,
Set<String>>();
+
+ /**
+ * Maps features to fully qualified names of implementations of ICDIExtention.
+ */
+ Map<String, Set<String>> featureToDesign = new HashMap<String,
Set<String>>();
+
+ /**
+ * Maps fully qualified names of implementations of ICDIExtention to their Class
objects.
+ */
+ Map<String, Class<? extends ICDIExtension>> designToClass = new
HashMap<String, Class<? extends ICDIExtension>>();
+
+ private CDIExtensionFactory() {
+ load();
+ }
+
+ private void load() {
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(POINT_ID);
+ IConfigurationElement[] cs = point.getConfigurationElements();
+ for (IConfigurationElement c: cs) {
+ String runtime = c.getAttribute("runtime");
+ String cls = c.getAttribute("class");
+ ICDIExtension extension = null;
+ try {
+ extension = (ICDIExtension)c.createExecutableExtension("class");
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ continue;
+ }
+ if(extension == null) continue;
+
+ designToClass.put(cls, extension.getClass());
+
+ Set<String> classes = runtimeToDesign.get(runtime);
+ if(classes == null) {
+ classes = new HashSet<String>();
+ runtimeToDesign.put(runtime, classes);
+ }
+ classes.add(cls);
+
+ String features = c.getAttribute("features");
+ StringTokenizer st = new StringTokenizer(features, ",");
+ while(st.hasMoreTokens()) {
+ String feature = st.nextToken();
+ classes = featureToDesign.get(feature);
+ if(classes == null) {
+ classes = new HashSet<String>();
+ featureToDesign.put(feature, classes);
+ }
+ classes.add(cls);
+ }
+ }
+ }
+
+ public Set<String> getExtensionClassesByRuntime(String qualifiedName) {
+ return runtimeToDesign.get(qualifiedName);
+ }
+
+ public ICDIExtension createExtensionInstance(String qualifiedName) {
+ Class<? extends ICDIExtension> cls = designToClass.get(qualifiedName);
+ if(cls != null) {
+ try {
+ return cls.newInstance();
+ } catch (InstantiationException e1) {
+ CDICorePlugin.getDefault().logError(e1);
+ } catch (IllegalAccessException e2) {
+ CDICorePlugin.getDefault().logError(e2);
+ }
+ }
+
+ return null;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java 2011-03-26
01:51:17 UTC (rev 30052)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.core.extension;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.tools.cdi.core.CDICoreNature;
+
+public class CDIExtensionManager {
+ CDICoreNature n;
+ Set<String> runtimes = new HashSet<String>();
+
+ Map<String, ICDIExtension> instances = new HashMap<String,
ICDIExtension>();
+ Map<String, Set<ICDIExtension>> featureToExtensions = new HashMap<String,
Set<ICDIExtension>>();
+
+ public CDIExtensionManager(CDICoreNature n) {
+ this.n = n;
+ }
+
+ public void setRuntimes(Set<String> runtimes) {
+ Set<String> addedRuntimes = new HashSet<String>();
+ Set<String> deletedRuntimes = new HashSet<String>();
+ for (String runtime: this.runtimes) {
+ if(!runtimes.contains(runtime)) {
+ deletedRuntimes.add(runtime);
+ }
+ }
+ for (String runtime: runtimes) {
+ if(!this.runtimes.contains(runtime)) {
+ addedRuntimes.add(runtime);
+ }
+ }
+
+ for (String runtime: deletedRuntimes) {
+ runtimes.remove(runtime);
+ Set<String> clss =
CDIExtensionFactory.getInstance().getExtensionClassesByRuntime(runtime);
+ for (String cls: clss) {
+ ICDIExtension ext = instances.remove(cls);
+ if(ext != null) {
+ String[] is = featureToExtensions.keySet().toArray(new String[0]);
+ for (String feature: is) {
+ Set<ICDIExtension> es = featureToExtensions.get(feature);
+ if(es != null) {
+ es.remove(ext);
+ if(es.isEmpty()) featureToExtensions.remove(feature);
+ }
+ }
+ }
+ }
+ }
+
+ for (String runtime: addedRuntimes) {
+ runtimes.add(runtime);
+ Set<String> clss =
CDIExtensionFactory.getInstance().getExtensionClassesByRuntime(runtime);
+ for (String cls: clss) {
+ ICDIExtension ext = CDIExtensionFactory.getInstance().createExtensionInstance(cls);
+ if(ext == null) continue;
+ //TODO initialize ext object.
+ instances.put(cls, ext);
+ Map<String, Set<String>> featureToDesign =
CDIExtensionFactory.getInstance().featureToDesign;
+ for (String feature: featureToDesign.keySet()) {
+ if(featureToDesign.get(feature).contains(cls)) {
+ Set<ICDIExtension> es = featureToExtensions.get(feature);
+ if(es == null) {
+ es = new HashSet<ICDIExtension>();
+ featureToExtensions.put(feature, es);
+ }
+ es.add(ext);
+ }
+ }
+ }
+ }
+
+ }
+
+ static Set<ICDIExtension> EMPTY = new HashSet<ICDIExtension>();
+
+ public Set<ICDIExtension> getExtensions(String feature) {
+ return featureToExtensions.containsKey(feature) ? featureToExtensions.get(feature) :
EMPTY;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java 2011-03-26
01:51:17 UTC (rev 30052)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.core.extension;
+
+/**
+ * This object represents CDI runtime extension in JBoss Tools CDI model.
+ * It is not necessarily one to one mapping between CDI runtime extension implementation
classes
+ * and JBoss Tools CDI model extension implementation classes.
+ * Mapping is set by Eclipse extension point
'org.jboss.tools.cdi.core.cdiextensions'
+ * where attribute 'id' is assigned to a CDI runtime extension implementation
class qualified name
+ * and attribute 'class' is assigned to a JBoss Tools CDI model extension
implementation class
+ * qualified name.
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface ICDIExtension {
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain