| /******************************************************************************* |
| * Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.buffers; |
| |
| import java.io.IOException; |
| import java.io.Writer; |
| import java.net.URISyntaxException; |
| |
| import org.eclipse.viatra2.core.IModelSpace; |
| import org.eclipse.viatra2.errors.VPMRuntimeException; |
| import org.eclipse.viatra2.natives.ASMNativeFunction; |
| import org.eclipse.viatra2.natives.NativeFunctionParameter; |
| import org.eclipse.viatra2.natives.VIATRANativeFunction; |
| |
| @VIATRANativeFunction(name = "flushBuffer", remark = "Flushes an output buffer.", |
| returns = { NativeFunctionParameter.ParameterType.BOOLEAN }, |
| params = { @NativeFunctionParameter( |
| description = "Uniquely identifies an output buffer.", |
| name = "bufferURI", |
| type = { NativeFunctionParameter.ParameterType.STRING }) }) |
| public class FlushBuffer implements ASMNativeFunction { |
| |
| public Object evaluate(IModelSpace msp, Object[] params) |
| throws VPMRuntimeException { |
| try { |
| Writer w = BufferStore.getBuffer(msp, params[0].toString()); |
| w.flush(); |
| return Boolean.TRUE; |
| } catch (URISyntaxException e) { |
| throw new VPMRuntimeException("Invalid URI syntax", e); |
| } catch (IOException e) { |
| throw new VPMRuntimeException("Error while flushing buffer", e); |
| } |
| } |
| |
| public String getDescription() { |
| return "Flushes an output buffer"; |
| } |
| |
| public String getID() { |
| return this.getClass().getCanonicalName(); |
| } |
| |
| public String getName() { |
| return "flushBuffer"; // VTCL
|
| } |
| |
| } |