Examples of DescrBuildError


Examples of org.drools.compiler.compiler.DescrBuildError

        if ( descr.getType() == ExprConstraintDescr.Type.POSITIONAL && pattern.getObjectType() instanceof ClassObjectType ) {
            Class< ? > klazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
            TypeDeclaration tDecl = context.getKnowledgeBuilder().getTypeDeclaration( klazz );

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

            ClassDefinition clsDef = tDecl.getTypeClassDef();
            if ( clsDef == null ) {
                context.addError(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.addError(new DescrBuildError(context.getParentDescr(),
                        descr,
                        null,
                        "Unable to find @positional field " + descr.getPosition() + " for class " + tDecl.getTypeName() + "\n"));
                return;
            }
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                                                                 final boolean reportError ) {
        Map<String, Class< ? >> declarations = new HashMap<String, Class< ? >>();
        for ( Map.Entry<String, Declaration> entry : context.getDeclarationResolver().getDeclarations( context.getRule() ).entrySet() ) {
            if ( entry.getValue().getExtractor() == null ) {
                if ( reportError ) {
                    context.addError(new DescrBuildError(context.getParentDescr(),
                            baseDescr,
                            null,
                            "Field Reader does not exist for declaration '" + entry.getKey() + "' in '" + baseDescr + "' in the rule '" + context.getRule().getName() + "'"));
                }
                continue;
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                                                                                                              ((ClassObjectType) objectType).getClassType() ) );

                if ( analysis == null ) {
                    // something bad happened
                    if ( reportError ) {
                        context.addError(new DescrBuildError(context.getParentDescr(),
                                descr,
                                null,
                                "Unable to analyze expression '" + fieldName + "'"));
                    }
                    return null;
                }

                final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();

                if ( !usedIdentifiers.getDeclrClasses().isEmpty() ) {
                    if ( reportError && descr instanceof BindingDescr ) {
                        context.addError(new DescrBuildError(context.getParentDescr(),
                                descr,
                                null,
                                "Variables can not be used inside bindings. Variable " + usedIdentifiers.getDeclrClasses().keySet() + " is being used in binding '" + fieldName + "'"));
                    }
                    return null;
                }

                reader = context.getPkg().getClassFieldAccessorStore().getMVELReader( context.getPkg().getName(),
                                                                                      ((ClassObjectType) objectType).getClassName(),
                                                                                      fieldName,
                                                                                      context.isTypesafe(),
                                                                                      ((MVELAnalysisResult)analysis).getReturnType() );
               
                MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
                ((MVELCompileable) reader).compile( data );
                data.addCompileable( (MVELCompileable) reader );
            } catch ( final Exception e ) {
                int dotPos = fieldName.indexOf('.');
                String varName = dotPos > 0 ? fieldName.substring(0, dotPos).trim() : fieldName;
                if (globals.containsKey(varName)) {
                    return null;
                }

                if ( reportError ) {
                    DialectUtil.copyErrorLocation(e,
                            descr);
                    context.addError(new DescrBuildError(context.getParentDescr(),
                            descr,
                            e,
                            "Unable to create reader for '" + fieldName + "':" + e.getMessage()));
                }
                // if there was an error, set the reader back to null
                reader = null;
            } finally {
                context.setDialect( dialect );
            }
        } else {
            Declaration decl = context.getDeclarationResolver().getDeclarations( context.getRule() ).get(fieldName);
            if (decl != null && decl.getExtractor() instanceof ClassFieldReader && "this".equals(((ClassFieldReader)decl.getExtractor()).getFieldName())) {
                return decl.getExtractor();
            }

            boolean alternatives = false;
            try {
                Map<String, Class< ? >> declarations = getDeclarationsMap( descr, context, false );
                Map<String, Class< ? >> globals = context.getKnowledgeBuilder().getGlobals();
                alternatives = declarations.containsKey( fieldName ) || globals.containsKey( fieldName );

                reader = context.getPkg().getClassFieldAccessorStore().getReader( ((ClassObjectType) objectType).getClassName(),
                                                                                  fieldName,
                                                                                  target );
            } catch ( final Exception e ) {
                if ( reportError && ! alternatives && context.isTypesafe() ) {
                    DialectUtil.copyErrorLocation(e,
                            descr);
                    context.addError(new DescrBuildError(context.getParentDescr(),
                            descr,
                            e,
                            "Unable to create Field Extractor for '" + fieldName + "'" + e.getMessage()));
                }
                // if there was an error, set the reader back to null
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

        DrlExprParser parser = new DrlExprParser( context.getConfiguration().getLanguageLevel() );
        ConstraintConnectiveDescr result = parser.parse( expression );
        result.copyLocation( original );
        if ( parser.hasErrors() ) {
            for ( DroolsParserException error : parser.getErrors() ) {
                context.addError(new DescrBuildError(context.getParentDescr(),
                        patternDescr,
                        null,
                        "Unable to parser pattern expression:\n" + error.getMessage()));
            }
            return null;
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                types[ numParams ] = returnKlass.getName();

                ((AbductiveQuery) query).setReturnType( objectType, params );

            } catch ( ClassNotFoundException e ) {
                context.addError( new DescrBuildError( context.getParentDescr(),
                                                       queryDescr,
                                                       e,
                                                       "Unable to resolve abducible type : " + returnName ) );
            } catch ( NoSuchMethodException e ) {
                context.addError( new DescrBuildError( context.getParentDescr(),
                                                       queryDescr,
                                                       e,
                                                       "Unable to resolve abducible constructor for type : " + returnName +
                                                       " with types " + types ) );

            }
        }

        int i = 0;
        try {
            for ( i = 0; i < params.length; i++ ) {
                Declaration declr = pattern.addDeclaration( params[i] );
               
                // this bit is different, notice its the ArrayElementReader that we wire up to, not the declaration.
                ArrayElementReader reader = new ArrayElementReader( arrayExtractor,
                                                                    i,
                                                                    context.getDialect().getTypeResolver().resolveType( types[i] ) );
                PatternBuilder.registerReadAccessor( context, argsObjectType, "elements", reader );
               
                declr.setReadAccessor( reader );
               
                declarations[i] = declr;
             }

            query.setParameters( declarations );

        } catch ( ClassNotFoundException e ) {
            context.addError( new DescrBuildError( context.getParentDescr(),
                                                          queryDescr,
                                                          e,
                                                          "Unable to resolve type '" + types[i] + " for parameter" + params[i] ) );
        }
        context.setPrefixPattern( pattern );
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                returnType = MVEL.analyze( expr,
                                           parserContext1 );
            } catch ( Exception e ) {
                BaseDescr base = (context instanceof RuleBuildContext) ? ((RuleBuildContext)context).getRuleDescr() : context.getParentDescr();
                DialectUtil.copyErrorLocation(e, context.getParentDescr());
                context.addError( new DescrBuildError( base,
                                                              context.getParentDescr(),
                                                              null,
                                                              "Unable to Analyse Expression " + expr + ":\n" + e.getMessage() ) );
                return null;
            }

            Set<String> requiredInputs = new HashSet<String>();
            requiredInputs.addAll( parserContext1.getInputs().keySet() );
            HashMap<String, Class< ? >> variables = (HashMap<String, Class< ? >>) ((Map) parserContext1.getVariables());
            if ( localTypes != null ) {
                for ( String str : localTypes.keySet() ) {
                    // we have to do this due to mvel regressions on detecting true local vars
                    variables.remove( str );
                }
            }

            // MVEL includes direct fields of context object in non-strict mode. so we need to strip those
            if ( availableIdentifiers.getThisClass() != null ) {
                for ( Iterator<String> it = requiredInputs.iterator(); it.hasNext(); ) {
                    if ( PropertyTools.getFieldOrAccessor( availableIdentifiers.getThisClass(),
                                                           it.next() ) != null ) {
                        it.remove();
                    }
                }
            }

            // now, set the required input types and compile again
            final ParserContext parserContext2 = new ParserContext( conf );
            parserContext2.setStrictTypeEnforcement( true );
            parserContext2.setStrongTyping( true );
            parserContext2.setInterceptors( dialect.getInterceptors() );

            for ( String str : requiredInputs ) {
                Class< ? > cls = availableIdentifiers.getDeclrClasses().get( str );
                if ( cls != null ) {
                    parserContext2.addInput( str,
                                             cls );
                    continue;
                }

                cls = availableIdentifiers.getGlobals().get( str );
                if ( cls != null ) {
                    parserContext2.addInput( str,
                                             cls );
                    continue;
                }

                cls = availableIdentifiers.getOperators().keySet().contains( str ) ? context.getConfiguration().getComponentFactory().getExpressionProcessor().getEvaluatorWrapperClass() : null;
                if ( cls != null ) {
                    parserContext2.addInput( str,
                                             cls );
                    continue;
                }

                if ( str.equals( contextIndeifier ) ) {
                    parserContext2.addInput( contextIndeifier,
                                             kcontextClass );
                } else if ( str.equals( "kcontext" ) ) {
                    parserContext2.addInput( "kcontext",
                                             kcontextClass );
                }
                if ( str.equals( "rule" ) ) {
                    parserContext2.addInput( "rule",
                                             Rule.class );
                }

                if ( localTypes != null ) {
                    cls = localTypes.get( str );
                    if ( cls != null ) { 
                        parserContext2.addInput( str,
                                                 cls );
                    }
                }
            }  
           
            if ( availableIdentifiers.getThisClass() != null ) {
                parserContext2.addInput( "this",
                                         availableIdentifiers.getThisClass() );
            }

            boolean typesafe = context.isTypesafe();
           
            try {
                returnType = MVEL.analyze( expr,
                                           parserContext2 );
                typesafe = true;
            } catch ( Exception e ) {
                // is this an error, or can we fall back to non-typesafe mode?
                if ( typesafe ) {
                    BaseDescr base = (context instanceof RuleBuildContext) ? ((RuleBuildContext)context).getRuleDescr() : context.getParentDescr();
                    DialectUtil.copyErrorLocation(e, context.getParentDescr());
                    context.addError( new DescrBuildError( base,
                                                           context.getParentDescr(),
                                                           null,
                                                           "Unable to Analyse Expression " + expr + ":\n" + e.getMessage() ) );
                    return null;                   
                }
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                                 expr );
           
            expr.compile( data );
        } catch ( final Exception e ) {
            copyErrorLocation(e, context.getRuleDescr());
            context.addError( new DescrBuildError( context.getParentDescr(),
                                                          context.getRuleDescr(),
                                                          null,
                                                          "Unable to build expression for 'salience' : " + e.getMessage() + "'" + context.getRuleDescr().getSalience() + "'" ) );
        } finally {
            context.setTypesafe( typesafe );
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

                                 expr );

            expr.compile( data );
        } catch ( final Exception e ) {
            DialectUtil.copyErrorLocation(e, context.getRuleDescr());
            context.addError( new DescrBuildError( context.getParentDescr(),
                                                          context.getRuleDescr(),
                                                          null,
                                                          "Unable to build expression for 'enabled' : " + e.getMessage() + " '" + context.getRuleDescr().getEnabled() + "'" ) );
        }
    }
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

            expr.compile( data );
            return eval;
        } catch ( final Exception e ) {
            copyErrorLocation(e, evalDescr);
            context.addError( new DescrBuildError( context.getParentDescr(),
                                                          evalDescr,
                                                          e,
                                                          "Unable to build expression for 'eval':" + e.getMessage() + " '" + evalDescr.getContent() + "'" ) );
            return null;
        } finally {
View Full Code Here

Examples of org.drools.compiler.compiler.DescrBuildError

        final Boolean[] notPatterns = new Boolean[declarations.length];
        for ( int i = 0, length = declarations.length; i < length; i++ ) {
            indexes[i] = i;
            notPatterns[i] = (declarations[i].getExtractor() instanceof AcceptsClassObjectType) ? Boolean.FALSE : Boolean.TRUE ;
            if (indexes[i] == -1 ) {
                context.addError( new DescrBuildError( context.getParentDescr(),
                                                              context.getRuleDescr(),
                                                              null,
                                                              "Internal Error : Unable to find declaration in list while generating the consequence invoker" ) );
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.