Menu

minbox source Demo

//A Java Bean
public class Man {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

A:call directly container

//invocation code with container
import org.jmin.ioc.BeanContainer;
import org.jmin.ioc.BeanElementFactory;
import org.jmin.ioc.BeanParameter;
import org.jmin.ioc.BeanParameterFactory;
import org.jmin.ioc.element.InjectionProperty;
import org.jmin.ioc.impl.BeanContainerImpl;

public class PropertyCase{
public static void test()throws Throwable{
BeanContainer container = new BeanContainerImpl();
BeanElementFactory beanElementFactory =container.getBeanElementFactory();
BeanParameterFactory beanParameterFactory =container.getBeanParameterFactory();
BeanParameter nameParmeter = beanParameterFactory.createStringParameter("Chris");
BeanParameter ageParmeter = beanParameterFactory.createIntegerParameter(28);

InjectionProperty nameProperty = beanElementFactory.createInjectionProperty("name",nameParmeter);
InjectionProperty ageProperty = beanElementFactory.createInjectionProperty("age",ageParmeter);
container.registerClass("Bean1", Man.class, new InjectionProperty[] {nameProperty, ageProperty});
Man man = (Man)container.getBean("Bean1");
if(man!=null){
if("Chris".equals(man.getName()) && (28== man.getAge())){
System.out.println("[Container].........Porperty injection ok..........");
}else{
throw new Error("[Container]...........Porperty injection failed............");
}
}
}

public static void main(String[] args)throws Throwable{
test();
}
}

B:xml configeruation

<beans>
<bean id="user-content-Bean1" class="">
<property name="name" value="Chris">
<property name="age" value="28">
</property></property></bean>
</beans>

//invocation code with xml context
import org.jmin.ioc.impl.config.BeanContext;
import org.jmin.test.TestCase;
public class PropertyXMLCase{
public static void test()throws Throwable{
BeanContext context=new BeanContext("pojo.xml");
Man man = (Man)context.getBean("Bean1");
if(man!=null){
if("Chris".equals(man.getName()) && (28== man.getAge())){
System.out.println("[XML].........Porperty injection ok..........");
}else{
throw new Error("[XML]...........Porperty injection failed............");
}
}
}

public static void main(String[] args)throws Throwable{
test();
}
}

More source Download
http://dl.vmall.com/c0u7lix55w

Posted by JavaTear 2013-04-16

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.