]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.db/src/org/simantics/graph/db/AbstractImportAdvisor2.java
Minor fix and optimization for exporting TG and Pgraph with sharedlib
[simantics/platform.git] / bundles / org.simantics.graph.db / src / org / simantics / graph / db / AbstractImportAdvisor2.java
1 package org.simantics.graph.db;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.db.Resource;
7 import org.simantics.graph.representation.Root;
8
9 abstract public class AbstractImportAdvisor2 implements IImportAdvisor2 {
10         
11         private Collection<RootInfo> rootInfo = new ArrayList<RootInfo>();
12
13         public Collection<Resource> getRoots() {
14                 ArrayList<Resource> result = new ArrayList<Resource>(rootInfo.size());
15                 for(RootInfo info : rootInfo) result.add(info.resource);
16                 return result;
17         }
18         
19         @Override
20         public void redirect(Resource temp) {
21         }
22         
23         @Override
24         public Collection<RootInfo> getRootInfo() {
25                 return rootInfo;
26         }
27         
28         public Resource getRoot() {
29                 if(rootInfo.size() == 1) return rootInfo.iterator().next().resource;
30                 else throw new IllegalStateException("Expected a single root, got " + rootInfo.size() + " roots.");
31         }
32         
33         protected void addRootInfo(Root root, String name, Resource resource) {
34                 rootInfo.add(new RootInfo(root, name, resource));
35         }
36
37         public Resource getRoot(String name) {
38                 for(RootInfo info : getRootInfo())
39                         if(info.name.equals(name)) return info.resource;
40                 return null;
41         }
42         
43 }