X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Furi%2FURIToResource.java;h=cd5fb954d7aa43c85a03cc1d6cead40208f4be2f;hb=HEAD;hp=d8e15391219ecdd54d0f286576aaf9eb1d2b071f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/URIToResource.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/URIToResource.java index d8e153912..cd5fb954d 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/URIToResource.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/uri/URIToResource.java @@ -1,104 +1,104 @@ -/******************************************************************************* - * 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.Arrays; -import java.util.Map; - -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.Queries; -import org.simantics.db.exception.ResourceNotFoundException; -import org.simantics.db.procedure.AsyncProcedure; -import org.simantics.db.request.AsyncRead; - -/** - * TODO: should this be considered deprecated and favor {@link Queries#resource(String)} ? - */ -public class URIToResource implements AsyncRead { - String[] nameSequence; - - public URIToResource(String[] nameSequence) { - this.nameSequence = nameSequence; - } - - public URIToResource(String uri) { - this.nameSequence = URIEscape.splitURI(uri); - } - - @Override - public void perform(AsyncReadGraph g, final AsyncProcedure procedure) { - if(nameSequence.length == 0) - procedure.execute(g, g.getRootLibrary()); - else - g.asyncRequest(new URIToResource(Arrays.copyOf(nameSequence, nameSequence.length-1)), - new AsyncProcedure() { - - @Override - public void execute(AsyncReadGraph g, Resource result) { - g.asyncRequest(new EscapedChildMapOfResource(result), - new AsyncProcedure>() { - - @Override - public void execute(AsyncReadGraph g, Map map) { - Resource r = map.get(nameSequence[nameSequence.length-1]); - if(r != null) - procedure.execute(g, r); - else - procedure.exception(g, new ResourceNotFoundException( - URIEscape.joinURI(nameSequence))); - } - - @Override - public void exception(AsyncReadGraph g, Throwable t) { - procedure.exception(g, t); - } - - } - ); - } - - @Override - public void exception(AsyncReadGraph g, Throwable t) { - procedure.exception(g, t); - } - - } - ); - - } - - @Override - public int hashCode() { - return Arrays.hashCode(nameSequence); - } - - @Override - public int threadHash() { - return hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(this == obj) - return true; - if(!(obj instanceof URIToResource)) - return false; - return Arrays.equals(nameSequence, ((URIToResource)obj).nameSequence); - } - - @Override - public int getFlags() { - return 0; - } - -} +/******************************************************************************* + * 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.Arrays; +import java.util.Map; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.Queries; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; + +/** + * TODO: should this be considered deprecated and favor {@link Queries#resource(String)} ? + */ +public class URIToResource implements AsyncRead { + String[] nameSequence; + + public URIToResource(String[] nameSequence) { + this.nameSequence = nameSequence; + } + + public URIToResource(String uri) { + this.nameSequence = URIEscape.splitURI(uri); + } + + @Override + public void perform(AsyncReadGraph g, final AsyncProcedure procedure) { + if(nameSequence.length == 0) + procedure.execute(g, g.getRootLibrary()); + else + g.asyncRequest(new URIToResource(Arrays.copyOf(nameSequence, nameSequence.length-1)), + new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph g, Resource result) { + g.asyncRequest(new EscapedChildMapOfResource(result), + new AsyncProcedure>() { + + @Override + public void execute(AsyncReadGraph g, Map map) { + Resource r = map.get(nameSequence[nameSequence.length-1]); + if(r != null) + procedure.execute(g, r); + else + procedure.exception(g, new ResourceNotFoundException( + URIEscape.joinURI(nameSequence))); + } + + @Override + public void exception(AsyncReadGraph g, Throwable t) { + procedure.exception(g, t); + } + + } + ); + } + + @Override + public void exception(AsyncReadGraph g, Throwable t) { + procedure.exception(g, t); + } + + } + ); + + } + + @Override + public int hashCode() { + return Arrays.hashCode(nameSequence); + } + + @Override + public int threadHash() { + return hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(!(obj instanceof URIToResource)) + return false; + return Arrays.equals(nameSequence, ((URIToResource)obj).nameSequence); + } + + @Override + public int getFlags() { + return 0; + } + +}