java - 将java类转换为vb 2008应用程序

标签 java vb.net bpel

我编写了一个 Java 类,它解析 bpel 文本文件,然后返回某些单词出现次数的计数。我想将其转换为 VB2008 Forms 应用程序,以便其结果显示在文本框中而不是控制台上。问题是VB2008缺少Scanner和StringTokenizer类,它们在我当前的Java类中。我不确定如何在 VB2008 中获得相同的功能(或更好的功能)。有人可以帮助转换这个类吗?谢谢。

Java类如下:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class StringParser 
{
private int ctrlFlowStructures;
private String filePath;
private ArrayList<String> activities;   
final String[] ctrlFlowsArray={"sequence","if","while","repeatUntil","forEach", "pick","flow"};

public StringParser(String path)         
{
    filePath=path;
    ctrlFlowStructures =0;
    activities=new ArrayList<String>();
}    

//count number of occurences of words in ctrlFlowStructureArray
public int countCtrlFlowStructures ()
{    
    Scanner input=null;
    StringTokenizer st;
    String line=null;
    String openingComment="!--";
    String closingComment="--";
    int c=0;

    try
    {
        input=new Scanner( new FileInputStream(filePath));
    }

    catch(FileNotFoundException e)
    {
        System.out.println("Problem opening files.");
        System.exit(0);
    }        

    while(input.hasNextLine())
    {
        line=input.nextLine();
        line.trim(); 
        st= new StringTokenizer(line, " <,>\"",false);    
        String temp=null;                 
        while (st.hasMoreTokens())
        {  
            temp=st.nextToken();             

            //eliminate comments
            if(temp.equals(openingComment)||temp.equalsIgnoreCase("documentation"))
            {
                c=1;
            }
            if(temp.equals(closingComment)||temp.equalsIgnoreCase("/documentation"))
            {
                c=2;
            }
            if(c==0||c==2)
            {               
                for(int i=0;i< ctrlFlowsArray.length;i++)
                if(temp.equalsIgnoreCase(ctrlFlowsArray [i]))
                {
                    ctrlFlowStructures ++;                     
                }
            }
        }  
    } 
    input.close();   
    return ctrlFlowStructures;
}

//display control flow structures
public void display()
{
    int openingComment=0; //number of occurrence of an activity
    for(int i=0;i< ctrlFlowsArray.length;i++)
    {           
        for (int j=0;j<activities.size();j++)
        {               
            if(ctrlFlowsArray [i].equalsIgnoreCase(activities.get(j)))
            {
                openingComment++;
            }               
        }
        if(openingComment>0)
        {
            System.out.println(ctrlFlowsArray [i]+" = "+openingComment);
            openingComment=0;
        }
    }
}
public static void main(String[] args)    
{
    StringParser sp=new StringParser("c:\\MyFile1.bpel");
    int a = sp.countCtrlFlowStructures();        
    System.out.println(" The number of control-flow structure(s) = " + a);         
}
}

这是已解析的 MyFile1.bpel 文件的代码片段:

    <sequence>
    <documentation>
        The sequence includes several activities which are executed in lexical order.
    </documentation>

    <receive
        name="start"
        partnerLink="MyProcess"
        operation="operation1"
        portType="ns1:portType1"
        variable="inputVar"
        createInstance="yes">

        <documentation>
            The Receive activity makes the process to wait for the incoming message to arrive.
        </documentation>
    </receive>

    <assign name="Assign1">
        <documentation>
            The Assign activity copies data from the input variable to the output variable.
        </documentation>

        <copy>
            <from>$inputVar.inputType/ns2:paramA</from>
            <to>$outputVar.resultType/ns2:paramA</to>
        </copy>
    </assign>

    <reply
        name="end"
        partnerLink="MyProcess"
        operation="operation1"
        portType="ns1:portType1"
        variable="outputVar">

        <documentation>
            The Reply activity returns a message from the process to the  partner which initiated the communication.
        </documentation>
    </reply>
</sequence>

结果:

The number of control-flow structure(s) = 1.

最佳答案

您可以使用String.Split而不是 StringTokenizer。为了您使用扫描仪,System.IO.StreamReader应该是一个合适的替代品。

由于您正在解析的内容看起来像 XML 文件,因此您可以考虑使用 .NET 的 XML 解析功能而不是字符串操作。

关于java - 将java类转换为vb 2008应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1643979/

相关文章:

java - stdrandom shuffle 方法的工作原理

java - JDA Discord 机器人删除文本 channel 中的所有消息

java - 缩短 AWT 异常堆栈跟踪

vb.net - 在vb中禁用回车键选择按钮

vb.net - 在VB.NET错误BC42025中,短语 "qualifying expression will not be evaluated"是什么意思?

java - 有 BPEL 异步 Web 服务的示例吗?

Java Web 服务和 BPEL

java - 在 Android 中使用线程时出现错误

vb.net - 循环遍历 TreeView 节点以删除某些节点

debugging - 用于调试目的的 WSO2 工作流执行跟踪