📄 fsexceptionhandler.java
字号:
/*
* FSExceptionHandler.java
* Transform
*
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Flagstone Software Ltd. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.flagstone.transform;
import java.util.*;
/**
The FSExceptionHandler class is used to specify try..catch blocks so exceptions can be thrown
and handled when executing a series of actions.
<table class="datasheet">
<tr><th align="left" colspan="2">Attributes</th></tr>
<tr>
<td><a name="FSExceptionHandler_0">type</a></td>
<td>Identifies the data structure when it is encoded. Read-only.</td>
</tr>
<tr>
<td><a name="FSExceptionHandler_1">register</a></td>
<td>The number of the register that the thrown object will be assigned to. Optional, Omitted if the variable attribute is set.</td>
</tr>
<tr>
<td><a name="FSExceptionHandler_2">variable</a></td>
<td>The variable in memory that the thrown object will be assigned to. Optional, Omitted if the register attribute is set.</td>
</tr>
<tr>
<td><a name="FSExceptionHandler_3">tryActions</a></td>
<td>The actions executed in the try block of the exception.</td>
</tr>
<tr>
<td><a name="FSExceptionHandler_4">catchActions </a></td>
<td>The actions executed in the catch block of the exception. Defining actions for the catch block is optional and may be set to the null object or an empty array if no actions will be executed.</td>
</tr>
<tr>
<td><a name="FSExceptionHandler_5">finalActions</a></td>
<td>The actions executed in a finally block of the exception. Defining actions for the finally block is optional and may be set to the null object or an empty array if no actions will be executed.</td>
</tr>
</table>
<p>The thrown object can be assigned to either one of the Flash Player's 256 internal registers or to a variable in memory. If a register number is set the variable name is set to null. Similarly if a variable name is set then the register number is set to zero.</p>
<p>The FSExceptionHandler class contains three arrays of actions supporting the standard syntax for an exception with try, catch and finally blocks. An exception is thrown by a Throw action which pops a value off the stack and assigns it to either a named variable or one of the Flash Player's internal registered so it can be processed by the actions in the catch block.</p>
<p>Exceptions may be nest to any level if a thrown exception is not handled by the immediate catch block it is propagated to the next handler in the exception hierarchy and so on until it is caught.</p>
<p>Both the catch and finally blocks are optional when defining an exception, the corresponding arguments in constructors and accessor methods may be set to null.</p>
<h1 class="datasheet">History</h1>
<p>The FSExceptionHandler represents the Try action introduced in Flash 7 and is used to directly support the exception handling syntax defined in ActionScript 2.0.</p>
*/
public class FSExceptionHandler extends FSActionObject
{
private int register = 0;
private String variable = null;
private ArrayList tryActions = null;
private ArrayList catchActions = null;
private ArrayList finalActions = null;
/**
* Construct an FSExceptionHandler object, initalizing it with values
* decoded from an encoded object.
*
* @param coder an FSCoder containing the binary data.
*/
public FSExceptionHandler(FSCoder coder)
{
super(ExceptionHandler);
decode(coder);
}
/**
* Constructs a new exception handler with the thrown object assigned to a local variable.
*
* @param name the name of the variable that the thrown object will be assigned to.
* @param tryArray actions that will be executed in the try block of the exception.
* @param catchArray actions that will be executed in the catch block of the exception, if one is defined. This may be null is no catch block is required - the exception will be handled by another catche block higher in the exception tree.
* @param finallyArray actions that will be executed in the finally block of the exception, if one is defined. This may be null is no finally block is required.
*/
public FSExceptionHandler(String name, ArrayList tryArray, ArrayList catchArray, ArrayList finallyArray)
{
super(ExceptionHandler);
register = 0;
variable = name;
tryActions = tryArray;
catchActions = catchArray;
finalActions = finallyArray;
}
/**
* Constructs a new exception handler with the thrown object assigned to one of the
* Flash Player's internal registers.
*
* @param index the number of the register that the thrown object will be assigned to.
* @param tryArray actions that will be executed in the try block of the exception.
* @param catchArray actions that will be executed in the catch block of the exception, if one is defined. This may be null is no catch block is required - the exception will be handled by another catche block higher in the exception tree.
* @param finallyArray actions that will be executed in the finally block of the exception, if one is defined. This may be null is no finally block is required.
*/
public FSExceptionHandler(int index, ArrayList tryArray, ArrayList catchArray, ArrayList finallyArray)
{
super(ExceptionHandler);
register = index;
variable = null;
tryActions = tryArray;
catchActions = catchArray;
finalActions = finallyArray;
}
/**
* Constructs an FSExceptionHandler object by copying values from an
* existing object.
*
* @param obj an FSExceptionHandler object.
*/
public FSExceptionHandler(FSExceptionHandler obj)
{
super(obj);
register = obj.register;
if (obj.variable != null)
variable = new String(obj.variable);
tryActions = new ArrayList(obj.tryActions.size());
for (Iterator i = obj.tryActions.iterator(); i.hasNext();)
tryActions.add(((FSActionObject)i.next()).clone());
if (obj.catchActions != null)
{
catchActions = new ArrayList(obj.catchActions.size());
for (Iterator i = obj.catchActions.iterator(); i.hasNext();)
catchActions.add(((FSActionObject)i.next()).clone());
}
if (obj.finalActions != null)
{
finalActions = new ArrayList(obj.finalActions.size());
for (Iterator i = obj.finalActions.iterator(); i.hasNext();)
finalActions.add(((FSActionObject)i.next()).clone());
}
}
/** Adds the action object to the array of actions for the try block.
@param anAction an action.
*/
public void addToTry(FSActionObject anAction)
{
tryActions.add(anAction);
}
/** Adds the action object to the array of actions for the catch block.
@param anAction an action.
*/
public void addToCatch(FSActionObject anAction)
{
if (catchActions == null)
catchActions = new ArrayList();
catchActions.add(anAction);
}
/** Adds the action object to the array of actions for the finally block.
@param anAction an action.
*/
public void addToFinally(FSActionObject anAction)
{
if (catchActions == null)
finalActions = new ArrayList();
finalActions.add(anAction);
}
/** Gets the name of the variable which the exception object is assigned to.
@return the name of the function. Returns null if the exception object
will be assigned to a register.
*/
public String getVariable()
{
return variable;
}
/**
* Sets the name of the variable that the exception object is assigned to.
*
* @param name the name of the variable. May be null if the exception object will
* be signed to a register.
*/
public void setVariable(String name)
{
variable = name;
register = 0;
}
/**
* Gets the index of the register that the exception object is assigned to.
*
* @return the number of register. Returns 0 if the exception object will be assigned
* to a local variable.
*/
public int getRegister()
{
return register;
}
/**
* Sets the index of the register that the exception object is assigned to.
*
* @param index the number of the register. May be 0 if the exception object
* will be assigned to a local variable.
*/
public void setRegister(int index)
{
register = index;
variable = null;
}
/** Gets the array of actions executed in the try block.
@return the array of actions for the try block.
*/
public ArrayList getTryActions()
{
return tryActions;
}
/** Sets the array of actions executed in the try block.
@param array the array of actions for the try block.
*/
public void setTryActions(ArrayList array)
{
tryActions = array;
}
/** Gets the array of actions executed in the catch block.
@return the array of actions for the catch block.
*/
public ArrayList getCatchActions()
{
return catchActions;
}
/** Sets the array of actions executed in the catch block.
@param array the array of actions for the catch block.
*/
public void setCatchActions(ArrayList array)
{
catchActions = array;
}
/** Gets the array of actions executed in the finally block.
@return the array of actions for the finally block.
*/
public ArrayList getFinalActions()
{
return finalActions;
}
/** Sets the array of actions executed in the final block.
@param array the array of actions for the final block.
*/
public void setFinalActions(ArrayList array)
{
finalActions = array;
}
public Object clone()
{
FSExceptionHandler anObject = (FSExceptionHandler)super.clone();
anObject.tryActions = new ArrayList();
anObject.catchActions = new ArrayList();
anObject.finalActions = new ArrayList();
for (Iterator i = tryActions.iterator(); i.hasNext();)
anObject.tryActions.add(((FSActionObject)i.next()).clone());
for (Iterator i = catchActions.iterator(); i.hasNext();)
anObject.catchActions.add(((FSActionObject)i.next()).clone());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -