예제 #1
0
  public static void closeQuietly(InputSource inputSource) {
    if (inputSource == null) {
      return; // nothing to do
    }

    closeQuietly(inputSource.getCharacterStream());
    closeQuietly(inputSource.getByteStream());
  }
예제 #2
0
  public static void writeToFile(String destLoc, String fileName, String contents)
      throws IOException {

    Writer fileWriter = null;
    try {
      fileWriter = getFileWriter(destLoc, fileName);
      fileWriter.write(contents);
    } finally {
      closeQuietly(fileWriter);
    }
  }
예제 #3
0
  public static void generateClientConfigXml(
      ClientConfigList clientCfgList, String destLoc, String configFileName)
      throws CodeGenFailedException {

    Writer fileWriter = null;
    try {
      fileWriter = CodeGenUtil.getFileWriter(destLoc, configFileName);

      JavaXmlBinder javaXmlBinder = JavaXmlBindingFactory.getInstance();
      javaXmlBinder.generateClientConfigXml(clientCfgList, fileWriter);

    } catch (Exception ex) {
      throw new CodeGenFailedException("Failed to generate Client Config xml file", ex);
    } finally {
      CodeGenUtil.closeQuietly(fileWriter);
    }
  }
예제 #4
0
  public static ServiceConfig parseServiceConfig(InputStream input) throws Exception {

    ServiceConfig serviceConfig = null;

    try {
      JavaXmlBinder javaXmlBinder = JavaXmlBindingFactory.getInstance();
      serviceConfig = (ServiceConfig) javaXmlBinder.unmarshal(input, ServiceConfig.class);
    } catch (Exception ex) {
      String errMsg = "Failed to parse service config xml : " + input;
      throw new Exception(errMsg, ex);
    } finally {
      CodeGenUtil.closeQuietly(
          input); // TODO: do not close here, let the calling method close its own inputstream.
    }

    return serviceConfig;
  }
예제 #5
0
  public static ClientConfigList parseClientConfig(InputStream input) throws Exception {

    ClientConfigList clientCfgList = null;

    try {
      JavaXmlBinder javaXmlBinder = JavaXmlBindingFactory.getInstance();
      clientCfgList = (ClientConfigList) javaXmlBinder.unmarshal(input, ClientConfigList.class);
    } catch (Exception ex) {
      String errMsg = "Failed to parse client config xml : " + input;
      throw new Exception(errMsg, ex);
    } finally {
      CodeGenUtil.closeQuietly(
          input); // TODO: do not close here, let the calling method close its own inputstream.
    }

    return clientCfgList;
  }
예제 #6
0
  public static void generateSecurityPolicyXml(
      ServiceSecurityConfig securityPolicyConfig, String destLoc, String configFileName)
      throws CodeGenFailedException {

    Writer fileWriter = null;
    try {
      fileWriter = CodeGenUtil.getFileWriter(destLoc, configFileName);

      JavaXmlBinder javaXmlBinder = JavaXmlBindingFactory.getInstance();
      javaXmlBinder.generateSecurityPolicyXml(securityPolicyConfig, fileWriter);

    } catch (Exception ex) {
      throw new CodeGenFailedException("Failed to generate Security Policy Config xml file", ex);
    } finally {
      CodeGenUtil.closeQuietly(fileWriter);
    }
  }