class RuleCompositionServiceImpl extends AbstractJargonService implements RuleCompositionService {

	@Override
	public Rule loadRuleFromIrods(final String absolutePathToRuleFile)
			throws FileNotFoundException, MissingOrInvalidRuleException, JargonException {

		log.info("loadRuleFromIrods()");

		if (absolutePathToRuleFile == null || absolutePathToRuleFile.isEmpty()) {
			throw new IllegalArgumentException("null or empty absolutepPathToRuleFile");
		}

		IRODSFileFactory irodsFileFactory = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount());

		IRODSFile irodsFile = irodsFileFactory.instanceIRODSFile(absolutePathToRuleFile);
		if (!irodsFile.exists()) {
			log.error("did not find rule file");
			throw new FileNotFoundException("rule file not found");
		}

		IRODSFileReader irodsFileReader = irodsFileFactory.instanceIRODSFileReader(absolutePathToRuleFile);

		StringWriter writer = null;
		String ruleString = null;

		try {
			writer = new StringWriter();
			char[] buff = new char[1024];
			int i = 0;
			while ((i = irodsFileReader.read(buff)) > -1) {
				writer.write(buff, 0, i);
			}

			ruleString = writer.toString();

			if (ruleString == null || ruleString.isEmpty()) {
				log.error("null or empty rule string");
				throw new MissingOrInvalidRuleException("no rule found");
			}

			return parseStringIntoRule(ruleString);

		} catch (IOException ioe) {
			log.error("io exception reading rule data from resource", ioe);
			throw new JargonException("error reading rule from resource", ioe);
		} finally {
			try {
				irodsFileReader.close();
				if (writer != null) {
					writer.close();
				}
			} catch (IOException e) {
				// ignore
			}

		}
	}

	public  RuleCompositionServiceImpl();
	public  RuleCompositionServiceImpl(final IRODSAccessObjectFactory irodsAccessObjectFactory,
			final IRODSAccount irodsAccount);

}