1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.db.layer0.request;
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;
27 public abstract class VariableRead<T> implements Read<T>, ReadInterface<T> {
29 final protected Variable variable;
32 public int hashCode() {
33 return variable.hashCode();
36 protected Class<?> clazz() {
41 public boolean equals(Object object) {
44 else if (object == null)
46 else if (!clazz().isInstance(object))
48 VariableRead<?> r = (VariableRead<?>) object;
49 return variable.equals(r.variable);
52 public VariableRead(Variable variable) {
53 if(variable == null) throw new IllegalArgumentException("Null variable.");
54 this.variable = variable;
58 public void request(AsyncRequestProcessor processor, AsyncProcedure<T> procedure) {
59 processor.asyncRequest(this, procedure);
63 public void request(AsyncRequestProcessor processor, Procedure<T> procedure) {
64 processor.asyncRequest(this, procedure);
68 public void request(AsyncRequestProcessor processor, SyncProcedure<T> procedure) {
69 processor.asyncRequest(this, procedure);
73 public void request(AsyncRequestProcessor processor, AsyncListener<T> procedure) {
74 processor.asyncRequest(this, procedure);
78 public void request(AsyncRequestProcessor processor, Listener<T> procedure) {
79 processor.asyncRequest(this, procedure);
83 public void request(AsyncRequestProcessor processor, SyncListener<T> procedure) {
84 processor.asyncRequest(this, procedure);
88 public T request(RequestProcessor processor) throws DatabaseException {
89 return processor.syncRequest(this);
93 public String toString() {
94 return getClass().getSimpleName() + "|" + variable;