]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/TypeString.java
9439ad28e75b5e6aa54fc34630a3cc7c7ffa4d46
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / TypeString.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.ResourceSet;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
22
23 public class TypeString extends BinaryRead<ResourceSet, String, String> {
24
25     final private Layer0 L0;
26     
27     public TypeString(Layer0 L0, Set<Resource> set) {
28         super((ResourceSet)set, " ");
29         this.L0 = L0;
30     }
31
32 //    public TypeString(Layer0 L0, ResourceSet set, String separator) {
33 //        super(set, separator);
34 //        if (separator == null)
35 //            throw new NullPointerException("null separator");
36 //        this.L0 = L0;
37 //    }
38
39     @Override
40     public String perform(ReadGraph graph) throws DatabaseException {
41
42         if (parameter == null || parameter.isEmpty()) return "";
43
44         StringBuilder result = new StringBuilder();
45
46         boolean first = true;
47         for(Resource r : parameter) {
48             String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
49             if(!first) result.append(parameter2);
50             else first = false;
51             result.append(name);
52         }
53         
54         return result.toString();
55         
56     }
57
58 }