Package org.drools.rule

Examples of org.drools.rule.TypeDeclaration


        ClassDefinition mcClassDef = new ClassDefinition( MapCore.class.getName(), MapCore.class.getSuperclass().getName(), mcInterfaces );
        mcClassDef.setTraitable( true );
        mcClassDef.setDefinedClass( MapCore.class );
        mcClassDef.setAbstrakt( false );

        TypeDeclaration mapCoreType = new TypeDeclaration( MapCore.class.getName() );
        mapCoreType.setKind( TypeDeclaration.Kind.CLASS );
        mapCoreType.setTypeClass( MapCore.class );
        mapCoreType.setTypeClassDef( mcClassDef );

        return mapCoreType;
    }
View Full Code Here


    }

    private void calculateModificationMask(KnowledgeHelper knowledgeHelper, WithNode node) {
        Class<?> nodeClass = node.getEgressType();
        InternalRuleBase ruleBase = (InternalRuleBase)knowledgeHelper.getWorkingMemory().getRuleBase();
        TypeDeclaration typeDeclaration = ruleBase.getTypeDeclaration(nodeClass);
        if (typeDeclaration == null || !typeDeclaration.isPropertyReactive()) {
            modificationMask = Long.MAX_VALUE;
            return;
        }

        List<String> settableProperties = typeDeclaration.getSettableProperties();
        modificationMask = 0L;

        // TODO: access parmValuePairs without reflection
        WithNode.ParmValuePair[] parmValuePairs = getFieldValue(WithNode.class, "withExpressions", node);
        for (WithNode.ParmValuePair parmValuePair : parmValuePairs) {
            Method method = extractMethod(parmValuePair);
            if (method == null) {
                modificationMask = Long.MAX_VALUE;
                return;
            }

            String propertyName = setter2property(method.getName());
            if (propertyName != null) {
                int pos = settableProperties.indexOf(propertyName);
                if (pos >= 0) modificationMask = BitMaskUtil.set(modificationMask, pos);
            }

            List<String> modifiedProps = typeDeclaration.getTypeClassDef().getModifiedPropsByMethod(method);
            if (modifiedProps != null) {
                for (String modifiedProp : modifiedProps) {
                    int pos = settableProperties.indexOf(modifiedProp);
                    if (pos >= 0) modificationMask = BitMaskUtil.set(modificationMask, pos);
                }
View Full Code Here

    }

    private boolean inspectForTraitability( Object value, WorkingMemory wm ) {
        Package pack = wm.getRuleBase().getPackage( value.getClass().getPackage().getName() );
        if ( pack != null ) {
            TypeDeclaration decl = pack.getTypeDeclaration( value.getClass() );
            if ( decl != null ) {
                return decl.getTypeClassDef().isFullTraiting();
            }
        }
        Traitable tbl =  value.getClass().getAnnotation( Traitable.class );
        return tbl != null && tbl.logical();
    }
View Full Code Here

            setDeclaredMask( -1L );
            return;
        }

        Class objectClass = ((ClassObjectType)objectType).getClassType();
        TypeDeclaration typeDeclaration = context.getRuleBase().getTypeDeclaration(objectClass);
        if typeDeclaration == null || !typeDeclaration.isPropertyReactive() ) {
            // if property specific is not on, then accept all modification propagations
            setDeclaredMask( -1L );
        } else  {
            List<String> settableProperties = getSettableProperties(context.getRuleBase(), objectClass);
            setDeclaredMask( calculatePositiveMask(pattern.getListenedProperties(), settableProperties) );
View Full Code Here

            declaredMask = -1L;
            return;
        }
       
        Class objectClass = ((ClassObjectType)objectType).getClassType();       
        TypeDeclaration typeDeclaration = context.getRuleBase().getTypeDeclaration(objectClass);
        if ( typeDeclaration == null || !typeDeclaration.isPropertyReactive() ) {
            // if property specific is not on, then accept all modification propagations
            declaredMask = -1L;
        } else {
            List<String> settableProperties = getSettableProperties(context.getRuleBase(), objectClass);
            declaredMask = calculateDeclaredMask(settableProperties);
View Full Code Here

    }

    protected  <K> ClassDefinition lookupClassDefinition( K core ) {
        Package pack = this.getWorkingMemory().getRuleBase().getPackage( core.getClass().getPackage().getName() );
        if ( pack != null ) {
            TypeDeclaration decl = pack.getTypeDeclaration( core.getClass() );
            if ( decl != null ) {
                return decl.getTypeClassDef();
            }
        }
        return null;
    }
View Full Code Here

                                             final long recency,
                                             final ObjectTypeConf conf,
                                             final InternalWorkingMemory workingMemory,
                                             final WorkingMemoryEntryPoint wmEntryPoint) {
        if ( conf != null && conf.isEvent() ) {
            TypeDeclaration type = conf.getTypeDeclaration();
            long timestamp;
            if ( type.getTimestampExtractor() != null ) {
                timestamp = type.getTimestampExtractor().getLongValue( workingMemory,
                                                                       object );
            } else {
                timestamp = workingMemory.getTimerService().getCurrentTime();
            }
            long duration = 0;
            if ( type.getDurationExtractor() != null ) {
                duration = type.getDurationExtractor().getLongValue( workingMemory,
                                                                     object );
            }
            return new EventFactHandle( id,
                                        object,
                                        recency,
View Full Code Here

    public static boolean isPropertyReactive(BuildContext context, ObjectType objectType) {
        return objectType instanceof ClassObjectType && isPropertyReactive(context, ((ClassObjectType) objectType).getClassType());
    }

    public static boolean isPropertyReactive(BuildContext context, Class<?> objectClass) {
        TypeDeclaration typeDeclaration = context.getRuleBase().getTypeDeclaration( objectClass );
        return typeDeclaration != null && typeDeclaration.isPropertyReactive();
    }
View Full Code Here

    public static List<String> getSettableProperties(InternalRuleBase ruleBase, Class<?> nodeClass) {
        if (nodeClass == null) {
            return null;
        }
        TypeDeclaration typeDeclaration = ruleBase.getTypeDeclaration(nodeClass);
        if (typeDeclaration == null) {
            return ClassUtils.getSettableProperties(nodeClass);
        }
        typeDeclaration.setTypeClass(nodeClass);
        return typeDeclaration.getSettableProperties();
    }
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 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

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.