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.message;
18 * public class MyResourceSchemeHandler extends AbstractMessageSchemeHandler<MyResource> {
19 * public MyResourceSchemeHandler() {
20 * super("myresource", MyResource.class);
22 * public void doPerform(MyResource r) {
28 * @author Tuukka Lehtonen
30 public abstract class AbstractMessageSchemeHandler<T> implements IMessageSchemeHandler {
32 private String scheme;
33 private Class<?> expectedDataClass;
35 public AbstractMessageSchemeHandler(String scheme, Class<?> expectedDataClass) {
37 this.expectedDataClass = expectedDataClass;
41 public String getScheme() {
45 @SuppressWarnings("unchecked")
47 public void perform(Object o) throws MessageSchemeException {
48 if (expectedDataClass.isInstance(o)) {
55 public void handleInvalidData(Object o) {
56 // Override to handle differently
57 throw new RuntimeException("Object " + o + " is not an instance of " + expectedDataClass.getCanonicalName());
60 public abstract void doPerform(T o) throws MessageSchemeException;