X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FUnescapedMethodMapOfResource.java;fp=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FUnescapedMethodMapOfResource.java;h=31cacdc6f7c2d94499707607fda462bc1fb7d37f;hb=277ddb17bc33a7c0b5c352f80bbc2605acaee50d;hp=0000000000000000000000000000000000000000;hpb=ea17057d1c483f8a2bcb765527e45cf4fba36df5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java new file mode 100644 index 000000000..31cacdc6f --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 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.db.layer0.request; + +import java.util.Collection; +import java.util.Map; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +import gnu.trove.map.hash.THashMap; + +public class UnescapedMethodMapOfResource extends ResourceRead> { + + public UnescapedMethodMapOfResource(Resource resource) { + super(resource); + } + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Collection predicates = graph.getPredicates(resource); + THashMap result = new THashMap(predicates.size()); + for(Resource predicate : predicates) { + if(graph.isSubrelationOf(predicate, L0.HasMethod)) { + String name = graph.getPossibleRelatedValue(predicate, L0.HasName, Bindings.STRING); + if(name != null) { + if (result.put(name, predicate) != null) + System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + predicate.getResourceId() +")."); + } + } + } + return result; + + } + +}