
org.crsh.command.PipeCommand Maven / Gradle / Ivy
/*
* Copyright (C) 2012 eXo Platform SAS.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.crsh.command;
import org.crsh.io.Filter;
import org.crsh.util.TypeResolver;
import java.io.IOException;
/**
* A pipe command.
*
* @param the consumed generic type
* @param the produced generic type
*/
public abstract class PipeCommand implements Filter> {
/** . */
protected InvocationContext context;
public final boolean isPiped() {
return context.isPiped();
}
public final Class
getProducedType() {
return (Class
)TypeResolver.resolveToClass(getClass(), PipeCommand.class, 1);
}
public final Class getConsumedType() {
return (Class)TypeResolver.resolveToClass(getClass(), PipeCommand.class, 0);
}
public void open(InvocationContext consumer) {
this.context = consumer;
//
open();
}
/**
* Open pipe.
*/
public void open() throws ScriptException {
}
/**
* Extends the throw clause of the {@link org.crsh.io.Consumer#provide(Object)} method.
*
* @param element the provided element
* @throws ScriptException any script exception
* @throws IOException any io exception
*/
public void provide(C element) throws ScriptException, IOException {
}
/**
* Flush pipe.
*
* @throws ScriptException any script exception
* @throws IOException any io exception
*/
public void flush() throws ScriptException, IOException {
context.flush();
}
/**
* Close pipe.
*
* @throws ScriptException any script exception
*/
public void close() throws ScriptException {
}
}