oaa2javanet.java

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

JAVA
90
字号
/* $Id: Oaa2JavaNet.java,v 1.3 2003/10/31 17:01:21 giuli Exp $*/
/**************************************************************************
 * Copyright 2001, 2002 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
 **************************************************************************/
package com.sri.oaa2.javanetbridge;

import com.sri.oaa2.lib.LibOaa;
import com.sri.oaa2.lib.OAAEventListener;
import com.sri.oaa2.icl.IclList;
import com.sri.oaa2.icl.IclTerm;

import java.io.File;
import java.util.List;
import java.util.Iterator;

/**
 *
 */
public class Oaa2JavaNet extends Oaa2JavaNet_Gen {
    final static String OAA2_LOG_CONFIG_FILE_NAME = "oaa_log_config.xml";

    public void destroy() {
        // Find any LibOaas in the object database and disconnect them.
        List objects = objDb.getObjects();
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            Object obj = iterator.next();
            if (obj instanceof LibOaa) {
                try {
                    LibOaa libOaa = (LibOaa)obj;
                    libOaa.oaaDisconnect(new IclList());
                } catch (Throwable ex) {
                    // Ignore...
                }
            }
        }
        super.destroy();
    }

    public void init() {
        super.init();
        // Check if the config file is present in the current directory. If it
        // is, then use that config file. If not, look for the config file where
        // the ActiveX dll is installed.
        File configFile = new File(OAA2_LOG_CONFIG_FILE_NAME);
        if (configFile.exists()) {
            System.setProperty("oaa.log.config.file", configFile.getAbsolutePath());
        } else {
            configFile = new File(System.getProperty("java.home") +
                    File.separator + "jre" + File.separator + "javanetbridge" +
                    File.separator + "bin" + File.separator + OAA2_LOG_CONFIG_FILE_NAME);
            if (!configFile.exists()) {
                configFile = new File(System.getProperty("java.home") +
                        File.separator + "javanetbridge" + File.separator + "bin" +
                        File.separator + OAA2_LOG_CONFIG_FILE_NAME);
            }
            if (configFile.exists()) {
                System.setProperty("oaa.log.config.file", configFile.getAbsolutePath());
            }
        }
    }

    public int LibOaa_new0(int arg0) throws com.sri.sedc.javanetbridge.ObjectNotFoundException {
        int retId = super.LibOaa_new0(arg0);
        // It is important to make sure LibOaa does not exit when an ev_halt
        // is received. Register for app_done and tell the remote bridge to exit.remoteBridge
        LibOaa oaa = (LibOaa)objDb.getObjFromId(retId);
        oaa.setExitOnEvHalt(false);
        oaa.oaaRegisterCallback("app_done", new OAAEventListener() {
            public boolean doOAAEvent(IclTerm goal, IclList params, IclList answers) {
                remoteBridge.onAppDone();
                return true;
            }
        });
        return retId;
    }
}

⌨️ 快捷键说明

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