X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Furi%2FEscapedChildMapOfResource.java;h=295bcc0276f3f61bc245338a2002178015420e70;hb=HEAD;hp=1d92da9c839a1e86f2d80e12100a08555f0d2d15;hpb=901596bae43d738281c8f02b4b27348c1964be51;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/EscapedChildMapOfResource.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/EscapedChildMapOfResource.java index 1d92da9c8..295bcc027 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/EscapedChildMapOfResource.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/EscapedChildMapOfResource.java @@ -1,84 +1,84 @@ -/******************************************************************************* - * 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.common.uri; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.simantics.databoard.util.URIStringUtils; -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.ProcedureBarrier; -import org.simantics.db.common.WriteBindings; -import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter; -import org.simantics.db.common.request.PropertyMapOfResource; -import org.simantics.db.common.request.ResourceAsyncRead; -import org.simantics.db.procedure.AsyncProcedure; -import org.simantics.layer0.Layer0; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class EscapedChildMapOfResource extends ResourceAsyncRead> { - - private static final Logger LOGGER = LoggerFactory.getLogger(EscapedChildMapOfResource.class); - - public EscapedChildMapOfResource(Resource resource) { - super(resource); - } - - @Override - public void perform(AsyncReadGraph g, final AsyncProcedure> procedure) { - - final Layer0 L0 = g.getService(Layer0.class); - final ConcurrentHashMap map = new ConcurrentHashMap(); - final ProcedureBarrier> barrier = new ProcedureBarrier>(1); - - g.forEachObject(resource, L0.ConsistsOf, new AsyncMultiProcedureAdapter() { - - @Override - public void execute(AsyncReadGraph g, final Resource child) { - barrier.incrementAndGet(); - - g.forPossibleRelatedValue(child, L0.HasName, WriteBindings.STRING, new AsyncProcedure() { - - @Override - public void execute(AsyncReadGraph g, Object name) { - if (name != null) { - String escapedName = URIStringUtils.escape((String)name); - if (map.put(escapedName, child) != null) - LOGGER.error("The database contains siblings with the same name " + escapedName + " (resource=" + resource.getResourceId() +")."); - } - barrier.dec(g, procedure, map); - } - - @Override - public void exception(AsyncReadGraph graph, Throwable t) { - barrier.dec(graph, procedure, t); - } - - }); - } - - @Override - public void exception(AsyncReadGraph graph, Throwable t) { - barrier.dec(graph, procedure, t); - } - - @Override - public void finished(AsyncReadGraph g) { - barrier.dec(g, procedure, map); - } - - }); - } - -} +/******************************************************************************* + * 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.common.uri; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.simantics.databoard.util.URIStringUtils; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.ProcedureBarrier; +import org.simantics.db.common.WriteBindings; +import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter; +import org.simantics.db.common.request.PropertyMapOfResource; +import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.layer0.Layer0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class EscapedChildMapOfResource extends ResourceAsyncRead> { + + private static final Logger LOGGER = LoggerFactory.getLogger(EscapedChildMapOfResource.class); + + public EscapedChildMapOfResource(Resource resource) { + super(resource); + } + + @Override + public void perform(AsyncReadGraph g, final AsyncProcedure> procedure) { + + final Layer0 L0 = g.getService(Layer0.class); + final ConcurrentHashMap map = new ConcurrentHashMap(); + final ProcedureBarrier> barrier = new ProcedureBarrier>(1); + + g.forEachObject(resource, L0.ConsistsOf, new AsyncMultiProcedureAdapter() { + + @Override + public void execute(AsyncReadGraph g, final Resource child) { + barrier.incrementAndGet(); + + g.forPossibleRelatedValue(child, L0.HasName, WriteBindings.STRING, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph g, Object name) { + if (name != null) { + String escapedName = URIStringUtils.escape((String)name); + if (map.put(escapedName, child) != null) + LOGGER.error("The database contains siblings with the same name " + escapedName + " (resource=" + resource.getResourceId() +")."); + } + barrier.dec(g, procedure, map); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + barrier.dec(graph, procedure, t); + } + + }); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + barrier.dec(graph, procedure, t); + } + + @Override + public void finished(AsyncReadGraph g) { + barrier.dec(g, procedure, map); + } + + }); + } + +}