0

私は、bpel テキスト ファイルを解析し、特定の単語の出現回数を返す Java クラスを作成しました。結果がコンソールではなくTextBoxに表示されるように、VB2008 Formsアプリケーションに変換したかったのです。問題は、VB2008 には現在の Java クラスにある Scanner および StringTokenizer クラスがないことです。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.
4

1 に答える 1

1

StringTokenizerの代わりに String.Splitを使用できます。Scanner を使用するには、System.IO.StreamReaderが適切な代替品である必要があります。

解析しているものは XML ファイルのように見えるため、文字列操作の代わりに .NET の XML 解析機能を使用することを検討してください。

于 2009-10-29T15:15:40.097 に答える