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 nz.org.take.AbstractPredicate;
13: import nz.org.take.KnowledgeElement;
14: import de.tu_cottbus.r2ml.LogicalFormula;
15: import de.tu_cottbus.r2ml.StrongNegation;
16:
17: class StrongNegationHandler implements XmlTypeHandler {
18:
19: public Object importObject(Object obj) throws R2MLException {
20: R2MLDriver driver = R2MLDriver.get();
21: MappingContext context = MappingContext.get();
22: StrongNegation neg = (StrongNegation) obj;
23: LogicalFormula argument = neg.getLogicalFormula().getValue();
24: XmlTypeHandler handler = driver.getHandlerByXmlType(argument
25: .getClass());
26: KnowledgeElement ke = null;
27: Object toNeg = null;
28: try {
29: toNeg = handler.importObject(argument);
30: ke = (KnowledgeElement) toNeg;
31: } catch (ClassCastException e) {
32: throw new R2MLException(
33: "Only elements that are mapped to a KnowledgeElement could be negated (actual type is '"
34: + toNeg.getClass().getSimpleName() + "').");
35: }
36: if (ke.getPredicate() instanceof AbstractPredicate) {
37: ((AbstractPredicate) ke.getPredicate()).setNegated(true);
38: } else
39: throw new R2MLException(
40: "Negation of Predicates that do not extend AbstractPredicate are not supported.",
41: R2MLException.FEATURE_NOT_SUPPORTED);
42: return ke;
43: }
44: }
|