Ejemplo n.º 1
0
  public static void closeQuietly(InputSource inputSource) {
    if (inputSource == null) {
      return; // nothing to do
    }

    closeQuietly(inputSource.getCharacterStream());
    closeQuietly(inputSource.getByteStream());
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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);
    }
  }