public class DroolsConversionHelper {
public static void main(String args[]) throws Exception {
System.out.println(convertDrlFileToXml("/sample.drl"));
System.out.println(convertXmlToDrlFile("/sample.xml"));
}
private static String convertDrlFileToXml(String drlFileName) throws Exception {
Reader source = new InputStreamReader(
DroolsConversionHelper.class.getResourceAsStream(drlFileName));
DrlParser drlParser = new DrlParser();
PackageDescr pkgDesc = drlParser.parse(source);
XmlDumper xmlDumper = new XmlDumper();
String xml = xmlDumper.dump(pkgDesc);
return xml;
}
private static String convertXmlToDrlFile(String xmlFileName) throws Exception {
Reader source = new InputStreamReader(
DroolsConversionHelper.class.getResourceAsStream(xmlFileName));
XmlPackageReader xmlPackageReader = new XmlPackageReader();
PackageDescr pkgDesc = xmlPackageReader.read(source);
DrlDumper drlDumper = new DrlDumper();
String drl = drlDumper.dump(pkgDesc);
return drl;
}
}
Please add
ReplyDeletePackageBuilder builder = new PackageBuilder();
in
convertDrlFileToXml(String drlFileName) method. then it will work, otherwise you will get nullpointer exception
Hie,
ReplyDeleteThere is a error in the code for
private static String convertXmlToDrlFile(String xmlFileName) throws Exception {
Reader source = new InputStreamReader(
DroolsConversionHelper.class.getResourceAsStream(xmlFileName));
XmlPackageReader xmlPackageReader = new XmlPackageReader();
PackageDescr pkgDesc = xmlPackageReader.read(source);
DrlDumper drlDumper = new DrlDumper();
String drl = drlDumper.dump(pkgDesc);
return drl;
}
at line of
XmlPackageReader xmlPackageReader = new XmlPackageReader();
it needs parameter in constructor but I am not understanding what is it. So can anyone help?