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