1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.subscription;
14 import java.util.List;
16 import org.simantics.databoard.util.Bean;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ResourceRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.modeling.ModelingResources;
25 * This query returns all subscriptions and their corersponding names.
27 * @author toni.kalajainen
29 public class SubscriptionsQuery extends ResourceRead<SubscriptionsQuery.SubscriptionsResult> {
31 public static class SubscriptionsResult extends Bean {
33 public List<Resource> resources;
34 public List<String> names;
36 public String[] toNames() {
37 return names.toArray( new String[names.size()] );
40 public String getName(Resource resource)
42 if (resource==null) return null;
43 for ( int i=0; i<resources.size(); i++ ) {
44 if ( resource.equals( resources.get(i) ) ) return names.get(i);
51 public SubscriptionsQuery(Resource resource) {
57 public SubscriptionsResult perform(ReadGraph graph) throws DatabaseException {
58 Layer0 L0 = Layer0.getInstance(graph);
59 ModelingResources MOD = ModelingResources.getInstance(graph);
61 SubscriptionsResult result = new SubscriptionsResult();
64 for (Resource r : graph.getObjects(resource, L0.ConsistsOf)) {
65 if ( !graph.isInstanceOf(r, MOD.Subscription) ) continue;
66 String label = graph.getPossibleRelatedValue(r, L0.HasLabel);
67 result.resources.add( r );
68 result.names.add( label == null ? "" : label );