webloaa2listener.java

来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 70 行

JAVA
70
字号
/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

package com.sri.oaa2.agt.webloaa2;

import com.sri.oaa2.lib.*;
import com.sri.oaa2.com.*;
import com.sri.oaa2.icl.*;

import webl.lang.expr.*;
import webl.lang.*;

import java.util.Vector;

public class WebLOaa2Listener implements OAAEventListener {
  String mCallbackName;
  FunExpr mCallbackFunction;
    
  Machine mMachine;  
    
  public WebLOaa2Listener(String inCallbackName, FunExpr inCallbackFunction){
    mCallbackName = inCallbackName;   
    mCallbackFunction = inCallbackFunction;
  }
  
  public boolean doOAAEvent(IclTerm goal, IclList params, IclList answers){
    if (mCallbackFunction!=null) {
      Vector localParams = new Vector();
      if (goal!=null)
        localParams.addElement(Program.Str(goal.toString()));
      else  
        localParams.addElement(Program.Str("[]"));
      if (params!=null)
        localParams.addElement(Program.Str(params.toString()));
      else  
        localParams.addElement(Program.Str("[]"));
      if (answers!=null)
        localParams.addElement(Program.Str(answers.toString()));
      else  
        localParams.addElement(Program.Str("[]"));
      try {
        // Since WebL srcipts cannot modify incoming parameters, the
        // answer to the request is returned as the Apply's value.
        Expr localWeblAnswer = mCallbackFunction.Apply(mMachine.universe, localParams, null);                      
        IclTerm localAnswer = null;
        if (localWeblAnswer!=null)
          localAnswer = IclTerm.fromString(true, IclUtils.removeQuotes(localWeblAnswer.toString()));
        if ((localAnswer!=null) && (answers!=null))
          answers.addAll((IclList)localAnswer);
        return true;
      }catch(WebLException e) {
        OaaWebL.printError("Webl exception in WebLOAAListenener " + e.report());
      }
    }    
    return false;
  };
  
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?