태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

package com.kame.struts2.architecture.valuestack;

import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;

public class ValueStackTest {
 public static void main(String[] args) {
  Person person = new Person();
  Animal animal = new Animal();
 
  ConfigurationManager configurationManager = new ConfigurationManager();
        configurationManager.addContainerProvider(new XWorkConfigurationProvider());
        Configuration config = configurationManager.getConfiguration();
        Container container = config.getContainer();

  // 스택을 만들어서 animal과 person을 push한다.
  ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();

  stack.push(animal);
  stack.push(person);

  stack.setValue("name", "Johnson"); // person.setName("Johnson");
  stack.setValue("salary", 5000000); // person.setSalary(5000000);
  stack.setValue("species", "pug"); // animal.setSpecies("pug");

  System.out.println(person);
  System.out.println(animal);

  System.out.println(stack.findValue("name")); // person.getName();
  System.out.println(stack.findValue("species")); // animal.getSpecies();
  System.out.println(stack.findValue("salary")); // person.getSalary();
 }
}

top

Trackback Address :: http://www.ssial.com/trackback/259 관련글 쓰기

Write a comment


◀ PREV : [1] : ... [48] : [49] : [50] : [51] : [52] : [53] : [54] : [55] : [56] : ... [209] : NEXT ▶