Skip to content

Commit d825b11

Browse files
committed
Test Model Interpreter is used to test resolving of import types
1 parent 0947924 commit d825b11

1 file changed

Lines changed: 222 additions & 0 deletions

File tree

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2011 - 2015 OpenWorm.
5+
* http://openworm.org
6+
*
7+
* All rights reserved. This program and the accompanying materials
8+
* are made available under the terms of the MIT License
9+
* which accompanies this distribution, and is available at
10+
* http://opensource.org/licenses/MIT
11+
*
12+
* Contributors:
13+
* OpenWorm - http://openworm.org/people.html
14+
*
15+
* Permission is hereby granted, free of charge, to any person obtaining a copy
16+
* of this software and associated documentation files (the "Software"), to deal
17+
* in the Software without restriction, including without limitation the rights
18+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
* copies of the Software, and to permit persons to whom the Software is
20+
* furnished to do so, subject to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be included in
23+
* all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
31+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
*******************************************************************************/
33+
package org.geppetto.datasources;
34+
35+
import java.io.File;
36+
import java.net.URL;
37+
import java.util.ArrayList;
38+
import java.util.Arrays;
39+
import java.util.List;
40+
41+
import org.geppetto.core.data.model.IAspectConfiguration;
42+
import org.geppetto.core.features.ISetParameterFeature;
43+
import org.geppetto.core.model.AModelInterpreter;
44+
import org.geppetto.core.model.GeppettoModelAccess;
45+
import org.geppetto.core.model.ModelInterpreterException;
46+
import org.geppetto.core.services.GeppettoFeature;
47+
import org.geppetto.core.services.registry.ServicesRegistry;
48+
import org.geppetto.model.GeppettoLibrary;
49+
import org.geppetto.model.ModelFormat;
50+
import org.geppetto.model.VariableValue;
51+
import org.geppetto.model.types.CompositeType;
52+
import org.geppetto.model.types.Type;
53+
import org.geppetto.model.types.TypesFactory;
54+
import org.geppetto.model.types.TypesPackage;
55+
import org.geppetto.model.util.GeppettoVisitingException;
56+
import org.geppetto.model.values.ImportValue;
57+
import org.geppetto.model.values.Pointer;
58+
import org.geppetto.model.values.Value;
59+
import org.geppetto.model.variables.Variable;
60+
import org.geppetto.model.variables.VariablesFactory;
61+
62+
/**
63+
* @author matteocantarelli
64+
*
65+
*/
66+
public class TestModelInterpreterService extends AModelInterpreter
67+
{
68+
69+
private class TestSetParameterFeature implements ISetParameterFeature
70+
{
71+
72+
@Override
73+
public GeppettoFeature getType()
74+
{
75+
return GeppettoFeature.SET_PARAMETERS_FEATURE;
76+
}
77+
78+
@Override
79+
public void setParameter(VariableValue variableValue) throws ModelInterpreterException
80+
{
81+
// TODO Auto-generated method stub
82+
83+
}
84+
85+
}
86+
87+
public TestModelInterpreterService()
88+
{
89+
super();
90+
this.addFeature(new TestSetParameterFeature());
91+
this.getName();
92+
93+
}
94+
95+
/*
96+
* (non-Javadoc)
97+
*
98+
* @see org.geppetto.core.services.IService#registerGeppettoService()
99+
*/
100+
@Override
101+
public void registerGeppettoService() throws Exception
102+
{
103+
List<ModelFormat> modelFormats = new ArrayList<ModelFormat>(Arrays.asList(ServicesRegistry.registerModelFormat("TEST_FORMAT")));
104+
ServicesRegistry.registerModelInterpreterService(this, modelFormats);
105+
106+
}
107+
108+
/*
109+
* (non-Javadoc)
110+
*
111+
* @see org.geppetto.core.services.IService#isSupported(org.geppetto.core.services.GeppettoFeature)
112+
*/
113+
@Override
114+
public boolean isSupported(GeppettoFeature feature)
115+
{
116+
switch(feature)
117+
{
118+
case SET_PARAMETERS_FEATURE:
119+
return true;
120+
default:
121+
return false;
122+
}
123+
}
124+
125+
126+
127+
128+
/*
129+
* (non-Javadoc)
130+
*
131+
* @see org.geppetto.core.model.IModelInterpreter#importType(java.net.URL, java.lang.String, org.geppetto.model.GeppettoLibrary, org.geppetto.core.model.GeppettoModelAccess)
132+
*/
133+
@Override
134+
public Type importType(URL url, String typeName, GeppettoLibrary library, GeppettoModelAccess commonLibraryAccess) throws ModelInterpreterException
135+
{
136+
CompositeType type = TypesFactory.eINSTANCE.createCompositeType();
137+
try
138+
{
139+
type.setId("testType");
140+
type.setName("testType");
141+
142+
Variable a = VariablesFactory.eINSTANCE.createVariable();
143+
a.setId("a");
144+
a.setName("a");
145+
a.getTypes().add(commonLibraryAccess.getType(TypesPackage.Literals.STATE_VARIABLE_TYPE));
146+
147+
Variable b = VariablesFactory.eINSTANCE.createVariable();
148+
b.setId("b");
149+
b.setName("b");
150+
b.getTypes().add(commonLibraryAccess.getType(TypesPackage.Literals.STATE_VARIABLE_TYPE));
151+
152+
Variable c = VariablesFactory.eINSTANCE.createVariable();
153+
c.setId("c");
154+
c.setName("c");
155+
c.getTypes().add(commonLibraryAccess.getType(TypesPackage.Literals.STATE_VARIABLE_TYPE));
156+
157+
Variable p1 = VariablesFactory.eINSTANCE.createVariable();
158+
p1.setId("p1");
159+
p1.setName("p1");
160+
p1.getTypes().add(commonLibraryAccess.getType(TypesPackage.Literals.PARAMETER_TYPE));
161+
162+
Variable p2 = VariablesFactory.eINSTANCE.createVariable();
163+
p2.setId("p2");
164+
p2.setName("p2");
165+
p2.getTypes().add(commonLibraryAccess.getType(TypesPackage.Literals.PARAMETER_TYPE));
166+
167+
type.getVariables().add(a);
168+
type.getVariables().add(b);
169+
type.getVariables().add(c);
170+
type.getVariables().add(p1);
171+
type.getVariables().add(p2);
172+
173+
library.getTypes().add(type);
174+
}
175+
catch(GeppettoVisitingException e)
176+
{
177+
throw new ModelInterpreterException(e);
178+
}
179+
return type;
180+
}
181+
182+
/*
183+
* (non-Javadoc)
184+
*
185+
* @see org.geppetto.core.model.IModelInterpreter#downloadModel(org.geppetto.model.values.Pointer, org.geppetto.model.ModelFormat, org.geppetto.core.data.model.IAspectConfiguration)
186+
*/
187+
@Override
188+
public File downloadModel(Pointer pointer, ModelFormat format, IAspectConfiguration aspectConfiguration) throws ModelInterpreterException
189+
{
190+
return new File("ModelFile");
191+
}
192+
193+
/*
194+
* (non-Javadoc)
195+
*
196+
* @see org.geppetto.core.model.IModelInterpreter#getSupportedOutputs(org.geppetto.model.values.Pointer)
197+
*/
198+
@Override
199+
public List<ModelFormat> getSupportedOutputs(Pointer pointer) throws ModelInterpreterException
200+
{
201+
List<ModelFormat> formats=new ArrayList<ModelFormat>();
202+
formats.add(ServicesRegistry.getModelFormat("TEST_FORMAT"));
203+
return formats;
204+
}
205+
206+
@Override
207+
public String getName()
208+
{
209+
return "Test Model Interpreter";
210+
}
211+
212+
@Override
213+
public Value importValue(ImportValue importValue)
214+
throws ModelInterpreterException {
215+
// TODO Auto-generated method stub
216+
return null;
217+
}
218+
219+
220+
221+
222+
}

0 commit comments

Comments
 (0)