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