use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.
the class ImpactModelBuilderImpl method addPackage.
@Override
public void addPackage(final PackageDescr packageDescr) {
if (compositePackagesMap == null) {
compositePackagesMap = new HashMap<>();
if (compositePackages != null) {
for (CompositePackageDescr pkg : compositePackages) {
compositePackagesMap.put(pkg.getNamespace(), pkg);
}
} else {
compositePackagesMap.put(packageDescr.getNamespace(), new CompositePackageDescr(packageDescr.getResource(), packageDescr));
}
compositePackages = null;
}
CompositePackageDescr pkgDescr = compositePackagesMap.get(packageDescr.getNamespace());
if (pkgDescr == null) {
compositePackagesMap.put(packageDescr.getNamespace(), new CompositePackageDescr(packageDescr.getResource(), packageDescr));
} else {
pkgDescr.addPackageDescr(packageDescr.getResource(), packageDescr);
}
PackageRegistry pkgRegistry = getOrCreatePackageRegistry(packageDescr);
InternalKnowledgePackage pkg = pkgRegistry.getPackage();
for (final ImportDescr importDescr : packageDescr.getImports()) {
pkgRegistry.addImport(importDescr);
}
for (GlobalDescr globalDescr : packageDescr.getGlobals()) {
try {
Class<?> globalType = pkg.getTypeResolver().resolveType(globalDescr.getType());
addGlobal(globalDescr.getIdentifier(), globalType);
pkg.addGlobal(globalDescr.getIdentifier(), globalType);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.
the class ModelBuilderImpl method addPackage.
@Override
public void addPackage(final PackageDescr packageDescr) {
if (compositePackagesMap == null) {
compositePackagesMap = new HashMap<>();
}
CompositePackageDescr pkgDescr = compositePackagesMap.get(packageDescr.getNamespace());
if (pkgDescr == null) {
compositePackagesMap.put(packageDescr.getNamespace(), new CompositePackageDescr(packageDescr.getResource(), packageDescr));
} else {
pkgDescr.addPackageDescr(packageDescr.getResource(), packageDescr);
}
PackageRegistry pkgRegistry = getOrCreatePackageRegistry(packageDescr);
InternalKnowledgePackage pkg = pkgRegistry.getPackage();
for (final ImportDescr importDescr : packageDescr.getImports()) {
pkgRegistry.addImport(importDescr);
}
for (GlobalDescr globalDescr : packageDescr.getGlobals()) {
try {
Class<?> globalType = pkg.getTypeResolver().resolveType(globalDescr.getType());
addGlobal(globalDescr.getIdentifier(), globalType);
pkg.addGlobal(globalDescr.getIdentifier(), globalType);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.
the class ModelBuilderImpl method buildDeclaredTypes.
private void buildDeclaredTypes(Collection<CompositePackageDescr> packages) {
for (CompositePackageDescr packageDescr : packages) {
PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
generatePOJOs(packageDescr, pkgRegistry);
}
List<GeneratedClassWithPackage> allGeneratedPojos = packageModels.values().stream().flatMap(p -> p.getGeneratedPOJOsSource().stream().map(c -> new GeneratedClassWithPackage(c, p.getName(), p.getImports(), p.getStaticImports()))).collect(Collectors.toList());
Map<String, Class<?>> allCompiledClasses = compileType(this, getBuilderConfiguration().getClassLoader(), allGeneratedPojos);
((CanonicalModelBuildContext) getBuildContext()).registerGeneratedPojos(allGeneratedPojos, allCompiledClasses);
}
use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.
the class CompositeKnowledgeBuilderImpl method registerPackageDescr.
private void registerPackageDescr(ResourceDescr resourceDescr, Map<String, CompositePackageDescr> packages, Resource resource, PackageDescr packageDescr) {
if (packageDescr != null) {
CompositePackageDescr compositePackageDescr = packages.get(packageDescr.getNamespace());
if (compositePackageDescr == null) {
compositePackageDescr = packageDescr instanceof CompositePackageDescr ? ((CompositePackageDescr) packageDescr) : new CompositePackageDescr(resource, packageDescr);
packages.put(packageDescr.getNamespace(), compositePackageDescr);
} else {
compositePackageDescr.addPackageDescr(resource, packageDescr);
}
compositePackageDescr.addFilter(resourceDescr.getFilter());
}
}
use of org.drools.compiler.lang.descr.CompositePackageDescr in project drools by kiegroup.
the class KnowledgeBuilderImpl method decisionTableToPackageDescr.
PackageDescr decisionTableToPackageDescr(Resource resource, ResourceConfiguration configuration) throws DroolsParserException {
DecisionTableConfiguration dtableConfiguration = configuration instanceof DecisionTableConfiguration ? (DecisionTableConfiguration) configuration : new DecisionTableConfigurationImpl();
if (!dtableConfiguration.getRuleTemplateConfigurations().isEmpty()) {
List<String> generatedDrls = DecisionTableFactory.loadFromInputStreamWithTemplates(resource, dtableConfiguration);
if (generatedDrls.size() == 1) {
return generatedDrlToPackageDescr(resource, generatedDrls.get(0));
}
CompositePackageDescr compositePackageDescr = null;
for (String generatedDrl : generatedDrls) {
PackageDescr packageDescr = generatedDrlToPackageDescr(resource, generatedDrl);
if (packageDescr != null) {
if (compositePackageDescr == null) {
compositePackageDescr = new CompositePackageDescr(resource, packageDescr);
} else {
compositePackageDescr.addPackageDescr(resource, packageDescr);
}
}
}
return compositePackageDescr;
}
dtableConfiguration.setTrimCell(this.configuration.isTrimCellsInDTable());
String generatedDrl = DecisionTableFactory.loadFromResource(resource, dtableConfiguration);
return generatedDrlToPackageDescr(resource, generatedDrl);
}
Aggregations