use of org.kie.soup.project.datamodel.packages.HasPackageName in project drools-wb by kiegroup.
the class DRLTextEditorServiceImpl method assertPackageName.
// Check if the DRL contains a Package declaration, appending one if it does not exist
@Override
public String assertPackageName(final String drl, final Path resource) {
try {
final String existingPackageName = PackageNameParser.parsePackageName(drl);
if (!"".equals(existingPackageName)) {
return drl;
}
final Package pkg = moduleService.resolvePackage(resource);
final String requiredPackageName = (pkg == null ? null : pkg.getPackageName());
final HasPackageName mockHasPackageName = new HasPackageName() {
@Override
public String getPackageName() {
return requiredPackageName;
}
@Override
public void setPackageName(final String packageName) {
// Nothing to do here
}
};
final StringBuilder sb = new StringBuilder();
PackageNameWriter.write(sb, mockHasPackageName);
sb.append(drl);
return sb.toString();
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
Aggregations