解决JCO3只能在当前工作路径下获取JCoDestination的问题

经过反编译SAP的JCO3的java代码,发现:JCO3在FileDestinationsDataProvider类中强制使用当前工作路径为jcoDestination的父路径,要想任意指定路径,一个较快的解决办法就是替换掉com.sap.conn.jco.rt.FileDestinationsDataProvider.java这个类,一下是此类的加强版的java代码:

package com.sap.conn.jco.rt;

import com.sap.conn.jco.ext.*;
import com.sap.conn.jco.util.FastStringBuffer;
import java.io.*;
import java.util.Properties;

public final class FileDestinationsDataProvider implements DestinationDataProvider, ServerDataProvider {
  private static String DESTINATION_FILES_SUFFIX = ".jcoDestination";
  private static String SERVER_CFG_FILES_SUFFIX = ".jcoServer";
  private File destinationDirectory;

  FileDestinationsDataProvider(String directory) throws FileNotFoundException {
    destinationDirectory = null;
    /*
    File destinationDirFile = null;
    FastStringBuffer error = new FastStringBuffer(128);
    destinationDirFile = new File(directory);
    if (checkFile(destinationDirFile, error)) {
      destinationDirectory = destinationDirFile;
    } else {
      throw new FileNotFoundException(error.toString());
    }
    */
  }

  private boolean checkFile(File file, FastStringBuffer error) {
    if (file.exists()) {
      if (file.canRead()) {
        return true;
      }
      if (error != null) {
        error.append("File ");
        error.append(file.getAbsolutePath());
        error.append(" exists, but cannot be read. ");
      }
    } else
    if (error != null) {
      error.append("File ");
      error.append(file.getAbsolutePath());
      error.append(" does not exist. ");
    }
    return false;
  }

  public Properties getDestinationProperties(String destinationName) {
    return loadProperties(destinationName, DESTINATION_FILES_SUFFIX);
  }

  public Properties getServerProperties(String serverName) {
    return loadProperties(serverName, SERVER_CFG_FILES_SUFFIX);
  }

  private Properties loadProperties(String destinationName, String suffix) {
    File destinationFile = new File(destinationDirectory,
                                    (new StringBuilder()).append(destinationName).append(suffix).toString());
    FastStringBuffer buf = new FastStringBuffer(256);
    if (!checkFile(destinationFile, buf)) {
      throw new RuntimeException(buf.toString());
    }
    FileInputStream fis = null;
    Properties properties = new Properties();
    try {
      Properties properties1;
      try {
        properties.load(fis = new FileInputStream(destinationFile));
        properties1 = properties;
      } catch (IOException ex) {
        throw new RuntimeException("Unable to load the destination properties", ex);
      }
      return properties1;
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (Exception e) {}
      }
    }
  }

  public boolean supportsEvents() {
    return false;
  }

  public void setDestinationDataEventListener(DestinationDataEventListener destinationdataeventlistener) {
  }

  public void setServerDataEventListener(ServerDataEventListener serverdataeventlistener) {
  }

}
 



附件里有我打包好的经过修改的JCO3的类库文件!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值