Package org.drools.core.definitions

Examples of org.drools.core.definitions.InternalKnowledgePackage


    protected TripleFactory getTripleFactory() {
        return getComponentFactory().getTripleFactory();
    }

    protected ClassFieldAccessorStore getClassFieldAccessorStore() {
        InternalKnowledgePackage traitPackage = kBase.getPackagesMap().get( pack );
        if ( traitPackage == null ) {
            traitPackage = new KnowledgePackageImpl( pack );
            traitPackage.setClassFieldAccessorCache( kBase.getClassFieldAccessorCache() );
            kBase.getPackagesMap().put( pack, traitPackage );
        }
        ClassFieldAccessorStore store = traitPackage.getClassFieldAccessorStore();
        return store;
    }
View Full Code Here


        return getPackage(packageName);
    }

    public Rule getRule(String packageName,
                        String ruleName) {
        InternalKnowledgePackage p = getPackage(packageName);
        return p == null ? null : p.getRule( ruleName );
    }
View Full Code Here

                if ( newPkg.hasTraitRegistry() ) {
                    getTraitRegistry().merge( newPkg.getTraitRegistry() );
                }

                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );
                if ( pkg == null ) {
                    pkg = new KnowledgePackageImpl( newPkg.getName() );

                    // @TODO we really should have a single root cache
                    pkg.setClassFieldAccessorCache( this.classFieldAccessorCache );
                    pkgs.put( pkg.getName(),
                              pkg );
                }

                // first merge anything related to classloader re-wiring
                pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry(),
                                                       this.rootClassLoader,
                                                       true );

            }

            List<TypeDeclaration> allTypeDeclarations = new ArrayList<TypeDeclaration>();
            // Add all Type Declarations, this has to be done first incase packages cross reference each other during build process.
            for ( InternalKnowledgePackage newPkg : clonedPkgs ) {
                // we have to do this before the merging, as it does some classloader resolving
                if ( newPkg.getTypeDeclarations() != null ) {
                    for ( TypeDeclaration newDecl : newPkg.getTypeDeclarations().values() ) {
                        allTypeDeclarations.add( newDecl );
                    }
                }
            }
            Collections.sort( allTypeDeclarations );

            String lastType = null;
            try {
                // add type declarations according to the global order
                for ( TypeDeclaration newDecl : allTypeDeclarations ) {
                    lastType = newDecl.getTypeClassName();
                    InternalKnowledgePackage newPkg = null;
                    for ( InternalKnowledgePackage kpkg : clonedPkgs ) {
                        if ( kpkg.getTypeDeclarations().containsKey( newDecl.getTypeName() ) ) {
                            newPkg = kpkg;
                            break;
                        }
                    }
                    processTypeDeclaration( newDecl, newPkg );
                }

            } catch (ClassNotFoundException e) {
                throw new RuntimeException( "unable to resolve Type Declaration class '" + lastType + "'", e );
            }

            for ( InternalKnowledgePackage newPkg : clonedPkgs ) {
                // Add functions
                try {
                    JavaDialectRuntimeData runtime = ((JavaDialectRuntimeData) newPkg.getDialectRuntimeRegistry().getDialectData( "java" ));

                    for ( Function function : newPkg.getFunctions().values() ) {
                        String functionClassName = function.getClassName();
                        byte [] def = runtime.getStore().get(convertClassToResourcePath(functionClassName));
                        registerAndLoadTypeDefinition( functionClassName, def );
                    }
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException( "unable to resolve Type Declaration class '" + lastType + "'", e );
                }
            }

            // now iterate again, this time onBeforeExecute will handle any wiring or cloader re-creating that needs to be done as part of the merge
            for (InternalKnowledgePackage newPkg : clonedPkgs) {
                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );

                // this needs to go here, as functions will set a java dialect to dirty
                if (newPkg.getFunctions() != null) {
                    for (Map.Entry<String, Function> entry : newPkg.getFunctions().entrySet()) {
                        pkg.addFunction( entry.getValue() );
                    }
                }

                pkg.getDialectRuntimeRegistry().onBeforeExecute();

                // with the classloader recreated for all byte[] classes, we should now merge and wire any new accessors
                pkg.getClassFieldAccessorStore().merge( newPkg.getClassFieldAccessorStore() );
            }


            for (InternalKnowledgePackage newPkg : clonedPkgs) {
                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );

                // now merge the new package into the existing one
                mergePackage( pkg,
                              newPkg );
View Full Code Here

    public void removeRule( final String packageName,
                            final String ruleName ) {
        lock();
        try {
            final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
            if (pkg == null) {
                throw new IllegalArgumentException( "Package name '" + packageName +
                                                    "' does not exist for this Rule Base." );
            }

            RuleImpl rule = pkg.getRule( ruleName );
            if (rule == null) {
                throw new IllegalArgumentException( "Rule name '" + ruleName +
                                                    "' does not exist in the Package '" +
                                                    packageName +
                                                    "'." );
            }

            this.removalsSinceLock++;

            removeRule( pkg,
                        rule );
            pkg.removeRule( rule );
            addReloadDialectDatas( pkg.getDialectRuntimeRegistry() );
        } finally {
            unlock();
        }
    }
View Full Code Here

    public void removeFunction( final String packageName,
                                final String functionName ) {
        lock();
        try {
            final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
            if (pkg == null) {
                throw new IllegalArgumentException( "Package name '" + packageName +
                                                    "' does not exist for this Rule Base." );
            }

            Function function = pkg.getFunctions().get(functionName);
            if (function == null) {
                throw new IllegalArgumentException( "function name '" + packageName +
                                                    "' does not exist in the Package '" +
                                                    packageName +
                                                    "'." );
            }

            removeFunction( pkg,
                            functionName );
            pkg.removeFunction( functionName );
            if (rootClassLoader instanceof ProjectClassLoader) {
                ((ProjectClassLoader)rootClassLoader).undefineClass(function.getClassName());
            }

            addReloadDialectDatas( pkg.getDialectRuntimeRegistry() );
        } finally {
            unlock();
        }
    }
View Full Code Here

    }

    public void removeKnowledgePackage(String packageName) {
        lock();
        try {
            final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
            if (pkg == null) {
                throw new IllegalArgumentException( "Package name '" + packageName +
                                                    "' does not exist for this Rule Base." );
            }
            this.removalsSinceLock++;

            this.eventSupport.fireBeforePackageRemoved( pkg );

            for (Rule rule : pkg.getRules()) {
                removeRule( pkg, (RuleImpl)rule );
            }

            // getting the list of referenced globals
            final Set<String> referencedGlobals = new HashSet<String>();
            for (InternalKnowledgePackage pkgref : this.pkgs.values()) {
                if (pkgref != pkg) {
                    referencedGlobals.addAll( pkgref.getGlobals().keySet() );
                }
            }
            // removing globals declared inside the package that are not shared
            for (String globalName : pkg.getGlobals().keySet()) {
                if (!referencedGlobals.contains( globalName )) {
                    this.globals.remove( globalName );
                }
            }
            //and now the rule flows
            for ( String processName : new ArrayList<String>(pkg.getRuleFlows().keySet()) ) {
                removeProcess( processName );
            }
            // removing the package itself from the list
            this.pkgs.remove( pkg.getName() );

            pkg.getDialectRuntimeRegistry().onRemove();

            //clear all members of the pkg
            pkg.clear();

            this.eventSupport.fireAfterPackageRemoved( pkg );
        } finally {
            unlock();
        }
View Full Code Here

        return getPackage(packageName);
    }

    public Rule getRule(String packageName,
                        String ruleName) {
        InternalKnowledgePackage p = getPackage(packageName);
        return p == null ? null : p.getRule( ruleName );
    }
View Full Code Here

                if ( newPkg.hasTraitRegistry() ) {
                    getTraitRegistry().merge( newPkg.getTraitRegistry() );
                }

                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );
                if ( pkg == null ) {
                    pkg = new KnowledgePackageImpl( newPkg.getName() );

                    // @TODO we really should have a single root cache
                    pkg.setClassFieldAccessorCache( this.classFieldAccessorCache );
                    pkgs.put( pkg.getName(),
                              pkg );
                }

                // first merge anything related to classloader re-wiring
                pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry(),
                                                       this.rootClassLoader,
                                                       true );

            }


            // Add all Type Declarations, this has to be done first incase packages cross reference each other during build process.
            for ( InternalKnowledgePackage newPkg : clonedPkgs ) {
                // we have to do this before the merging, as it does some classloader resolving
                String lastType = null;
                try {
                    // Add the type declarations to the RuleBase
                    if ( newPkg.getTypeDeclarations() != null ) {
                        JavaDialectRuntimeData runtime = ((JavaDialectRuntimeData) newPkg.getDialectRuntimeRegistry().getDialectData( "java" ));

                        // add type declarations
                        for ( TypeDeclaration newDecl : newPkg.getTypeDeclarations().values() ) {
                            lastType = newDecl.getTypeClassName();


                            TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( newDecl.getTypeClassName() );
                            if ( typeDeclaration == null ) {
                                String className = newDecl.getTypeClassName();

                                byte [] def = runtime.getClassDefinition(convertClassToResourcePath(className));
                                Class<?> definedKlass = registerAndLoadTypeDefinition( className, def );

                                if ( definedKlass == null && typeDeclaration.isNovel() ) {
                                    throw new RuntimeException( "Registering null bytes for class " + className );
                                }

                                if (newDecl.getTypeClassDef() == null) {
                                    newDecl.setTypeClassDef( new ClassDefinition() );
                                }
                                newDecl.getTypeClassDef().setDefinedClass( definedKlass );
                                newDecl.setTypeClass( definedKlass );

                                this.classTypeDeclaration.put( className, newDecl );
                                typeDeclaration = newDecl;
                            } else {
                                Class<?> definedKlass = typeDeclaration.getTypeClass();

                                newDecl.getTypeClassDef().setDefinedClass( definedKlass );
                                newDecl.setTypeClass( definedKlass );

                                mergeTypeDeclarations( typeDeclaration,
                                                       newDecl );
                            }

                            // update existing OTNs
                            updateDependentTypes( newPkg,
                                                  typeDeclaration );
                        }

                        for ( Function function : newPkg.getFunctions().values() ) {
                            String functionClassName = function.getClassName();
                            byte [] def = runtime.getStore().get(convertClassToResourcePath(functionClassName));
                            registerAndLoadTypeDefinition( functionClassName, def );
                        }
                    }
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException( "unable to resolve Type Declaration class '" + lastType + "'", e );
                }
            }

            // now iterate again, this time onBeforeExecute will handle any wiring or cloader re-creating that needs to be done as part of the merge
            for (InternalKnowledgePackage newPkg : clonedPkgs) {
                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );

                // this needs to go here, as functions will set a java dialect to dirty
                if (newPkg.getFunctions() != null) {
                    for (Map.Entry<String, Function> entry : newPkg.getFunctions().entrySet()) {
                        pkg.addFunction( entry.getValue() );
                    }
                }

                pkg.getDialectRuntimeRegistry().onBeforeExecute();

                // with the classloader recreated for all byte[] classes, we should now merge and wire any new accessors
                pkg.getClassFieldAccessorStore().merge( newPkg.getClassFieldAccessorStore() );
            }


            for (InternalKnowledgePackage newPkg : clonedPkgs) {
                InternalKnowledgePackage pkg = this.pkgs.get( newPkg.getName() );

                // now merge the new package into the existing one
                mergePackage( pkg,
                              newPkg );
View Full Code Here

    public void removeRule( final String packageName,
                            final String ruleName ) {
        lock();
        try {
            final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
            if (pkg == null) {
                throw new IllegalArgumentException( "Package name '" + packageName +
                                                    "' does not exist for this Rule Base." );
            }

            RuleImpl rule = pkg.getRule( ruleName );
            if (rule == null) {
                throw new IllegalArgumentException( "Rule name '" + ruleName +
                                                    "' does not exist in the Package '" +
                                                    packageName +
                                                    "'." );
            }

            this.removalsSinceLock++;

            removeRule( pkg,
                        rule );
            pkg.removeRule( rule );
            addReloadDialectDatas( pkg.getDialectRuntimeRegistry() );
        } finally {
            unlock();
        }
    }
View Full Code Here

    public void removeFunction( final String packageName,
                                final String functionName ) {
        lock();
        try {
            final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
            if (pkg == null) {
                throw new IllegalArgumentException( "Package name '" + packageName +
                                                    "' does not exist for this Rule Base." );
            }

            Function function = pkg.getFunctions().get(functionName);
            if (function == null) {
                throw new IllegalArgumentException( "function name '" + packageName +
                                                    "' does not exist in the Package '" +
                                                    packageName +
                                                    "'." );
            }

            removeFunction( pkg,
                            functionName );
            pkg.removeFunction( functionName );
            if (rootClassLoader instanceof ProjectClassLoader) {
                ((ProjectClassLoader)rootClassLoader).undefineClass(function.getClassName());
            }

            addReloadDialectDatas( pkg.getDialectRuntimeRegistry() );
        } finally {
            unlock();
        }
    }
View Full Code Here

TOP

Related Classes of org.drools.core.definitions.InternalKnowledgePackage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.