]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/SubscriptionItemsQuery.java
Log some information about missing property in SCLLabelRule
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / subscription / SubscriptionItemsQuery.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * 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.modeling.subscription;
13
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.UniqueRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.modeling.ModelingResources;
24
25
26 /**
27  * This query returns all subscription items for a collection of subscriptions. 
28  */
29 public class SubscriptionItemsQuery extends UniqueRead<Set<Resource>> {
30
31         Collection<Resource> resources;
32         
33     public SubscriptionItemsQuery(Collection<Resource> resources) {
34         super();
35         this.resources = resources;
36     }
37
38     @Override
39     public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
40         
41         Set<Resource> result = new HashSet<Resource>();
42         ModelingResources MOD = ModelingResources.getInstance(graph);
43         Layer0 L0 = Layer0.getInstance(graph);
44                         
45         for (Resource r : resources) {
46                 if ( graph.isInstanceOf(r, MOD.Subscription_Item)) result.add(r);
47                 else if ( graph.isInstanceOf(r, MOD.Subscription)) {
48                         for (Resource rr : graph.getObjects(r, L0.ConsistsOf)) {
49                         if ( graph.isInstanceOf(rr, MOD.Subscription_Item)) result.add(rr);                             
50                         }
51                 }
52         }
53         
54         return result;
55         
56     }
57 }