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.structural.annotations.factories;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Method;
17 import org.apache.log4j.Logger;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.objmap.backward.IBackwardMapping;
22 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
23 import org.simantics.objmap.exceptions.MappingException;
24 import org.simantics.objmap.forward.IForwardMapping;
25 import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
27 public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
29 static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
32 public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g,
33 Annotation annotation,
35 throws DatabaseException {
36 method.setAccessible(true);
37 return new IBidirectionalMappingRule<Domain,Range>() {
40 public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
41 Domain domainElement, Range rangeElement)
42 throws MappingException {
43 LOGGER.info(" UpdateMethodFactory.updateRange");
45 return (Boolean)method.invoke(rangeElement, g, domainElement);
46 } catch (Exception e) {
47 // TODO Auto-generated catch block
54 public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain,Range> map,
55 Domain domainElement, Range rangeElement)
56 throws MappingException {
60 public void createDomain(WriteGraph g, IBackwardMapping<Domain,Range> map, Domain domainElement, Range rangeElement) throws MappingException {
61 updateDomain(g, map, domainElement, rangeElement);
64 public void createRange(ReadGraph g, IForwardMapping<Domain,Range> map, Domain domainElement, Range rangeElement) throws MappingException {
65 updateRange(g, map, domainElement, rangeElement);