X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FDatabaseUtils.java;h=dde7c6c5cc7f42664012730aaa57f5f080a4d9cf;hb=627664d06302d454ea3b3fe14d13bb5ab739d666;hp=830e93d7f0a66d7cf9d50956c49634497132c81f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/DatabaseUtils.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/DatabaseUtils.java index 830e93d7f..dde7c6c5c 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/DatabaseUtils.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/DatabaseUtils.java @@ -1,97 +1,97 @@ -/******************************************************************************* - * 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.impl; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.Literals; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; -import org.simantics.layer0.Layer0; - -public class DatabaseUtils { - - public static String getReadableName(ReadGraph graph, Resource resource) throws ValidationException, ServiceException { - Layer0 b = Layer0.getInstance(graph); - - String uri = graph.getPossibleURI(resource); - if(uri != null) return uri; - - List names = new ArrayList(1); - for(Resource nameResource : graph.getObjects(resource, b.HasName)) { - Object value = graph.getPossibleValue(nameResource); - if(value != null) { - names.add(Literals.shortString(Literals.literalToString(value))); - } - } - if(!names.isEmpty()) { - if(names.size() == 1) - return names.get(0); - else { - StringBuilder bb = new StringBuilder(); - bb.append('['); - for(int i=0;i0) - bb.append(", "); - bb.append(names.get(i)); - } - bb.append(']'); - return bb.toString(); - } - } - StringBuilder bb = new StringBuilder(); - Object val = graph.getPossibleValue(resource); - if(val != null) { - if(val instanceof double[]) - bb.append(Literals.shortString(Arrays.toString((double[])val))); - else if(val instanceof float[]) - bb.append(Literals.shortString(Arrays.toString((float[])val))); - else if(val instanceof int[]) - bb.append(Literals.shortString(Arrays.toString((int[])val))); - else if(val instanceof boolean[]) - bb.append(Literals.shortString(Arrays.toString((boolean[])val))); - else if(val instanceof long[]) - bb.append(Literals.shortString(Arrays.toString((long[])val))); - else if(val instanceof byte[]) - bb.append(Literals.shortString(Arrays.toString((byte[])val))); - else if(val instanceof String[]) - bb.append(Literals.shortString(Arrays.toString((String[])val))); - else - bb.append(Literals.shortString(val)); - } - else - bb.append(resource.getResourceId()); - boolean ok = false; - for(Resource r : graph.getObjects(resource, b.InstanceOf)) { - bb.append(" : (" + getReadableName(graph, r) + ")"); - ok = true; - } - if(!ok) { - for(Resource r : graph.getObjects(resource, b.Inherits)) { - bb.append(" names = new ArrayList(1); + for(Resource nameResource : graph.getObjects(resource, b.HasName)) { + Object value = graph.getPossibleValue(nameResource); + if(value != null) { + names.add(Literals.shortString(Literals.literalToString(value))); + } + } + if(!names.isEmpty()) { + if(names.size() == 1) + return names.get(0); + else { + StringBuilder bb = new StringBuilder(); + bb.append('['); + for(int i=0;i0) + bb.append(", "); + bb.append(names.get(i)); + } + bb.append(']'); + return bb.toString(); + } + } + StringBuilder bb = new StringBuilder(); + Object val = graph.getPossibleValue(resource); + if(val != null) { + if(val instanceof double[]) + bb.append(Literals.shortString(Arrays.toString((double[])val))); + else if(val instanceof float[]) + bb.append(Literals.shortString(Arrays.toString((float[])val))); + else if(val instanceof int[]) + bb.append(Literals.shortString(Arrays.toString((int[])val))); + else if(val instanceof boolean[]) + bb.append(Literals.shortString(Arrays.toString((boolean[])val))); + else if(val instanceof long[]) + bb.append(Literals.shortString(Arrays.toString((long[])val))); + else if(val instanceof byte[]) + bb.append(Literals.shortString(Arrays.toString((byte[])val))); + else if(val instanceof String[]) + bb.append(Literals.shortString(Arrays.toString((String[])val))); + else + bb.append(Literals.shortString(val)); + } + else + bb.append(resource.getResourceId()); + boolean ok = false; + for(Resource r : graph.getObjects(resource, b.InstanceOf)) { + bb.append(" : (" + getReadableName(graph, r) + ")"); + ok = true; + } + if(!ok) { + for(Resource r : graph.getObjects(resource, b.Inherits)) { + bb.append("