]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.db/src/org/simantics/graph/db/WrapperAdvisor.java
Collect model dependencies in reversed topological order
[simantics/platform.git] / bundles / org.simantics.graph.db / src / org / simantics / graph / db / WrapperAdvisor.java
1 package org.simantics.graph.db;
2
3 import java.util.Collection;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.WriteOnlyGraph;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.graph.representation.Root;
10
11 public class WrapperAdvisor implements IImportAdvisor2 {
12
13     private final IImportAdvisor advisor;
14     
15     public WrapperAdvisor(IImportAdvisor advisor) {
16         this.advisor = advisor;
17     }
18     
19     @Override
20     public void redirect(Resource temp) {
21         if(advisor instanceof IImportAdvisor2)
22                 ((IImportAdvisor2)advisor).redirect(temp);
23     }
24     
25     @Override
26     public Resource getTarget() {
27         if(advisor instanceof IImportAdvisor2)
28                 return ((IImportAdvisor2)advisor).getTarget();
29         return null;
30     }
31     
32     @Override
33     public Collection<Resource> getRoots() {
34         if(advisor instanceof IImportAdvisor2)
35                 return ((IImportAdvisor2)advisor).getRoots();
36         return null;
37     }
38     
39     @Override
40     public Collection<RootInfo> getRootInfo() {
41         if(advisor instanceof IImportAdvisor2)
42                 return ((IImportAdvisor2)advisor).getRootInfo();
43         return null;
44     }
45     
46     @Override
47     public Resource analyzeRoot(ReadGraph graph, Root root) throws DatabaseException {
48         return advisor.analyzeRoot(graph, root);
49     }
50
51     @Override
52     public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException {
53         return advisor.createRoot(graph, root);
54     }
55
56     @Override
57     public Resource createRoot(WriteOnlyGraph graph, Root root, Resource resource) throws DatabaseException {
58         if(advisor instanceof IImportAdvisor2) {
59                 return ((IImportAdvisor2)advisor).createRoot(graph, root, resource);
60         } else {
61                 throw new UnsupportedOperationException();
62         }
63     }
64
65     @Override
66     public void beforeWrite(WriteOnlyGraph graph, TransferableGraphImporter process)
67             throws DatabaseException {
68         if(advisor instanceof IImportAdvisor2)
69                 ((IImportAdvisor2)advisor).beforeWrite(graph, process);
70     }
71
72     @Override
73     public void afterWrite(WriteOnlyGraph graph, TransferableGraphImporter process)
74             throws DatabaseException {
75         if(advisor instanceof IImportAdvisor2)
76                 ((IImportAdvisor2)advisor).afterWrite(graph, process);
77     }
78
79     @Override
80     public boolean allowImmutableModifications() {
81         if(advisor instanceof IImportAdvisor2)
82                 return ((IImportAdvisor2)advisor).allowImmutableModifications();
83         else
84                 return false;
85     }
86
87     @Override
88     public Resource createChild(WriteOnlyGraph graph, TransferableGraphImporter process, Resource parent,
89             String name) throws DatabaseException {
90         if(advisor instanceof IImportAdvisor2)
91                 return ((IImportAdvisor2)advisor).createChild(graph, process, parent, name);
92         else
93                 return process.createChild(graph, parent, null, name);
94     }
95
96     @Override
97     public Resource createChild(WriteOnlyGraph graph, TransferableGraphImporter process, Resource parent, Resource child,
98             String name) throws DatabaseException {
99         if(advisor instanceof IImportAdvisor2)
100                 return ((IImportAdvisor2)advisor).createChild(graph, process, parent, child, name);
101         else
102                 return process.createChild(graph, parent, child, name);
103     }
104
105 }