001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * *** 008 * 009 * Community License: GPL 3.0 010 * 011 * This file is free software: you can redistribute it and/or modify 012 * it under the terms of the GNU General Public License as published 013 * by the Free Software Foundation, either version 3 of the License, 014 * or (at your option) any later version. 015 * 016 * This file is distributed in the hope that it will be useful, but 017 * WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 019 * GNU General Public License for more details. 020 * 021 * You should have received a copy of the GNU General Public License 022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 023 * 024 * *** 025 * 026 * Available Commercial License: GraniteDS SLA 1.0 027 * 028 * This is the appropriate option if you are creating proprietary 029 * applications and you are not prepared to distribute and share the 030 * source code of your application under the GPL v3 license. 031 * 032 * Please visit http://www.granitedataservices.com/license for more 033 * details. 034 */ 035package org.granite.client.tide.server; 036 037/** 038 * Convenience classes to build Tide responders 039 * 040 * @author William DRAI 041 */ 042public class TideResponders { 043 044 private static class EmptyTideResponder<T> implements TideMergeResponder<T> { 045 046 private final T mergeWith; 047 048 public EmptyTideResponder(T mergeWith) { 049 this.mergeWith = mergeWith; 050 } 051 052 @Override 053 public final void result(TideResultEvent<T> event) { 054 // Do nothing 055 } 056 057 @Override 058 public final void fault(TideFaultEvent event) { 059 // Do nothing 060 } 061 062 @Override 063 public T getMergeResultWith() { 064 return mergeWith; 065 } 066 } 067 068 /** 069 * Create an empty responder which does not implement any operation 070 * @param <T> expected result type 071 * @return a new responder 072 */ 073 public static <T> TideResponder<T> noop() { 074 return new EmptyTideResponder<T>(null); 075 } 076 077 /** 078 * Create an empty responder which forces the merge of the result with an existing object 079 * @param mergeWith object to merge the result with 080 * @param <T> expected result type 081 * @return a new responder 082 */ 083 public static <T> TideMergeResponder<T> mergeWith(T mergeWith) { 084 return new EmptyTideResponder<T>(mergeWith); 085 } 086 087}