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.beans.PropertyDescriptor;
13:
14: import nz.org.take.ComplexTerm;
15: import nz.org.take.JFunction;
16: import nz.org.take.Term;
17: import nz.org.take.Variable;
18: import nz.org.take.r2ml.util.R2MLUtil;
19: import de.tu_cottbus.r2ml.AttributeFunctionTerm;
20:
21: /**
22: * @author schenke
23: *
24: */
25: public class AttributeFunctionTermHandler implements XmlTypeHandler {
26:
27: /**
28: * @param obj
29: * an AttributionFunctionTerm
30: * @return a ComplexTerm representing the accessor of the Property
31: * @see nz.org.take.r2ml.XmlTypeHandler#importObject(java.lang.Object)
32: */
33: public Object importObject(Object obj) throws R2MLException {
34: // AttributionFunctionTermHandler should be replaced before compiling the knowledge base
35: R2MLDriver driver = R2MLDriver.get();
36:
37: if (driver.getPropertyMode() == R2MLDriver.INFER_PROPERTIES_MODE)
38: throw new R2MLException(
39: "AttributionFunctionTerm not replaced although INFER_PROPERTIES_MODE is enabled.");
40: AttributeFunctionTerm term = (AttributeFunctionTerm) obj;
41:
42: Term takeTerm = null;
43:
44: // building objectTerm
45: Term contextArgument = null;
46: XmlTypeHandler contextHandler = driver
47: .getHandlerByXmlType(term.getContextArgument()
48: .getObjectTerm().getDeclaredType());
49: contextArgument = (Term) contextHandler.importObject(term
50: .getContextArgument().getObjectTerm().getValue());
51:
52: String localName = term.getAttributeID().getLocalPart();
53: // building method
54: PropertyDescriptor prop = R2MLUtil.buildProperty(localName,
55: contextArgument.getType());
56: if (prop == null) {
57: // takeTerm = buildRuleForDerivedAttributes(localName,
58: // contextArgument);
59: throw new R2MLException("The domain class \""
60: + contextArgument.getType().getSimpleName()
61: + "\" does not support the property \"" + localName
62: + "\".");
63: } else {
64: ComplexTerm tt = new ComplexTerm();
65: JFunction jFunction = new JFunction();
66: jFunction.setMethod(prop.getReadMethod());
67: tt.setFunction(jFunction);
68: tt.setTerms(new Term[] { contextArgument });
69:
70: takeTerm = tt;
71: }
72:
73: return takeTerm;
74: }
75:
76: // private Variable buildRuleForDerivedAttributes(String localName, Term
77: // contextArgument) throws R2MLException {
78: // Class type = R2MLDriver.get().lookUpType(localName, contextArgument);
79: // Variable var = new Variable();
80: // var.setName(localName);
81: // var.setType(type);
82: // buildRuleToResolvVariable(contextArgument);
83: // return var;
84: //
85: // }
86:
87: private void buildRuleToResolvVariable(Term contextArgument)
88: throws R2MLException {
89: // TODO Auto-generated method stub
90: throw new R2MLException("alles scheisse");
91: }
92:
93: }
|