Package org.drools.rule

Examples of org.drools.rule.TypeDeclaration


           "end\n" +
           "declare " + DImpl.class.getCanonicalName() + "\n" +
           "end\n";          

        PackageBuilder builder = getPackageBuilder( str );
        TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class );
        assertEquals( true, tdecl.isTypesafe() );
        assertEquals( Role.EVENT, tdecl.getRole() );
    }    
View Full Code Here


           "    @role(fact)\n" +             
           "end\n" +            
           "declare " + DImpl.class.getCanonicalName() + "\n" +
           "end\n";
        PackageBuilder builder = getPackageBuilder( str );
        TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class );
        assertEquals( true, tdecl.isTypesafe() );
        assertEquals( Role.FACT, tdecl.getRole() );       
    }     
View Full Code Here

                    }           
                    pkg.getClassFieldAccessorStore().merge( newPkg.getClassFieldAccessorStore() );
                    pkg.getDialectRuntimeRegistry().onBeforeExecute();
                   
                    // we have to do this before the merging, as it does some classloader resolving
                    TypeDeclaration lastType = null;
                    try {
                        // Add the type declarations to the RuleBase
                        if ( newPkg.getTypeDeclarations() != null ) {
                            // add type declarations
                            for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
                                lastType = type;
                                type.setTypeClass( this.rootClassLoader.loadClass( type.getTypeClassName() ) );
                                // @TODO should we allow overrides? only if the class is not in use.
                                if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
                                    // add to rulebase list of type declarations                       
                                    this.classTypeDeclaration.put( type.getTypeClass(),
                                                                   type );
                                }
                            }
                        }
                    } catch ( ClassNotFoundException e ) {
                        throw new RuntimeDroolsException( "unable to resolve Type Declaration class '" + lastType.getTypeName()+"'" );           
                    }           
   
                    // now merge the new package into the existing one
                    mergePackage( pkg,
                                  newPkg );
View Full Code Here

                        tempDescr.setNamespace( typeDescr.getNamespace() );
                        tempDescr.setFields( typeDescr.getFields() );
                        tempDescr.setType( target,
                                           typeDescr.getNamespace() );
                        tempDescr.addSuperType( typeDescr.getType() );
                        TypeDeclaration tempDeclr = new TypeDeclaration( target );
                        tempDeclr.setFormat( TypeDeclaration.Format.TRAIT );
                        tempDeclr.setTypesafe( type.isTypesafe() );
                        tempDeclr.setNovel( true );
                        tempDeclr.setTypeClassName( tempDescr.getType().getFullName() );
                        tempDeclr.setResource( type.getResource() );

                        ClassDefinition tempDef = new ClassDefinition( target );
                        tempDef.setClassName( tempDescr.getType().getFullName() );
                        tempDef.setTraitable( false );
                        for ( FieldDefinition fld : def.getFieldsDefinitions() ) {
View Full Code Here

            for (Package newPkg : newPkgs) {
                Package pkg = this.pkgs.get( newPkg.getName() );

                // we have to do this before the merging, as it does some classloader resolving
                TypeDeclaration lastType = null;
                try {
                    // Add the type declarations to the RuleBase
                    if (newPkg.getTypeDeclarations() != null) {
                        // add type declarations
                        for (TypeDeclaration newDecl : newPkg.getTypeDeclarations().values()) {
                            lastType = newDecl;
                            newDecl.setTypeClass( this.rootClassLoader.loadClass( newDecl.getTypeClassName() ) );
                            // @TODO should we allow overrides? only if the class is not in use.
                            TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( newDecl.getTypeClass() );
                            if (typeDeclaration == null) {
                                // add to rulebase list of type declarations                       
                                this.classTypeDeclaration.put( newDecl.getTypeClass(),
                                                               newDecl );
                                typeDeclaration = newDecl;
View Full Code Here

        public TypeDeclaration candidate = null;
        public int             score     = Integer.MAX_VALUE;
    }

    public TypeDeclaration getTypeDeclaration( Class<?> clazz ) {
        TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( clazz );
        if (typeDeclaration == null) {
            // check super classes and keep a score of how up in the hierarchy is there a declaration
            TypeDeclarationCandidate candidate = checkSuperClasses( clazz );
            // now check interfaces
            candidate = checkInterfaces( clazz,
View Full Code Here

        return typeDeclaration;
    }

    private TypeDeclarationCandidate checkSuperClasses( Class<?> clazz ) {
        TypeDeclarationCandidate candidate = null;
        TypeDeclaration typeDeclaration = null;
        Class<?> current = clazz.getSuperclass();
        int score = 0;
        while (typeDeclaration == null && current != null) {
            score++;
            typeDeclaration = this.classTypeDeclaration.get( current );
View Full Code Here

    private TypeDeclarationCandidate checkInterfaces( Class<?> clazz,
            TypeDeclarationCandidate baseline,
            int level ) {
        TypeDeclarationCandidate candidate = null;
        TypeDeclaration typeDeclaration = null;
        if (baseline == null || level < baseline.score) {
            // search
            for (Class<?> ifc : clazz.getInterfaces()) {
                typeDeclaration = this.classTypeDeclaration.get( ifc );
                if (typeDeclaration != null) {
View Full Code Here

        // adding the newly created pattern to the build stack this is necessary in case of local declaration usage
        context.getBuildStack().push( pattern );

        if ( pattern.getObjectType() instanceof ClassObjectType ) {
            Class< ? > cls = ((ClassObjectType) pattern.getObjectType()).getClassType();
            TypeDeclaration typeDeclr = context.getPackageBuilder().getTypeDeclaration( cls );
            if ( typeDeclr != null ) {
                context.setTypesafe( typeDeclr.isTypesafe() );
            } else {
                context.setTypesafe( true );
            }
        }
View Full Code Here

                                    final PatternDescr patternDescr,
                                    final Pattern pattern,
                                    final ExprConstraintDescr descr ) {
        if ( descr.getType() == ExprConstraintDescr.Type.POSITIONAL && pattern.getObjectType() instanceof ClassObjectType ) {
            Class< ? > klazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
            TypeDeclaration tDecl = context.getPackageBuilder().getTypeDeclaration( klazz );

            if ( tDecl == null ) {
                context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                              descr,
                                                              klazz,
                                                              "Unable to find @positional definitions for :" + klazz + "\n" ) );
                return;
            }

            ClassDefinition clsDef = tDecl.getTypeClassDef();
            if ( clsDef == null ) {
                context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                              descr,
                                                              null,
                                                              "Unable to find @positional field " + descr.getPosition() + " for class " + tDecl.getTypeName() + "\n" ) );
                return;
            }

            FieldDefinition field = clsDef.getField( descr.getPosition() );
            if ( field == null ) {
                context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                              descr,
                                                              null,
                                                              "Unable to find @positional field " + descr.getPosition() + " for class " + tDecl.getTypeName() + "\n" ) );
                return;
            }

            // TODO: WTH is this??????
            DRLLexer lex = new DRLLexer( new ANTLRStringStream( descr.getExpression() ) );
View Full Code Here

TOP

Related Classes of org.drools.rule.TypeDeclaration

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.