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.PropertyPredicate;
17: import nz.org.take.Term;
18: import nz.org.take.r2ml.util.R2MLUtil;
19: import de.tu_cottbus.r2ml.ReferencePropertyFunctionTerm;
20:
21: public class ReferencePropertyFunctionTermHandler implements
22: XmlTypeHandler {
23:
24: public Object importObject(Object obj) throws R2MLException {
25: R2MLDriver driver = R2MLDriver.get();
26:
27: if (driver.getPropertyMode() == R2MLDriver.INFER_PROPERTIES_MODE)
28: throw new R2MLException(
29: "ReferencePropertyFunctionTerm not replaced although INFER_PROPERTIES_MODE is enabled.");
30: ReferencePropertyFunctionTerm term = (ReferencePropertyFunctionTerm) obj;
31:
32: ComplexTerm takeTerm = new ComplexTerm();
33:
34: // building objectTerm
35: XmlTypeHandler contextHandler = driver
36: .getHandlerByXmlType(term.getContextArgument()
37: .getObjectTerm().getDeclaredType());
38: Term contextArgument = (Term) contextHandler.importObject(term
39: .getContextArgument().getObjectTerm().getValue());
40: takeTerm.setTerms(new Term[] { contextArgument });
41:
42: // building method
43: PropertyDescriptor prop = R2MLUtil.buildProperty(term
44: .getReferencePropertyID().getLocalPart(),
45: contextArgument.getType());
46: JFunction jFunction = new JFunction();
47: jFunction.setMethod(prop.getReadMethod());
48:
49: takeTerm.setFunction(jFunction);
50:
51: return takeTerm;
52: }
53:
54: }
|