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

📄 planetupdatecommandprocessor.java

📁 Ajax开发精要 Ajax开发精要 Ajax开发精要
💻 JAVA
字号:
package com.manning.ajaxinaction.planets;

import java.beans.Statement;

import org.jdom.Element;

import com.manning.ajaxinaction.command.XMLCommandProcessor;

/**
 * @author crane
 */
public class PlanetUpdateCommandProcessor implements XMLCommandProcessor {

  public PlanetUpdateCommandProcessor() {
    super();
  }

  public Element processXML(Element el) {
    Element result=new Element("command");
    String id=el.getAttributeValue("id");
    result.setAttribute("id",id);
    String status=null;
    String reason=null;
    String planetId=el.getAttributeValue("planetId");
    String field=el.getAttributeValue("field");
    String value=el.getAttributeValue("value");
    Planet planet=findPlanet(planetId);
    if (planet==null){
      status="failed";
      reason="no planet found for id "+planetId;
    }else{
      Double numValue=new Double(value);
      Object[] args=new Object[]{ numValue };
      String method="set"+field.substring(0,1).toUpperCase()+field.substring(1);
      Statement statement=new Statement(planet,method,args);
      try {
      statement.execute();
      status="ok";
      } catch (Exception e) {
      status="failed";
        reason="unable to set value "+value+" for field "+field;
      }
    }
    result.setAttribute("status",status);
    if (reason!=null){
      result.setAttribute("reason",reason);
    }
    return result;
  }

  /**
   * @param planetId
   * @return
   */
  private Planet findPlanet(String planetId) {
    // TODO use hibernate
    return null;
  }

}

⌨️ 快捷键说明

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