01: /*
02: * Copyright 2007 Bastian Schenke Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */
10: /*
11: * Copyright 2007 Bastian Schenke Licensed under the Apache License, Version 2.0 (the "License");
12: * you may not use this file except in compliance with the License.
13: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
14: * Unless required by applicable law or agreed to in writing, software distributed under the
15: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
16: * either express or implied. See the License for the specific language governing permissions
17: * and limitations under the License.
18: */
19: package nz.org.take.r2ml;
20:
21: import nz.org.take.Variable;
22: import de.tu_cottbus.r2ml.DataVariable;
23:
24: class DataVariableHandler implements XmlTypeHandler {
25:
26: public Object importObject(Object obj) throws R2MLException {
27: DataVariable dVar = (DataVariable) obj;
28: R2MLDriver driver = R2MLDriver.get();
29: MappingContext context = MappingContext.get();
30: Variable var = context.getVariable(dVar.getName());
31: if (var != null)
32: return var;
33: try {
34: if (driver.logger.isInfoEnabled()) {
35: driver.logger.info("Create new Variable ("
36: + dVar.getName()
37: + ":"
38: + driver.getDatatypeMapper().getType(
39: dVar.getDatatypeID()) + ").");
40: }
41: } catch (RuntimeException e) {
42: // TODO Auto-generated catch block
43: e.printStackTrace();
44: }
45: var = new Variable();
46: var.setName(dVar.getName());
47: var.setType(driver.getDatatypeMapper().getType(
48: dVar.getDatatypeID()));
49: context.addVariable(var.getName(), var);
50: return var;
51: }
52:
53: }
|