corbamnq.java

来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 220 行

JAVA
220
字号
package com.corba.mnq.main;

import com.corba.mnq.tool.EtcProperties;
import com.corba.mnq.tool.GetEtcTool;
import com.corba.mnq.tool.LoggerTool;
import com.corba.mnq.tool.Warehouse;
import com.corba.mnq.tool.idl.IdlFile;
import com.corba.mnq.tool.idl.IdlRoot;
import com.corba.mnq.tool.idl.type.TypeBase;
import com.corba.mnq.ui.WelcomeScreen;

import java.io.File;
import java.io.FileInputStream;
import java.util.logging.Logger;

import org.omg.PortableServer.IdAssignmentPolicyValue;
import org.omg.PortableServer.LifespanPolicyValue;
import org.omg.PortableServer.POA;

public class CorbaMNQ {

    /** used for java.util.logging */
    private static final Logger LOG = Logger.getLogger(CorbaMNQ.class.getName());

    public CorbaMNQ() {
        super();
        // TODO Auto-generated constructor stub
    }

    public static String ossDir = System.getProperty("CorbaMNQ.dir", ".");

    public static String projectDir = ossDir;

    public static EtcProperties props = GetEtcTool.getProperties();

    public static CorbaMNQ test = new CorbaMNQ();

    public static String initProjectName = "";

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            // URL pic =
            // ClassLoader.class.getResource("/images/mnq.gif");
            // WelcomeScreen.instance().setFile(pic);
            WelcomeScreen.instance().dispaly();
            while (WelcomeScreen.instance().wait) {
                try {
                    Thread.sleep(50);
                } catch (Exception e) {
                    //
                }
            }

            WelcomeScreen.instance().exit();

            parseIdls(projectDir);

            Thread t = new Thread(new Runnable() {

                public void run() {
                    try {
                        POA rootPoa = org.omg.PortableServer.POAHelper.narrow(TypeBase.orb
                                .resolve_initial_references("RootPOA"));

                        // create special policies
                        org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
                        policies[0] = rootPoa
                                .create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
                        policies[1] = rootPoa
                                .create_lifespan_policy(LifespanPolicyValue.PERSISTENT);

                        /**
                         * Create a POA with a short name, as the name
                         * will become part of every of its OID, which
                         * will be transmitted with every Corba call.
                         */
                        poa = rootPoa.create_POA("Mnq$$", rootPoa.the_POAManager(), policies);

                        poa.the_POAManager().activate();
                        TypeBase.orb.run();
                    } catch (Exception e) {
                        LoggerTool.logStackTrace(e, LOG);
                    }
                }
            });
            t.start();

            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {
                    MNQmainFrame.createAndShowGUI(initProjectName);
                }
            });

        } catch (Exception e) {
            LoggerTool.logStackTrace(e, LOG);
        }
    }

    /**
     * Method: "parseIdls"
     * 
     * @param dir
     */
    public static void parseIdls(String dir) {
        double usedTime = System.currentTimeMillis();
        File file = new File(dir + File.separator + "idl");
        test.doMore(file, true);
        usedTime = System.currentTimeMillis() - usedTime;
        LOG.info("Total time: " + usedTime / 1000 + " seconds");
    }

    public void reloadProject() {
        IdlRoot.sibling.clear();
        Warehouse.clear();

        double usedTime = System.currentTimeMillis();
        File file = new File(projectDir + File.separator + "idl");
        test.doMore(file, true);
        usedTime = System.currentTimeMillis() - usedTime;
        LOG.info("Tital time: " + usedTime / 1000 + " seconds");

        if (TypeBase.orb != null) {
            poa.destroy(true, true);
            try {
                POA rootPoa = org.omg.PortableServer.POAHelper.narrow(TypeBase.orb
                        .resolve_initial_references("RootPOA"));

                // create special policies
                org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
                policies[0] = rootPoa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
                policies[1] = rootPoa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);

                /**
                 * Create a POA with a short name, as the name will
                 * become part of every of its OID, which will be
                 * transmitted with every Corba call.
                 */
                poa = rootPoa.create_POA("Mnq$$", rootPoa.the_POAManager(), policies);

                poa.the_POAManager().activate();
            } catch (Exception e) {
                LoggerTool.logStackTrace(e, LOG);
            }
        }
    }

    public static org.omg.PortableServer.POA poa;

    private void doMore(File file, boolean recur) {

        File[] xmlFiles = file.listFiles();
        for (int i = 0; i < xmlFiles.length; i++) {
            if (xmlFiles[i].isDirectory()) {
                if (recur) {
                    doMore(xmlFiles[i], recur);
                }
                continue;
            }
            parseContent(xmlFiles[i].getAbsolutePath());

        }

    }

    public void parseContent(String in) {
        try {
            // System.out.println(in);
            String filename = in.substring(in.lastIndexOf(File.separator) + 1);
            if (!filename.endsWith(".idl"))
                return;

            FileInputStream fis = new FileInputStream(in);

            String str = "";
            while (fis.available() != 0) {
                byte[] bA = new byte[fis.available()];
                int numRead = fis.read(bA);
                if (numRead > 0) {
                    str += new String(bA, 0, numRead);
                }
                // continue
            }

            // close file
            fis.close();

            // The below coding is used for removing the comments in
            // the IDL file.
            // if (removeComment) {
            // Pattern pComment =
            // Pattern.compile("(//.*?$)|(/\\*.*?\\*/)",
            // Pattern.DOTALL
            // + Pattern.MULTILINE);
            // Matcher mGet = pComment.matcher(str);
            // str = mGet.replaceAll("");
            // }

            IdlFile fn = new IdlFile();
            fn.cName = in;
            fn.sName = filename;
            fn.content = str;
            fn.fn = fn;
            IdlRoot.sibling.add(fn);
            Warehouse.cname2node.put(fn.cName, fn);

            // recursive the content
            fn.recurContent();
        } catch (Exception e) {
            LoggerTool.logStackTrace(e, LOG);
        }
    }

}
/* EOF */

⌨️ 快捷键说明

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