bridgeexample.java

来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 69 行

JAVA
69
字号


package Jt.examples.patterns;

import Jt.JtBridge;
import Jt.JtFactory;
import Jt.JtMessage;
import Jt.JtObject;
import Jt.examples.HelloWorld;
import Jt.xml.JtXMLHelper;


/**
 * Example of the use of JtBridge.
 */

public class BridgeExample  {



  public BridgeExample () {
  }


  /**
   * Demonstrates the use of JtBridge. It encodes
   * an object using two XML implementations.
   */

  public static void main(String[] args) {

    JtFactory factory = new JtFactory ();
    JtBridge bridge;
    JtObject implementor;
    JtMessage msg;
    HelloWorld hello = new HelloWorld ();
    
    hello.setGreetingMessage("Hello World ...");

    // Create an instance of JtBridge

    bridge = (JtBridge) factory.createObject (JtBridge.JtCLASS_NAME, "bridge");

    // Specify the implementor to be executed.

    implementor = (JtObject) factory.createObject (JtXMLHelper.JtCLASS_NAME);
    bridge.setImplementor(implementor);

    // Encode the object using the XML implemetor selected
    
    msg = new JtMessage (JtObject.JtXML_ENCODE); 
    msg.setMsgContent(hello);
    System.out.println ("Java encoding:" +  factory.sendMessage (bridge, msg));
    
    // Use a different encoding implementation
    
    bridge.setImplementor(new JtObject ());
    
    System.out.println ("Jt encoding:" + factory.sendMessage (bridge, msg));
    
    factory.removeObject ("bridge");


  }

}


⌨️ 快捷键说明

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