TextProtocolItem.java
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:2k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- VideoServer application
- $Id: TextProtocolItem.java,v 1.5 1999/01/14 02:41:52 andrew Exp $
- */
- package edu.sunysb.cs.ecsl.videoserver;
- import java.io.*;
- import java.util.Vector;
- import java.lang.reflect.Method;
- import java.lang.Class;
- /** Every item of this class must hold the Method to work on specific
- text protocol's command
- */
- class TextProtocolItem
- {
- private String keyword = null;
- private java.lang.reflect.Method methodToCall = null;
- VideoServerThread implementator = null;
- Class parameterTypes[] = new Class[1];
- /** keep instances of possible exceptions to compare */
- KillRequestedException kre = new KillRequestedException("");
- SyntaxException se = new SyntaxException("");
- IOException ioe = new IOException();
- /** implementator class must have a function called 'keyword' + '_impl'.
- Parameter types is fixed
- */
- public TextProtocolItem( VideoServerThread _implementator, String _keyword )
- throws SyntaxException
- {
- implementator = _implementator;
- try
- {
- parameterTypes[0] = Class.forName( "java.util.Vector" );
- }
- catch( ClassNotFoundException e )
- {
- throw new SyntaxException( "Stupid, " + e.toString() );
- }
- keyword = _keyword.toLowerCase().trim();
- String name = keyword + "_impl";
- try
- {
- methodToCall = implementator.getClass().
- getMethod( name, parameterTypes );
- }
- catch( NoSuchMethodException e )
- {
- throw new SyntaxException( "Not implemented: " + name );
- }
- }
- protected void execute( Vector args )
- throws SyntaxException, KillRequestedException, IOException,
- IllegalAccessException, NoSuchMethodException
- {
- try
- {
- Object c_args[] = new Object[1];
- c_args[0] = args;
- methodToCall.invoke( implementator, c_args );
- }
- catch( java.lang.reflect.InvocationTargetException e )
- {
- Throwable te = (Throwable) e.getTargetException();
- if( kre.getClass().isInstance( te ))
- throw (KillRequestedException) te;
- if( se.getClass().isInstance( te ))
- throw (SyntaxException) te;
- if( ioe.getClass().isInstance( te ))
- throw (IOException) te;
- // unknown
- throw new SyntaxException( te.toString() );
- }
- }
- }