Menu

minbox Introduction

1:Introduction
minbox is a java micro-container,which can manage bean definition and supply bean instance for outside caller,then the developers needn't create ojbect instance with 'new' keyword. The container is very easy to study,and fast development in java application.

2:Feature list
1:bean destory and initialization
2:bean singleton instance or multi instance
3:constructer injection
4:property injection
5:invocation injection
6:factory bean creation
7:AOP interception(sub wrapper and proxy)
8:type converter for injection parameter
9:parameter type:java primitive type and java container type
10:xml configuration

3:Bean definition element
Before creation,bean definition must be existed in container.Some ojbects are used to define bean part definition and work as instuction to container,we call them as elments.Some elements are listed below

1:InstanceCreation
2:InstanceSingleton
3:InitializeMethodName
4:DestroyMethodName
5:InjectionProperty
6:InjectionInvocation
7:InvocationInterception
8:ParentReferenceId

4:Bean Injection parameter
Afer bean instance created,container will inject parameters into them.There are four kind of ioc paramter types,contaienr will convert them to real value before injection.

1:Primitive type
2:Instance type
3:Refrence type
4:Container type

5:How to get Instance
1: call directly container
2: use xml context

6:Demo show
//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("org/jmin/test/ioc/property/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();
}
}

7: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.