X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.objmap2%2Fsrc%2Forg%2Fsimantics%2Fobjmap%2Fgraph%2Frules%2Fdomain%2FRelatedObjectAccessor.java;h=2cfc98185f5b3cd842255363c8a17e71f5bf3b07;hb=240fea4f9c0aa8dba1e1af496aebb4157740fa20;hp=91a164781e6c1bd0141c7cd0fc4478c13a315414;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java index 91a164781..2cfc98185 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java @@ -1,71 +1,72 @@ -/******************************************************************************* - * Copyright (c) 2007, 2013 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.objmap.graph.rules.domain; - -import org.apache.log4j.Logger; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.objmap.exceptions.MappingException; - -/** - * Accesses a resource attached to the element by given functional relation. - * @author Hannu Niemistö - */ -public class RelatedObjectAccessor implements IDomainAccessor { - - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); - - Resource relation; - - public RelatedObjectAccessor(Resource relation) { - this.relation = relation; - } - - @Override - public Resource get(ReadGraph g, Resource element) throws MappingException { - try { - LOGGER.info(" RelatedObjectAccessor.get"); - return g.getPossibleObject(element, relation); - } catch (DatabaseException e) { - throw new MappingException(e); - } - } - - @Override - public boolean set(WriteGraph g, Resource element, Resource value) - throws MappingException { - try { - LOGGER.info(" RelatedObjectAccessor.set"); - Resource resource = g.getPossibleObject(element, relation); - if(resource == null) { - if(value == null) - return false; - g.claim(element, relation, value); - return true; - } - else if(resource.equals(value)) - return false; - else { - g.deny(element, relation); - if(value != null) - g.claim(element, relation, value); - return true; - } - } catch (DatabaseException e) { - throw new MappingException(e); - } - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2013 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.graph.rules.domain; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.exceptions.MappingException; + +/** + * Accesses a resource attached to the element by given functional relation. + * @author Hannu Niemistö + */ +public class RelatedObjectAccessor implements IDomainAccessor { + + static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class); + + Resource relation; + + public RelatedObjectAccessor(Resource relation) { + this.relation = relation; + } + + @Override + public Resource get(ReadGraph g, Resource element) throws MappingException { + try { + LOGGER.info(" RelatedObjectAccessor.get"); + return g.getPossibleObject(element, relation); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(WriteGraph g, Resource element, Resource value) + throws MappingException { + try { + LOGGER.info(" RelatedObjectAccessor.set"); + Resource resource = g.getPossibleObject(element, relation); + if(resource == null) { + if(value == null) + return false; + g.claim(element, relation, value); + return true; + } + else if(resource.equals(value)) + return false; + else { + g.deny(element, relation); + if(value != null) + g.claim(element, relation, value); + return true; + } + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +}