1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.objmap.structural.annotations.factories;
\r
14 import java.lang.annotation.Annotation;
\r
15 import java.lang.reflect.Method;
\r
17 import org.apache.log4j.Logger;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.WriteGraph;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.objmap.backward.IBackwardMapping;
\r
22 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
\r
23 import org.simantics.objmap.exceptions.MappingException;
\r
24 import org.simantics.objmap.forward.IForwardMapping;
\r
25 import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
\r
27 public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
\r
29 static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
\r
32 public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g,
\r
33 Annotation annotation,
\r
34 final Method method)
\r
35 throws DatabaseException {
\r
36 method.setAccessible(true);
\r
37 return new IBidirectionalMappingRule<Domain,Range>() {
\r
40 public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
\r
41 Domain domainElement, Range rangeElement)
\r
42 throws MappingException {
\r
43 LOGGER.info(" UpdateMethodFactory.updateRange");
\r
45 return (Boolean)method.invoke(rangeElement, g, domainElement);
\r
46 } catch (Exception e) {
\r
47 // TODO Auto-generated catch block
\r
48 e.printStackTrace();
\r
54 public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain,Range> map,
\r
55 Domain domainElement, Range rangeElement)
\r
56 throws MappingException {
\r
60 public void createDomain(WriteGraph g, IBackwardMapping<Domain,Range> map, Domain domainElement, Range rangeElement) throws MappingException {
\r
61 updateDomain(g, map, domainElement, rangeElement);
\r
64 public void createRange(ReadGraph g, IForwardMapping<Domain,Range> map, Domain domainElement, Range rangeElement) throws MappingException {
\r
65 updateRange(g, map, domainElement, rangeElement);
\r