⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileexpressionstore.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        final java.io.File[] dirs =             new java.io.File(this.workDirectory)                .listFiles(new DirectoryFilter());        for (int i=0; i<dirs.length; i++)        {            log.debug                ("contentIterator() considering directory "+dirs[i].getPath());            final java.io.File[] digitDirs = dirs[i].listFiles();            for (int ii=0; ii<digitDirs.length; ii++)            {                final java.io.File[] wfidDirs = digitDirs[ii].listFiles();                for (int iii=0; iii<wfidDirs.length; iii++)                {                    log.debug                        ("contentIterator() in dir "+wfidDirs[iii].getPath());                    //                    // roam through each expression (with timeout) file                    java.io.File[] files = null;                    if (shortNames == null || shortNames.length < 1)                    {                        files = wfidDirs[iii]                            .listFiles(new FilenameFilter());                    }                    else                    {                        files = wfidDirs[iii]                            .listFiles(new FilenameFilter(shortNames));                    }                    for (int j=0; j<files.length; j++)                    {                        java.io.File file = files[j];                        log.debug("contentIterator() considering file "+file);                        //                        // test with the 'is instance of'                        if ( ! file.exists())                        {                            log.debug                                ("contentIterator() "+                                 "file doesn't exist. Skipped");                            continue;                        }                        FlowExpression fe = null;                        try                        {                            fe = loadExpression(file.getPath());                            //log.debug                            //    ("contentIterator() examining "+fe.getId());                        }                        catch (final Throwable t)                        {                            log.warn                                ("contentIterator() "+                                 "failed to load expression from file '"+                                 file.getPath()+"'", t);                            continue;                        }                        //log.debug("contentIterator() ...");                        if ( ! ExpoolUtils                                .isAssignableFromClass(fe, assignClass))                        {                            //log.debug                            //    ("contentIterator() not assignable from "+                            //     assignClass.getName());                            continue;                        }                        result.add(fe);                        log.debug("contentIterator() took "+fe.getId());                    }                }            }        }        final long elapsedTime = System.currentTimeMillis() - startTime;        log.debug("contentIterator() "+result.size()+" expressions matching");        log.debug("contentIterator() took "+elapsedTime+"ms");        return result.iterator();    }        /**     * Returns the count of expressions stored here.     */    public int size ()    {        int count = 0;        final java.io.File[] dirs =             new java.io.File(this.workDirectory)                .listFiles(new DirectoryFilter());        for (int i=0; i<dirs.length; i++)        {            //            // roam through each expression (with timeout) file            final java.io.File[] files = dirs[i]                .listFiles(new FilenameFilter(".*\\.xml"));            count += files.length;        }        return count;    }    /**     * returns true if the expression behind the expression id is still     * alive (present in the store).     * this implementation simply looks if the file for the expression     * exists and is not a directory. It makes no attempt at loading the     * expression and validating it.     */    public boolean isExpressionActive (final FlowExpressionId fei)    {        final String fileName = determineFileName(fei);        final java.io.File f = (new java.io.File(fileName));        return             (f.exists() && ! f.isDirectory());    }    //    // METHODS from Service    /**     * Status is outputted as a JDOM element. The status is various     * information about a service activities and state.     */    public org.jdom.Element getStatus ()    {        org.jdom.Element result = new org.jdom.Element(getName());        result.addContent(XmlUtils.getClassElt(this));        result.addContent(XmlUtils.getRevisionElt("$Id: FileExpressionStore.java,v 1.25 2005/07/17 16:31:49 jmettraux Exp $"));        int totalExpressionCount = 0;        //        // count expressions per flow instance                java.util.Map expressionsPerFlow = new java.util.HashMap();        java.util.Map expressionsPerInstance = new java.util.HashMap();        final java.io.File workDir =             new java.io.File(this.workDirectory);        final java.io.File[] flowDirs =             workDir.listFiles(new DirectoryFilter());        for (int i=0; i<flowDirs.length; i++)        {            final java.io.File flowDir = flowDirs[i];            final java.io.File[] subDirs = flowDir                .listFiles(new DirectoryFilter());            for (int j=0; j<subDirs.length; j++)            {                final java.io.File[] expFiles =                     subDirs[j].listFiles(new ExpressionFilter());                totalExpressionCount += expFiles.length;                expressionsPerFlow.put                    (flowDir.getName(), new Integer(expFiles.length));                for (int k=0; k<expFiles.length; k++)                {                    final String fileName = expFiles[k].getName();                    final String instanceId = ""+extractInstanceId(fileName);                    //log.debug("getStatus() considering file "+fileName);                    openwfe.org.Utils.inc(expressionsPerInstance, instanceId);                }            }        }        org.jdom.Element eFlows = new org.jdom.Element("flows");        java.util.Iterator it = expressionsPerFlow.keySet().iterator();        while (it.hasNext())        {            String flowDef = (String)it.next();            Integer count = (Integer)expressionsPerFlow.get(flowDef);            org.jdom.Element eFlow = new org.jdom.Element("flow");            eFlow.setAttribute("def", flowDef);            eFlow.setAttribute("expressions", count.toString());            eFlows.addContent(eFlow);        }        it = expressionsPerInstance.keySet().iterator();        while (it.hasNext())        {            String flowId = (String)it.next();            Integer count = (Integer)expressionsPerInstance.get(flowId);            org.jdom.Element eFlow = new org.jdom.Element("flow");            eFlow.setAttribute("id", flowId);            eFlow.setAttribute("expressions", count.toString());            eFlows.addContent(eFlow);        }        result.addContent(eFlows);        //        // add total expression count        org.jdom.Element eTotalExpressionCount =             new org.jdom.Element("expressionsStored");        eTotalExpressionCount.addContent            (new org.jdom.Text(""+totalExpressionCount));        result.addContent(eTotalExpressionCount);        //        // the end        return result;    }    /* *     * A debug method : will dump the status of the store in      * $OPENWFE_HOME/logs/store_dump.xml     * /    protected void dumpStatus ()    {        final org.jdom.Document doc = new org.jdom.Document(getStatus());        final String s = openwfe.org.Utils.toString(doc, null);            // 'null' means : use default encoding        final String dumpFileName = getContext()            .getApplicationDirectory()+"logs/store_dump.xml";        try        {            final java.io.BufferedWriter bw = new java.io.BufferedWriter                (new java.io.FileWriter(dumpFileName));            bw.write(s);            bw.flush();            bw.close();        }        catch (final Exception e)        {            log.warn                ("Failed to dump to "+dumpFileName, e);        }    }     */    //     // STATIC METHODS    private static long extractInstanceId (final String fileName)    {        final int i = fileName.indexOf("--");        if (i < 0) return -1;        try        {            return Long.parseLong(fileName.substring(0, i));        }        catch (NumberFormatException nfe)        {            log.warn("failed to parse '"+fileName+"' (til '--') into a long");        }        return -1;    }    //    // INNER CLASSES    private static class ExpressionFilter        implements java.io.FilenameFilter    {        public boolean accept (final java.io.File dir, final String fileName)        {            return fileName.endsWith(".xml");        }    }    private static class FilenameFilter        implements java.io.FilenameFilter    {        private String[] shortNames = null;        public FilenameFilter ()        {        }        public FilenameFilter (final String expressionShortName)        {            this.shortNames = new String[] { expressionShortName };        }        public FilenameFilter (final String[] expressionShortNames)        {            this.shortNames = expressionShortNames;        }        public boolean accept (final java.io.File dir, final String fileName)        {            if ( ! fileName.endsWith(".xml")) return false;            if (this.shortNames == null) return true;            for (int i=0; i<this.shortNames.length; i++)            {                if (fileName.matches(".*--"+this.shortNames[i]+"--.*\\.xml"))                {                    return true;                }            }            return false;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -