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

📄 jtprototype.java

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


package Jt;

/**
 * Jt Implementation of the Prototype design pattern.
 */

public class JtPrototype extends JtObject {

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


  public JtPrototype () {
  }



  private Object test () {

    JtObject tmp;


    tmp = (JtObject) processMessage (new JtMessage (JtObject.JtCLONE));

    if (tmp == null)
      return (null);

    return (tmp.processMessage (new JtMessage (JtObject.JtPRINT)));
  }

  /**
    * Process object messages.
    * <ul>
    * <li>JtCLONE - returns a clone of this object. The behavior is inherited from JtObject.
    * </ul>
    */

  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 ());     
     }


     if (msgid.equals (JtObject.JtREMOVE)) {
       return (null);     
     }

     return (super.processMessage(event));

  }

 
  /**
   * Demonstrates the messages processed by JtPrototype
   */

  public static void main(String[] args) {

    JtFactory factory = new JtFactory ();
    JtComposite aux;
    JtPrototype tree, branch;
    Double leaf1 = new Double (1.0);
    Double leaf2 = new Double (2.0);
    Double leaf3 = new Double (3.0); 
    JtMessage msg;
    
    // Create an instance of JtPrototype

    tree = (JtPrototype) factory.createObject (JtComposite.JtCLASS_NAME, "tree");    
    
    // Add objects to the tree
        
    msg = new JtMessage (JtComposite.JtADD_CHILD);
    msg.setMsgContent(leaf1); 
    
    factory.sendMessage(tree, msg);   
    msg.setMsgContent(leaf2);
    factory.sendMessage(tree, msg);
        
    branch = (JtComposite) factory.createObject (JtComposite.JtCLASS_NAME, "branch");    
    msg.setMsgContent(leaf3);

    factory.sendMessage(branch, msg);
    
    msg = new JtMessage (JtComposite.JtADD_CHILD);
    msg.setMsgContent(branch);
    factory.sendMessage(tree, msg);
    

    // Clone the object. In this case the tree is cloned
    
    aux = (JtComposite) factory.sendMessage(tree, new JtMessage (JtObject.JtCLONE));
    
    // Print the new tree (using XML)
    
    factory.sendMessage(aux, new JtMessage (JtComposite.JtPRINT));

    //factory.sendMessage (proto, new JtMessage ("JtTEST"));

    // Remove the object

    factory.removeObject (tree);


  }

}


⌨️ 快捷键说明

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