1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.objmap.graph;
\r
14 import java.util.Collection;
\r
15 import java.util.Set;
\r
17 import org.simantics.db.Disposable;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.WriteGraph;
\r
20 import org.simantics.objmap.bidirectional.IBidirectionalMapping;
\r
21 import org.simantics.objmap.exceptions.MappingException;
\r
24 * A mapping consists of domain (a set of resources), range (a set of Java objects) and
\r
25 * a set of links relating them. The mapping is used to propagate modifications of
\r
26 * domain elements to range and vice versa.
\r
28 * @see <a href="http://www.simantics.org/wiki/index.php/org.simantics.objmap_Manual#Concepts">Manual</a>
\r
30 * @author Hannu Niemistö
\r
32 public interface IMapping<Domain,Range> extends Disposable, IBidirectionalMapping<Domain, Range> {
\r
35 * Returns the domain of the mapping. All set operations are supported.
\r
36 * Adding a new domain element does not automatically create a link to it.
\r
37 * Removal of a domain element removes also a link and the target element,
\r
38 * but does not remove the element from the database.
\r
40 Set<Domain> getDomain();
\r
43 * Returns the range of the mapping. All set operations are supported.
\r
44 * Adding a new range element does not automatically create a link to it.
\r
45 * Removal of a range element removes also a link and the domain element,
\r
46 * but does not remove the domain element from the database.
\r
48 Set<Range> getRange();
\r
51 * Updates all domain elements whose counterpart is modified and creates new
\r
52 * domain elements for previously added range elements. Returns the
\r
53 * collection of domain elements that were modified or created in the update
\r
56 Collection<Domain> updateDomain(WriteGraph g) throws MappingException;
\r
59 * Updates all range elements whose counterpart is modified and creates new
\r
60 * range elements for previously added domain elements. Returns the
\r
61 * collection of range elements that were modified or created in the update
\r
64 Collection<Range> updateRange(ReadGraph g) throws MappingException;
\r
67 * Returns the counterpart of a domain element or null if the element does
\r
68 * not belong to the domain or does not have a link.
\r
70 Range get(Domain domainElement);
\r
73 * Returns the counterpart of a range element or null if the element does
\r
74 * not belong to the range or does not have a link.
\r
76 Domain inverseGet(Range rangeElement);
\r
79 * A convenience method that adds a domain element to the mapping and
\r
80 * immediately updates the mapping and returns the corresponding range
\r
83 Range map(ReadGraph g, Domain domainElement) throws MappingException;
\r
86 * A convenience method that adds a range element to the mapping and
\r
87 * immediately updates the mapping and returns the corresponding domain
\r
90 Domain inverseMap(WriteGraph g, Range rangeElement)
\r
91 throws MappingException;
\r
94 * Tells the mapping that the domain element has been modified.
\r
96 void domainModified(Domain domainElement);
\r
99 * Tells the mapping that the range element has been modified.
\r
101 void rangeModified(Range rangeElement);
\r
104 * Tells if some domain elements have been modified or added.
\r
106 boolean isDomainModified();
\r
109 * Tells if some range elements have been modified or added.
\r
111 boolean isRangeModified();
\r
113 Collection<Domain> getDomainModified();
\r
114 Collection<Range> getRangeModified();
\r
117 * Returns a collection of domain elements which have been modified and also
\r
118 * their counterparts in the mapping are modified. These elements are in
\r
119 * conflict in the sense that the updating domain and range in different
\r
120 * orders may produce different results.
\r
122 Collection<Domain> getConflictingDomainElements();
\r
125 * Returns a collection of range elements which have been modified and also
\r
126 * their counterparts in the mapping are modified. These elements are in
\r
127 * conflict in the sense that the updating domain and range in different
\r
128 * orders may produce different results.
\r
130 Collection<Range> getConflictingRangeElements();
\r
133 * Adds a listener for domain and range modifications.
\r
135 void addMappingListener(IMappingListener listener);
\r
138 * Removes a previously added listener.
\r
140 void removeMappingListener(IMappingListener listener);
\r