Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList.java108
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList2.java107
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl.java30
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl2.java25
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluator.java76
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluatorFactory.java88
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementation.java70
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementationFactory.java84
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ClassAlreadyExistsException.java21
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ResourceURIExpectedException.java21
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/plugin/Activator.java68
11 files changed, 698 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList.java
new file mode 100644
index 00000000000..25d8afcb4ee
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2009 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Bertrand Daru (Mia-Software) - initial API and implementation
+ * Gregoire Dupe (Mia-Software) - initial API and implementation
+ */
+package org.eclipse.emf.facet.query.java.core.internal;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.emf.facet.efacet.EFacetFactory;
+import org.eclipse.emf.facet.efacet.Parameter;
+import org.eclipse.emf.facet.efacet.ParameterValue;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList;
+
+//deprecated APIs that are still maintained
+@SuppressWarnings("deprecation")
+public class ParameterValueList extends ArrayList<ParameterValue> implements
+ IParameterValueList {
+
+ // This class is a copy of
+ // org.eclipse.emf.facet.infra.query.core.java.ParameterValueList
+
+ /** SERIAL ID */
+ private static final long serialVersionUID = 1L;
+
+ ParameterValueList(final ParameterValue... values) {
+ this.addAll(Arrays.asList(values));
+ }
+
+ /**
+ * Return the value of the parameter with the specified name.
+ *
+ * @param name
+ * the name of the parameter
+ * @return the value, or <code>null</code> if there is no parameter with
+ * that name.
+ */
+ public Object getValueByParameterName(final String name) {
+ ParameterValue param = getParameterValueByName(name);
+ if (param == null) {
+ return null;
+ }
+ return param.getValue();
+ }
+
+ /**
+ * Return the parameter with the specified name.
+ *
+ * @param name
+ * the name of the parameter
+ * @return the parameter, or <code>null</code> if there is no parameter with
+ * that name.
+ */
+ public ParameterValue getParameterValueByName(final String name) {
+ for (ParameterValue param : this) {
+ if (param.getParameter().getName().equals(name)) {
+ return param;
+ }
+ }
+ return null;
+ }
+
+ public static ParameterValue createParameterValue(final Object value,
+ final Parameter parameter) {
+ ParameterValue paramValue = EFacetFactory.eINSTANCE
+ .createParameterValue();
+ paramValue.setParameter(parameter);
+ paramValue.getValue().add(value);
+
+ return paramValue;
+ }
+
+ /**
+ * Return the parameter corresponding to the given parameter declaration.
+ *
+ * @param parameter
+ * the parameter declaration
+ * @return the parameter, or <code>null</code> if the given parameter
+ * declaration is unknown.
+ */
+ public ParameterValue getParameterValue(final Parameter parameter) {
+ for (ParameterValue paramValue : this) {
+ if (paramValue.getParameter() == parameter) {
+ return paramValue;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the value of a parameter
+ *
+ * @param parameter
+ * the parameter
+ * @return the value of the parameter
+ */
+ public Object getValue(final Parameter parameter) {
+ return getParameterValue(parameter).getValue();
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList2.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList2.java
new file mode 100644
index 00000000000..25d9e31fd37
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueList2.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2009 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Bertrand Daru (Mia-Software) - initial API and implementation
+ * Gregoire Dupe (Mia-Software) - initial API and implementation
+ * Emmanuelle Rouillé (Mia-Software) - Bug 352618 - To be able to use non derived facet structural features and save them values.
+ * Nicolas Bros (Mia-Software) - Bug 361612 - New core for new version of the Facet metamodel
+ * David Couvrand (Soft-Maint) - Bug 418813 - [Query] Optimization in creation of ParameterValueList2
+ */
+package org.eclipse.emf.facet.query.java.core.internal;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.emf.ecore.EParameter;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList2;
+
+public class ParameterValueList2 extends ArrayList<ParameterValue> implements IParameterValueList2 {
+ // This class is a copy of
+ // org.eclipse.emf.facet.infra.query.core.java.ParameterValueList
+
+ private static final long serialVersionUID = 1L;
+
+ ParameterValueList2(final ParameterValue... values) {
+ super(Arrays.asList(values));
+ }
+
+ /**
+ * Return the value of the parameter with the specified name.
+ *
+ * @param name
+ * the name of the parameter
+ * @return the value, or <code>null</code> if there is no parameter with
+ * that name.
+ */
+ public Object getValueByParameterName(final String name) {
+ ParameterValue param = getParameterValueByName(name);
+ if (param == null) {
+ return null;
+ }
+ return param.getValue();
+ }
+
+ /**
+ * Return the parameter with the specified name.
+ *
+ * @param name
+ * the name of the parameter
+ * @return the parameter, or <code>null</code> if there is no parameter with
+ * that name.
+ */
+ public ParameterValue getParameterValueByName(final String name) {
+ for (ParameterValue param : this) {
+ EParameter parameter = param.getParameter();
+ if (parameter != null) {
+ if (name.equals(parameter.getName())) {
+ return param;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static ParameterValue createParameterValue(final Object value,
+ final EParameter parameter) {
+ ParameterValue paramValue = EFacetFactory.eINSTANCE
+ .createParameterValue();
+ paramValue.setParameter(parameter);
+ paramValue.setValue(value);
+ return paramValue;
+ }
+
+ /**
+ * Return the parameter corresponding to the given parameter declaration.
+ *
+ * @param parameter
+ * the parameter declaration
+ * @return the parameter, or <code>null</code> if the given parameter
+ * declaration is unknown.
+ */
+ public ParameterValue getParameterValue(final EParameter parameter) {
+ for (ParameterValue paramValue : this) {
+ if (paramValue.getParameter() == parameter) {
+ return paramValue;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the value of a parameter
+ *
+ * @param parameter
+ * the parameter
+ * @return the value of the parameter
+ */
+ public Object getValue(final EParameter parameter) {
+ return getParameterValue(parameter).getValue();
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl.java
new file mode 100644
index 00000000000..e44b2959b45
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 334615 - Java Query for EMF Facet
+ */
+package org.eclipse.emf.facet.query.java.core.internal;
+
+import org.eclipse.emf.facet.efacet.ParameterValue;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList;
+import org.eclipse.emf.facet.query.java.core.IParameterValueListFactory;
+
+/**
+ * Implementation of {@link IParameterValueListFactory}
+ */
+//deprecated APIs that are still maintained
+@SuppressWarnings("deprecation")
+public class ParameterValueListFactoryImpl implements
+ IParameterValueListFactory {
+
+ public IParameterValueList createParameterValueList(
+ final ParameterValue... values) {
+ return new ParameterValueList(values);
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl2.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl2.java
new file mode 100644
index 00000000000..16ad2f11caf
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/ParameterValueListFactoryImpl2.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 334615 - Java Query for EMF Facet
+ * Emmanuelle Rouillé (Mia-Software) - Bug 352618 - To be able to use non derived facet structural features and save them values.
+ */
+package org.eclipse.emf.facet.query.java.core.internal;
+
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList2;
+import org.eclipse.emf.facet.query.java.core.IParameterValueListFactory2;
+
+public class ParameterValueListFactoryImpl2 implements
+ IParameterValueListFactory2 {
+
+ public IParameterValueList2 createParameterValueList(
+ final ParameterValue... values) {
+ return new ParameterValueList2(values);
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluator.java
new file mode 100644
index 00000000000..423efac3da8
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluator.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2009 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Gregoire Dupe (Mia-Software) - initial API and implementation
+ */
+package org.eclipse.emf.facet.query.java.core.internal.evaluator;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.efacet.ParameterValue;
+import org.eclipse.emf.facet.efacet.Query;
+import org.eclipse.emf.facet.efacet.core.exception.QueryException;
+import org.eclipse.emf.facet.efacet.core.query.IQueryEvaluator;
+import org.eclipse.emf.facet.query.java.core.IJavaQuery;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList;
+import org.eclipse.emf.facet.query.java.core.IParameterValueListFactory;
+
+/**
+ * This class is the EMF Facet Java Query Evaluator
+ *
+ * @author Gregoire Dupe (Mia-Software)
+ */
+// deprecated but still maintained
+@SuppressWarnings("deprecation")
+public class JavaQueryEvaluator implements IQueryEvaluator {
+
+ // This class is modified copy of :
+ // org.eclipse.emf.facet.infra.query.core.java.internal.JavaModelQueryAdapter
+ private final IJavaQuery<EObject, ?> javaQuery;
+ private boolean checkResultType = false;
+
+ /**
+ * @param query
+ * @param javaQuery
+ * the javaQuery to be evaluated
+ */
+ public JavaQueryEvaluator(final Query query,
+ final IJavaQuery<EObject, ?> javaQuery) {
+ this.javaQuery = javaQuery;
+ }
+
+ public Object basicEvaluate(final Query query, final EObject context,
+ final List<ParameterValue> parameterValues) throws QueryException {
+
+ IParameterValueList plist = IParameterValueListFactory.INSTANCE
+ .createParameterValueList();
+
+ if (parameterValues != null) {
+ plist.addAll(parameterValues);
+ }
+ return this.javaQuery.evaluate(context, plist);
+
+ }
+
+ public boolean getCheckResultType() {
+ return this.checkResultType;
+ }
+
+ public void setCheckResultType(final boolean checkResultType) {
+ this.checkResultType = checkResultType;
+ }
+
+ public void startEvaluate() {
+ // Nothing to do
+ }
+
+ public void endEvaluate() {
+ // Nothing to do
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluatorFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluatorFactory.java
new file mode 100644
index 00000000000..1ab14defb22
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryEvaluatorFactory.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 334615 - Java Query for EMF Facet
+ */
+package org.eclipse.emf.facet.query.java.core.internal.evaluator;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.efacet.Query;
+import org.eclipse.emf.facet.efacet.core.exception.QueryException;
+import org.eclipse.emf.facet.efacet.core.exception.QueryExecutionException;
+import org.eclipse.emf.facet.efacet.core.query.IQueryEvaluator;
+import org.eclipse.emf.facet.efacet.core.query.IQueryEvaluatorFactory;
+import org.eclipse.emf.facet.query.java.core.IJavaQuery;
+import org.eclipse.emf.facet.query.java.core.internal.plugin.Activator;
+import org.eclipse.emf.facet.query.java.javaquery.JavaQuery;
+import org.eclipse.emf.facet.query.java.javaquery.JavaqueryPackage;
+import org.eclipse.emf.facet.util.core.Logger;
+import org.osgi.framework.Bundle;
+
+
+@Deprecated
+public class JavaQueryEvaluatorFactory implements IQueryEvaluatorFactory {
+ public IQueryEvaluator create(final Query query, final Bundle bundle)
+ throws QueryException {
+ if (!(query instanceof JavaQuery)) {
+ throw new QueryException("Wrong kind of Query: " //$NON-NLS-1$
+ + query.getClass().getSimpleName() + " found, " //$NON-NLS-1$
+ + JavaQuery.class.getSimpleName() + " expected."); //$NON-NLS-1$
+ }
+ if (bundle == null) {
+ throw new QueryException("Query: " //$NON-NLS-1$
+ + query.getClass().getSimpleName()
+ + " should be create with a bundle."); //$NON-NLS-1$
+ }
+ JavaQueryEvaluator javaQueryEvaluator = null;
+ try {
+ JavaQuery javaQuery = (JavaQuery) query;
+ String className = javaQuery.getImplementationClassName();
+ if (className == null || className.length() == 0) {
+ throw new QueryExecutionException(
+ "implementationClassName is empty"); //$NON-NLS-1$
+ }
+ Class<?> javaQueryClass = bundle.loadClass(className);
+ if (!IJavaQuery.class.isAssignableFrom(javaQueryClass)) {
+ throw new Exception(className + " does not implement " //$NON-NLS-1$
+ + IJavaQuery.class.getSimpleName() + "."); //$NON-NLS-1$
+ }
+ javaQueryEvaluator = createJavaQueryImpl(javaQuery,
+ javaQueryClass);
+ // Initially a null test was perform on bundle to determine whether
+ // to check the result type. Now we need a bundle so
+ // checkResultType=true
+ javaQueryEvaluator.setCheckResultType(true);
+ } catch (Exception e) {
+ QueryException queryException = new QueryException(
+ "Failed to load the java query:" //$NON-NLS-1$
+ + query.getName(), e);
+ Logger.logError(queryException, Activator.getDefault());
+ throw queryException;
+ }
+ return javaQueryEvaluator;
+ }
+
+ /** This methods is dedicated to isolate the "Unchecked cast" warning. */
+ @SuppressWarnings("unchecked")
+ private static JavaQueryEvaluator createJavaQueryImpl(
+ final JavaQuery javaQuery, final Class<?> javaQueryClass)
+ throws InstantiationException, IllegalAccessException {
+ IJavaQuery<EObject, ?> javaQueryInst;
+ javaQueryInst = (IJavaQuery<EObject, ?>) javaQueryClass
+ .newInstance();
+ JavaQueryEvaluator javaQueryEvaluator = new JavaQueryEvaluator(javaQuery,
+ javaQueryInst);
+ return javaQueryEvaluator;
+ }
+
+ public EClass getManagedQueryType() {
+ return JavaqueryPackage.eINSTANCE.getJavaQuery();
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementation.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementation.java
new file mode 100644
index 00000000000..3b5c2855bc4
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementation.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2009 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Gregoire Dupe (Mia-Software) - initial API and implementation
+ * Emmanuelle Rouillé (Mia-Software) - Bug 352618 - To be able to use non derived facet structural features and save them values.
+ * Nicolas Bros (Mia-Software) - Bug 361612 - New core for new version of the Facet metamodel
+ * Nicolas Bros (Mia-Software) - Bug 362191 - [Restructuring] Query mechanism for eFacet2
+ * Nicolas Bros (Mia-Software) - Bug 376941 - [EFacet] Facet operation arguments in Facet model
+ */
+package org.eclipse.emf.facet.query.java.core.internal.evaluator;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.efacet.core.IFacetManager;
+import org.eclipse.emf.facet.efacet.core.exception.DerivedTypedElementException;
+import org.eclipse.emf.facet.efacet.core.query.IQueryImplementation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+import org.eclipse.emf.facet.query.java.core.IJavaQuery2;
+import org.eclipse.emf.facet.query.java.core.IParameterValueList2;
+import org.eclipse.emf.facet.query.java.core.IParameterValueListFactory2;
+
+public class JavaQueryImplementation implements IQueryImplementation {
+
+ // This class is a modified copy of :
+ // org.eclipse.emf.facet.infra.query.core.java.internal.JavaModelQueryAdapter
+
+ private final IJavaQuery2<EObject, ?> javaQuery;
+ private boolean checkResultType = false;
+
+ /**
+ * @param query
+ * @param javaQuery
+ * the javaQuery to be evaluated
+ */
+ public JavaQueryImplementation(final IJavaQuery2<EObject, ?> javaQuery) {
+ this.javaQuery = javaQuery;
+ }
+
+ public Object getValue(final Query query, final DerivedTypedElement feature, final EObject source, final List<ParameterValue> parameterValues, final IFacetManager facetManager)
+ throws DerivedTypedElementException {
+ final IParameterValueList2 plist = IParameterValueListFactory2.INSTANCE
+ .createParameterValueList();
+
+ if (parameterValues != null) {
+ plist.addAll(parameterValues);
+ }
+ return this.javaQuery.evaluate(source, plist, facetManager);
+ }
+
+ public void setValue(final Query query, final DerivedTypedElement feature, final EObject source, final List<ParameterValue> parameterValues, final Object newValue)
+ throws DerivedTypedElementException {
+ throw new UnsupportedOperationException("not implemented yet"); //$NON-NLS-1$
+ }
+
+ public boolean isCheckResultType() {
+ return this.checkResultType;
+ }
+
+ public void setCheckResultType(final boolean checkResultType) {
+ this.checkResultType = checkResultType;
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementationFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementationFactory.java
new file mode 100644
index 00000000000..c2d7418148d
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/evaluator/JavaQueryImplementationFactory.java
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 334615 - Java Query for EMF Facet
+ * Emmanuelle Rouillé (Mia-Software) - Bug 352618 - To be able to use non derived facet structural features and save them values.
+ * Nicolas Bros (Mia-Software) - Bug 361612 - New core for new version of the Facet metamodel
+ * Nicolas Bros (Mia-Software) - Bug 362191 - [Restructuring] Query mechanism for eFacet2
+ * Nicolas Bros (Mia-Software) - Bug 376941 - [EFacet] Facet operation arguments in Facet model
+ */
+package org.eclipse.emf.facet.query.java.core.internal.evaluator;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.efacet.core.IDerivedTypedElementManager;
+import org.eclipse.emf.facet.efacet.core.exception.DerivedTypedElementException;
+import org.eclipse.emf.facet.efacet.core.internal.query.QueryUtils;
+import org.eclipse.emf.facet.efacet.core.query.IQueryImplementation;
+import org.eclipse.emf.facet.efacet.core.query.IQueryImplementationFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+import org.eclipse.emf.facet.query.java.core.IJavaQuery2;
+import org.eclipse.emf.facet.query.java.core.internal.plugin.Activator;
+import org.eclipse.emf.facet.query.java.metamodel.v0_2_0.javaquery.JavaQuery;
+import org.eclipse.emf.facet.query.java.metamodel.v0_2_0.javaquery.JavaQueryPackage;
+import org.eclipse.emf.facet.util.core.Logger;
+import org.osgi.framework.Bundle;
+
+public class JavaQueryImplementationFactory implements IQueryImplementationFactory {
+
+ public IQueryImplementation create(final Query query, final Bundle bundle, final IDerivedTypedElementManager manager) throws DerivedTypedElementException {
+ if (!(query instanceof JavaQuery)) {
+ throw new IllegalArgumentException("The given DerivedTypedElement does not have a JavaQuery"); //$NON-NLS-1$
+ }
+ JavaQuery javaQuery = (JavaQuery) query;
+
+ if (bundle == null) {
+ throw new DerivedTypedElementException("Java query implementation class '" //$NON-NLS-1$
+ + javaQuery.getClass().getName()
+ + "' should be created within a bundle."); //$NON-NLS-1$
+ }
+ JavaQueryImplementation javaQueryEvaluator = null;
+ try {
+ String className = javaQuery.getImplementationClassName();
+ if (className == null || className.length() == 0) {
+ throw new DerivedTypedElementException("The Java query's implementationClassName must not be empty"); //$NON-NLS-1$
+ }
+ Class<?> javaQueryClass = bundle.loadClass(className);
+ if (!IJavaQuery2.class.isAssignableFrom(javaQueryClass)) {
+ throw new Exception("Java query implementation class '" + className + "' does not implement " //$NON-NLS-1$ //$NON-NLS-2$
+ + IJavaQuery2.class.getSimpleName() + "."); //$NON-NLS-1$
+ }
+ javaQueryEvaluator = createJavaQueryImpl(javaQueryClass);
+ // Initially a null test was performed on bundle to determine whether
+ // to check the result type. Now we need a bundle so
+ // checkResultType=true
+ javaQueryEvaluator.setCheckResultType(true);
+ } catch (Exception e) {
+ DerivedTypedElementException queryException = new DerivedTypedElementException(
+ "The bundle " + bundle.getSymbolicName() + " failed to load the java query: " //$NON-NLS-1$ //$NON-NLS-2$
+ + QueryUtils.getQueryDescription(javaQuery), e);
+ Logger.logError(queryException, Activator.getDefault());
+ throw queryException;
+ }
+ return javaQueryEvaluator;
+ }
+
+ /** This method is dedicated to isolate the "Unchecked cast" warning. */
+ @SuppressWarnings("unchecked")
+ private static JavaQueryImplementation createJavaQueryImpl(final Class<?> javaQueryClass)
+ throws InstantiationException, IllegalAccessException {
+ IJavaQuery2<EObject, ?> javaQueryInst;
+ javaQueryInst = (IJavaQuery2<EObject, ?>) javaQueryClass.newInstance();
+ JavaQueryImplementation javaQueryEvaluator = new JavaQueryImplementation(javaQueryInst);
+ return javaQueryEvaluator;
+ }
+
+ public EClass getManagedQueryType() {
+ return JavaQueryPackage.eINSTANCE.getJavaQuery();
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ClassAlreadyExistsException.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ClassAlreadyExistsException.java
new file mode 100644
index 00000000000..64fadf98d70
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ClassAlreadyExistsException.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 349569 - Need new exceptions for java query class creation
+ *******************************************************************************/
+package org.eclipse.emf.facet.query.java.core.internal.exceptions;
+
+/**
+ * This exception is raised whenever the class being created already exists.
+ * @since 0.2
+ */
+public class ClassAlreadyExistsException extends Exception {
+
+ private static final long serialVersionUID = -7352916272441579074L;
+
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ResourceURIExpectedException.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ResourceURIExpectedException.java
new file mode 100644
index 00000000000..7a539f19f04
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/exceptions/ResourceURIExpectedException.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 349569 - Need new exceptions for java query class creation
+ *******************************************************************************/
+package org.eclipse.emf.facet.query.java.core.internal.exceptions;
+
+/**
+ * This exception is raised whenever an URI is not a resource URI as expected
+ * @since 0.2
+ */
+public class ResourceURIExpectedException extends Exception {
+
+ private static final long serialVersionUID = 6891585699949077305L;
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/plugin/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/plugin/Activator.java
new file mode 100644
index 00000000000..25c2cd78401
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.core/src/org/eclipse/emf/facet/query/java/core/internal/plugin/Activator.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 334615 - Java Query for EMF Facet
+ */
+package org.eclipse.emf.facet.query.java.core.internal.plugin;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.emf.facet.query.java.core"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ super.start(context);
+ Activator.plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void stop(final BundleContext context) throws Exception {
+ Activator.plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return Activator.plugin;
+ }
+
+}

Back to the top