]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/VariableRead.java
Merge "Removed extra modules OntologyModule imported to namespace" into release/1...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / VariableRead.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.db.layer0.request;
13
14 import org.simantics.db.AsyncRequestProcessor;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.layer0.variable.Variable;
18 import org.simantics.db.procedure.AsyncListener;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.db.procedure.Listener;
21 import org.simantics.db.procedure.Procedure;
22 import org.simantics.db.procedure.SyncListener;
23 import org.simantics.db.procedure.SyncProcedure;
24 import org.simantics.db.request.Read;
25 import org.simantics.db.request.ReadInterface;
26
27 public abstract class VariableRead<T> implements Read<T>, ReadInterface<T> {
28
29     final protected Variable variable;
30
31     @Override
32     public int hashCode() {
33         return variable.hashCode();
34     }
35     
36     protected Class<?> clazz() {
37         return getClass();
38     }
39
40     @Override
41     public boolean equals(Object object) {
42         if (this == object)
43             return true;
44         else if (object == null)
45             return false;
46         else if (!clazz().isInstance(object))
47             return false;
48         VariableRead<?> r = (VariableRead<?>) object;
49         return variable.equals(r.variable);
50     }
51
52     public VariableRead(Variable variable) {
53         if(variable == null) throw new IllegalArgumentException("Null variable.");
54         this.variable = variable;
55     }
56
57     @Override
58     public void request(AsyncRequestProcessor processor, AsyncProcedure<T> procedure) {
59         processor.asyncRequest(this, procedure);
60     }
61     
62     @Override
63     public void request(AsyncRequestProcessor processor, Procedure<T> procedure) {
64         processor.asyncRequest(this, procedure);
65     }
66     
67     @Override
68     public void request(AsyncRequestProcessor processor, SyncProcedure<T> procedure) {
69         processor.asyncRequest(this, procedure);
70     }
71
72     @Override
73     public void request(AsyncRequestProcessor processor, AsyncListener<T> procedure) {
74         processor.asyncRequest(this, procedure);
75     }
76     
77     @Override
78     public void request(AsyncRequestProcessor processor, Listener<T> procedure) {
79         processor.asyncRequest(this, procedure);
80     }
81     
82     @Override
83     public void request(AsyncRequestProcessor processor, SyncListener<T> procedure) {
84         processor.asyncRequest(this, procedure);
85     }
86     
87     @Override
88     public T request(RequestProcessor processor) throws DatabaseException {
89         return processor.syncRequest(this);
90     }
91     
92     @Override
93     public String toString() {
94         return getClass().getSimpleName() + "|" + variable; 
95     }
96     
97 }