]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/RangeUpdateRequest.java
Stop using pack200 because it has been deprecated and removed
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / impl / RangeUpdateRequest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management
3  * in 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.objmap.graph.impl;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.procedure.SyncListener;
17 import org.simantics.db.request.Read;
18
19 import org.simantics.objmap.exceptions.MappingException;
20 import org.simantics.objmap.forward.IForwardMapping;
21 import org.simantics.objmap.graph.impl.Link;
22
23
24 public class RangeUpdateRequest<Domain,Range> implements Read<Boolean>, SyncListener<Boolean> {
25
26     Link<Domain,Range> link;
27     /*
28      * Note that this map uses a read request that it has got from caller and 
29      * not the one that is used in updateRange. This is intentional.
30      */
31     IForwardMapping<Domain, Range> map; // map==null is used to flag that request is performed once
32     Mapping<Domain, Range> mapping; // mapping==null is used as a flag the request disposed
33     
34     public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {
35         this.link = link;
36         this.map = map;
37         this.mapping = mapping;
38     }
39
40     @Override
41     public Boolean perform(ReadGraph g) throws DatabaseException {
42         if(map != null) {
43             link.type.updateRange(g, map, link.domainElement, link.rangeElement);
44             map = null;
45             return Boolean.TRUE;
46         }
47         else if(mapping != null) {
48             mapping.domainModified(link);
49             mapping = null;
50             return Boolean.FALSE;
51         }
52         else
53             return null;
54     }
55     
56     @Override
57     public void exception(ReadGraph graph, Throwable throwable)
58             throws DatabaseException {
59         if(throwable instanceof DatabaseException)
60             throw (DatabaseException)throwable;
61         else
62             throw new MappingException(throwable);
63     }
64
65     @Override
66     public void execute(ReadGraph graph, Boolean result)
67             throws DatabaseException {       
68     }
69
70     @Override
71     public boolean isDisposed() {
72         return mapping == null || link.removed || mapping.isDisposed();
73     }
74     
75     
76     
77 }