Search in sources :

Example 1 with HasPackageName

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);
    }
}
Also used : HasPackageName(org.kie.soup.project.datamodel.packages.HasPackageName) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Aggregations

Package (org.guvnor.common.services.project.model.Package)1 HasPackageName (org.kie.soup.project.datamodel.packages.HasPackageName)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1