Package org.drools.lang.descr

Examples of org.drools.lang.descr.PackageDescr


    public void addPackageFromPMML(Resource resource, ResourceType type, ResourceConfiguration configuration) throws Exception {
        PMMLCompiler compiler = getPMMLCompiler();
        if ( compiler != null ) {
            if ( compiler.getResults().isEmpty() ) {
                this.resource = resource;
                PackageDescr descr = pmmlModelToPackageDescr(compiler, resource);
                if ( descr != null ) {
                    addPackage( descr );
                }
                this.resource = null;
            } else {
View Full Code Here


            this.results.addAll( compiler.getResults() );
            return null;
        }

        DrlParser parser = new DrlParser();
        PackageDescr pkg = parser.parse( new StringReader( theory ) );
        this.results.addAll( parser.getErrors() );
        if ( pkg == null ) {
            this.results.add( new ParserError( resource, "Parser returned a null Package", 0, 0 ) );
            return pkg;
        } else {
View Full Code Here

        if (pkgRegistry != null) {
            pkg = pkgRegistry.getPackage();
        }

        if (pkg == null) {
            PackageDescr packageDescr = new PackageDescr( newPkg.getName() );
            pkgRegistry = newPackage( packageDescr );
            mergePackage( this.pkgRegistryMap.get( packageDescr.getNamespace() ), packageDescr );
            pkg = pkgRegistry.getPackage();
        }

        // first merge anything related to classloader re-wiring
        pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry(),
View Full Code Here

        if ( typeDeclaration.getNature() == TypeDeclaration.Nature.DECLARATION || packageName.equals(typeDeclaration.getTypeClass().getPackage().getName()) ) {
            PackageRegistry packageRegistry = pkgRegistryMap.get( packageName );
            if (packageRegistry != null) {
                packageRegistry.getPackage().addTypeDeclaration( typeDeclaration );
            } else {
                newPackage( new PackageDescr( packageName, "" ) );
                pkgRegistryMap.get( packageName ).getPackage().addTypeDeclaration( typeDeclaration );
            }
        }
    }
View Full Code Here

            fillFieldTypes( typeDescr,
                            packageDescr );

            if ( !typeDescr.getNamespace().equals( packageDescr.getNamespace() ) ) {
                // If the type declaration is for a different namespace, process that separately.
                PackageDescr altDescr = new PackageDescr( typeDescr.getNamespace() );
                if ( typeDescr instanceof TypeDeclarationDescr ) {
                    altDescr.addTypeDeclaration( (TypeDeclarationDescr) typeDescr );
                } else if ( typeDescr instanceof EnumDeclarationDescr) {
                    altDescr.addEnumDeclaration( (EnumDeclarationDescr) typeDescr );
                }

                for ( ImportDescr imp : packageDescr.getImports() ) {
                    altDescr.addImport( imp );
                }
                if (!getPackageRegistry().containsKey( altDescr.getNamespace() )) {
                    newPackage(altDescr);
                }
                mergePackage( this.pkgRegistryMap.get( altDescr.getNamespace() ), altDescr );
            }

        }

        // sort declarations : superclasses must be generated first
View Full Code Here

                                             dotPos );
            }

            PackageRegistry pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            if ( pkgReg == null ) {
                pkgBuilder.addPackage( new PackageDescr( pkgName ) );
                pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            }

            JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect( "java" );
            dialect.addSrc( convertToResource( entry.getKey() ),
View Full Code Here

        if ( ruleSetName == null || ruleSetName.trim().equals( "" ) ) {
            throw new SAXParseException( "<package> requires a 'name' attribute",
                                         parser.getLocator() );
        }

        final PackageDescr packageDescr = new PackageDescr( ruleSetName.trim() );

        parser.setData( packageDescr );
        return packageDescr;
    }
View Full Code Here

    }

    public Object end(final String uri,
                      final String localName,
                      final ExtensibleXmlParser parser) throws SAXException {
        final PackageDescr packageDescr = ( PackageDescr ) parser.getData();
        final Element element = parser.endElementBuilder();

       
        NodeList imports = element.getElementsByTagName( "import" );

        for ( int i = 0, length = imports.getLength(); i < length; i++ ) {
            final String importEntry = ((Element)imports.item(i)).getAttribute( "name" );

            if ( importEntry == null || importEntry.trim().equals( "" ) ) {
                throw new SAXParseException( "<import> cannot be blank",
                                             parser.getLocator() );
            }
            packageDescr.addImport( new ImportDescr( importEntry ) );
        }
       
        NodeList importfunctions = element.getElementsByTagName( "importfunction" );

        for ( int i = 0, length = importfunctions.getLength(); i < length; i++ ) {
            final String importfunctionEntry = ((Element)importfunctions.item(i)).getAttribute( "name" );

            if ( importfunctionEntry == null || importfunctionEntry.trim().equals( "" ) ) {
                throw new SAXParseException( "<importfunction> cannot be blank",
                                             parser.getLocator() );
            }
           
            FunctionImportDescr funcdescr = new FunctionImportDescr();
            funcdescr.setTarget( importfunctionEntry );
           
            packageDescr.addFunctionImport(funcdescr);
        }
       
        NodeList globals = element.getElementsByTagName( "global" );

        for ( int i = 0, length = globals.getLength(); i < length; i++ ) {
            final String identifier = ((Element)globals.item(i)).getAttribute( "identifier" );

            if ( identifier == null || identifier.trim().equals( "" ) ) {
                throw new SAXParseException( "<global> must have an identifier",
                                             parser.getLocator() );
            }

            final String type = ((Element)globals.item(i)).getAttribute( "type" );
            if ( type == null || type.trim().equals( "" ) ) {
                throw new SAXParseException( "<global> must have specify a type",
                                             parser.getLocator() );
            }
            final GlobalDescr global = new GlobalDescr( identifier,
                                                        type );
            packageDescr.addGlobal( global );
        }

        return packageDescr;
    }
View Full Code Here

        return this.results;
    }

    private PackageDescr compile(boolean isEditor,
                                  final DRLParser parser ) throws DroolsParserException {
        PackageDescr pkgDescr = null;
        try {
            if ( isEditor ) {
                parser.enableEditorInterface();
            }
            pkgDescr = parser.compilationUnit(resource);
View Full Code Here

    }

    protected void loadImportsAndFunctions() {
        try {
            DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(this, true, false);
            PackageDescr descr = drlInfo.getPackageDescr();
            // package
            this.packageName = drlInfo.getPackageName();
            // imports
            List<ImportDescr> allImports = descr.getImports();
            this.imports = new ArrayList<String>();
            if (packageName != null) {
                imports.addAll(getAllClassesInPackage(packageName));
            }
            Iterator<ImportDescr> iterator = allImports.iterator();
            while (iterator.hasNext()) {
                String importName = iterator.next().getTarget();
                if (importName.endsWith(".*")) {
                    String packageName = importName.substring(0, importName.length() - 2);
                    imports.addAll(getAllClassesInPackage(packageName));
                } else {
                    imports.add(importName);
                }
            }
            // functions
            List<FunctionDescr> functionDescrs = descr.getFunctions();
            List<FunctionImportDescr> functionImports = descr.getFunctionImports();
            functions = new ArrayList<String>(functionDescrs.size());
            Iterator<FunctionDescr> iterator2 = functionDescrs.iterator();
            while (iterator2.hasNext()) {
                functions.add(iterator2.next().getName());
            }
            Iterator<FunctionImportDescr> iterator3 = functionImports.iterator();
            while (iterator3.hasNext()) {
                String functionImport = iterator3.next().getTarget();
                if (functionImport.endsWith(".*")) {
                    String className = functionImport.substring(0, functionImport.length() - 2);
                    functions.addAll(getAllStaticMethodsInClass(className));
                } else {
                    int index = functionImport.lastIndexOf('.');
                    if (index != -1) {
                        functions.add(functionImport.substring(index + 1));
                    }
                }
            }
            // globals
            List<GlobalDescr> globalDescrs = descr.getGlobals();
            globals = new ArrayList<GlobalDescr>();
            Iterator<GlobalDescr> iterator5 = globalDescrs.iterator();
            while (iterator5.hasNext()) {
                globals.add(iterator5.next());
            }

            //attributes
            this.attributes = new HashMap<String, String>();
            for (Iterator<AttributeDescr> attrIter = descr.getAttributes().iterator(); attrIter.hasNext();) {
                AttributeDescr attribute = attrIter.next();
                if (attribute != null && attribute.getName() != null) {
                    attributes.put(attribute.getName(), attribute.getValue());
                }
            }
View Full Code Here

TOP

Related Classes of org.drools.lang.descr.PackageDescr

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.