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: package nz.org.take.r2ml;
11:
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.List;
15:
16: import javax.xml.bind.JAXBElement;
17:
18: import de.tu_cottbus.r2ml.Atom;
19: import de.tu_cottbus.r2ml.QfAndOrNafNegFormula;
20: import de.tu_cottbus.r2ml.QfDisjunction;
21:
22: import nz.org.take.Fact;
23: import nz.org.take.Prerequisite;
24: import nz.org.take.r2ml.util.R2MLUtil;
25:
26: /**
27: * Map a quantifier free disjunction from R2ML (QfDisjunction) to a list of take
28: * prerequisites (List<Prerequisite>).
29: *
30: * @param obj
31: * a QfDisjunction object
32: * @param driver
33: * the used R2MLDriver
34: * @return a list of take prerequisites
35: *
36: * @see nz.org.take.r2ml.XmlTypeHandler#importObject(java.lang.Object,
37: * nz.org.take.r2ml.R2MLDriver)
38: */
39: public class QfDisjunctionHandler implements XmlTypeHandler {
40:
41: public Object importObject(Object obj) throws R2MLException {
42:
43: QfDisjunction formula = (QfDisjunction) obj;
44: List<List<Prerequisite>> bodies = new ArrayList<List<Prerequisite>>();
45:
46: for (JAXBElement<? extends QfAndOrNafNegFormula> disjunct : formula
47: .getQfAndOrNafNegFormula()) {
48: XmlTypeHandler handler = R2MLDriver
49: .get()
50: .getHandlerByXmlType(disjunct.getValue().getClass());
51: Object object = handler.importObject(disjunct.getValue());
52: if (object instanceof List) {
53: bodies.add((List) object);
54: } else {
55: List<Prerequisite> list = new ArrayList<Prerequisite>();
56: list.add(R2MLUtil.factAsPrerequisite((Fact) object));
57: bodies.add(list);
58: }
59: } // for
60: return bodies;
61: }
62:
63: }
|