]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/SuperTypeString.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / SuperTypeString.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.request;
13
14 import java.util.Set;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.utils.Logger;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
22
23 public class SuperTypeString extends BinaryRead<Resource, String, String> {
24
25     public SuperTypeString(Resource type) {
26         super(type, " ");
27     }
28
29     public SuperTypeString(Resource type, String separator) {
30         super(type, separator);
31         if (separator == null)
32             throw new NullPointerException("null separator");
33     }
34
35     @Override
36     public String perform(ReadGraph graph) throws DatabaseException {
37         
38         Layer0 L0 = Layer0.getInstance(graph);
39         Set<Resource> supers = graph.getSupertypes(parameter);
40         final StringBuilder b = new StringBuilder();
41         String name = graph.getPossibleRelatedValue(parameter, L0.HasName, Bindings.STRING);
42         if(name != null) {
43                 b.append(TypeString.escapeToken(name));
44             for (Resource r : supers) {
45                 name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
46                 if(name != null) {
47                         b.append(parameter2);
48                         b.append(TypeString.escapeToken(name));
49                 } else {
50                         Logger.defaultLogError(new DatabaseException("No name for type " + r));
51                 }
52             }
53         } else {
54                 Logger.defaultLogError(new DatabaseException("No name for type " + parameter));
55         }
56
57         return b.toString();
58
59     }
60
61 }