📄 oaaproxy.java
字号:
// $CALOLSI$
/*
* #=========================================================================
* # Copyright 2004 SRI International. All rights reserved.
* #
* # The material contained in this file is confidential and proprietary to SRI
* # International and may not be reproduced, published, or disclosed to others
* # without authorization from SRI International.
* #
* # DISCLAIMER OF WARRANTIES
* #
* # SRI International MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
* # SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
* # LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* # PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SRI International SHALL NOT BE
* # LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* # OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
* #=========================================================================
* Author : evans
* Date: May 28, 2004
* Time: 12:34:22 PM
*/
package com.sri.oaa2.mapper;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import com.sri.oaa2.icl.IclList;
import com.sri.oaa2.icl.IclTerm;
import com.sri.oaa2.lib.LibOaa;
/**
* Proxy class that maps function calls to ICL solvable calls.
*/
public class OAAProxy
implements InvocationHandler
{
private OAAMapper oaaMapper;
private LibOaa oaaFacilitator;
public OAAProxy(OAAMapper oaaMapper, LibOaa oaaFacilitator)
{
this.oaaMapper = oaaMapper;
this.oaaFacilitator = oaaFacilitator;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
try
{
IclTerm solvable = oaaMapper.createSolvable(proxy.getClass(), method, args);
IclList answers = new IclList();
boolean successful = oaaFacilitator.oaaSolve(solvable, new IclList(), answers);
if(!successful) throw new MappingException("Call was unsuccessful");
if(answers.getNumChildren() > 0 && method.getReturnType() != null)
return oaaMapper.iclToJava(method.getReturnType(), answers.getTerm(0));
else return null;
}
catch(Exception e)
{
throw new ProxyMappingException("Exception when calling " + method + " " + e, e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -