1 | package de.uka.ipd.sdq.pcm.transformations; |
2 | |
3 | import java.util.Set; |
4 | |
5 | import org.eclipse.emf.ecore.EClass; |
6 | import org.eclipse.emf.ecore.EClassifier; |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.query.ocl.conditions.BooleanOCLCondition; |
9 | import org.eclipse.emf.query.statements.FROM; |
10 | import org.eclipse.emf.query.statements.SELECT; |
11 | import org.eclipse.emf.query.statements.WHERE; |
12 | import org.eclipse.ocl.OCL; |
13 | |
14 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
15 | |
16 | public abstract class AllInstancesTransformer<T> { |
17 | |
18 | private EObject rootNode; |
19 | private EClassifier eClass; |
20 | |
21 | public AllInstancesTransformer(EClassifier eClass, EObject rootNode) { |
22 | super(); |
23 | this.rootNode = rootNode; |
24 | this.eClass = eClass; |
25 | } |
26 | |
27 | @SuppressWarnings("unchecked") |
28 | public void transform() throws JobFailedException { |
29 | OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance(); |
30 | |
31 | try { |
32 | Set<EObject> result = (Set<EObject>) new SELECT( |
33 | new FROM(rootNode), |
34 | new WHERE(new BooleanOCLCondition<EClassifier, EClass, EObject>( |
35 | ocl.getEnvironment(), |
36 | "true", |
37 | eClass))).getEObjects(); |
38 | for(EObject eObject : result) { |
39 | transform((T)eObject); |
40 | } |
41 | } catch (Exception ex) { |
42 | throw new JobFailedException("Transformation failed",ex); |
43 | } |
44 | } |
45 | |
46 | protected abstract void transform(T object); |
47 | } |