package abstrasy.externals;
import abstrasy.Bivalence;
import abstrasy.Node;
import abstrasy.SELF;
import abstrasy.interpreter.InterpreterException;
import abstrasy.interpreter.ORef;
import abstrasy.interpreter.StdErrors;
/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
* http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/
public class External_Exception implements AExtClonable,AExtCachable,AExtVObject {
public static Node create(int code,String type, Node msg) throws Exception {
External_Exception except = new External_Exception();
except.err=code;
except.etype=type;
if(msg!=null){
except.emsg=msg;
}
return Node.createExternal(except);
}
public static Node create(Exception ex) throws Exception {
if(ex instanceof InterpreterException){
InterpreterException iex = (InterpreterException)ex;
return create(iex.getErrCode(),iex.getMessage(),iex.getMessageExt());
}
else{
return create(StdErrors.Unknown_error.getErr(),StdErrors.Unknown_error.getMsg(),new Node(ex.getMessage()));
}
}
int err = StdErrors.Unknown_error.getErr();
String etype = StdErrors.Unknown_error.getMsg();
Node emsg = Node.createNothing();
public External_Exception() {
}
public Node external_string(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 1);
return new Node(err+" : "+etype+ " ("+emsg+")");
}
public Node external_get_code(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 1);
return new Node(err);
}
public Node external_get_trace(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 1);
return new Node(etype);
}
public Node external_get_message(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 1);
return emsg;
}
public Node external_mutator_set_code(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 2);
SELF.require_SELF_mutable();
err = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return null;
}
public Node external_mutator_set_trace(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 2);
SELF.require_SELF_mutable();
etype = startAt.getSubNode(1, Node.TYPE_STRING).getString();
return null;
}
public Node external_mutator_set_message(Node startAt) throws Exception {
startAt.isGoodArgsLength(true, 2);
SELF.require_SELF_mutable();
emsg = startAt.getSubNode(1, Node.VTYPE_VALUABLE);
return null;
}
public Object clone_my_self(Bivalence bival) {
External_Exception t=new External_Exception();
t.emsg=this.emsg;
t.err =this.err;
t.etype=this.etype;
return t;
}
public void raise() throws Exception{
throw new InterpreterException(this.err,this.etype,this.emsg);
}
/*
* ----------------------------------------------------------------------------
*
* Optimisation par cache d'instanciantion (mars 2012) rev 1.0-6321.0
*
* ----------------------------------------------------------------------------
*/
private static ORef _optim_symbols_cache_ = new ORef();
@Override
public Object getSymbolsCache() {
return _optim_symbols_cache_.getRef();
}
@Override
public void setSymbolsCache(Object cache) {
_optim_symbols_cache_.setRef(cache);
}
}