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

📄 jtbusinessdelegate.java

📁 Java Pattern Oriented Framework (Jt) 是为了实现Java快速开发的面向模式的框架。
💻 JAVA
字号:

package Jt.ejb;


//import javax.ejb.*;
//import javax.naming.*;
//import java.rmi.*;


import Jt.*;
import Jt.examples.HelloWorld;


/**
 * Jt implementation of the J2EE Business Delegate pattern. 
 */ 

public class JtBusinessDelegate extends JtEJBAdapter  {

    public static final String JtCLASS_NAME = JtBusinessDelegate.class.getName(); 
    private static final long serialVersionUID = 1L;


    public JtBusinessDelegate () {
    }



    /**
     * Process object messages.
     * <ul>
     * <li> JtTEST - Tests the messages processes by JtBusinessDelegate
     * </ul>
     * @param event message
     */

    public Object processMessage (Object event) {

        String msgid = null;
        JtMessage e = (JtMessage) event;

        if (e == null)
            return null;

        msgid = (String) e.getMsgId ();

        if (msgid == null)
            return null;


        if (msgid.equals (JtObject.JtTEST)) {            
            return (test ());
        }

        // Let the superclass (JtEJBAdapter) do most of the work (handle the
        // EJB related functionality

        return (super.processMessage (event));

    }

    private Object test () {
    JtObject factory = new JtFactory ();
    JtEJBAdapter adapter;
    String reply = null, tmp;
    Exception ex;
    JtMessage msg;
    JtProxy proxy;

    //main.setLogFile ("log.txt");
    // Create the Jt EJB Adapter

    adapter = (JtEJBAdapter) factory.createObject (JtEJBAdapter.JtCLASS_NAME);
    

    // Create a remote instance of the HelloWorld class. JtBusinessDelegate
    // can be used to create remote objects. A local proxy is returned.

    msg = new JtMessage (JtEJBAdapter.JtCREATE_PROXY);
    msg.setMsgContent(HelloWorld.JtCLASS_NAME);
  
    //msg.setMsgData("helloWorld");

    proxy = (JtProxy) factory.sendMessage (adapter, msg);
    factory.setValue (proxy, "logLevel", "0");
    factory.setValue (proxy, "logging", "true");
    
    //msg.setMsgContent("Jt.examples.Member");   
    //JtProxy proxy1 = (JtProxy) factory.sendMessage (adapter, msg);

    factory.setValue (proxy, "greetingMessage", "Hello there...");

    tmp = (String) factory.getValue (proxy, "greetingMessage");

    System.out.println ("greetingMessage:" + tmp);

    msg = new JtMessage (HelloWorld.JtHELLO);

    // Send JtHello to the remote helloWorld object

    reply = (String) factory.sendMessage (proxy, msg);    


    ex = (Exception) proxy.getObjException();


    // Display the reply unless an exception is detected

    if (ex == null)    
        System.out.println (reply);

    // Remove the EJB adapter and the proxy

    factory.removeObject (proxy);
    factory.removeObject (adapter);
    return (reply);
    }
   
    
    /**
     * Demonstrates all the messages processed by JtBusinessDelegate. 
     */

    public static void main(String[] args) {

        JtObject main = new JtObject ();
        JtBusinessDelegate businessDelegate;
        //String str;
        String reply = null;
        //Exception ex;

        //main.setObjTrace (1);
        //main.setLogFile ("log.txt");


        // Create the Jt businessDelegate

        businessDelegate = (JtBusinessDelegate) main.createObject (JtBusinessDelegate.JtCLASS_NAME, 
        "businessDelegate");


        // send a test message (JtTEST) to the delegate


        reply = (String) main.sendMessage (businessDelegate, new JtMessage (JtObject.JtTEST));


        // ex = (Exception) main.getValue (businessDelegate, "objException");    


        // Display the reply unless an exception is detected

        System.out.println (reply);


        // Remove the business delegate

        main.removeObject (businessDelegate);

    }

}


⌨️ 快捷键说明

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