第一部分翻譯

jegg發表於2007-01-24
Configuration quick guide



With a few lines of configuration, JDon Framework can be easly entegrated into your application. Here is an example:



TestService testService = (TestService) WebAppUtil.getService("testService ", request);



In this article, I am going to show you how to get job done within jdonframework.xml for class testService.



We called the class invoked by client (Servlet/Jsp/Action) as service class. There are two types of service class. One is common java class or JavaBeans, all of which called POJO. The other is EJB-regulation-complied classes which could be simply called EJB. Any of these two type class could be used as service class, hence there will be two corresponding service configurations for POJO and EJB done by proService and jbService respectively.



Common service class configuration

There are two basic properties in pojoService, name and class. Property class is for putting POJO’s full name. Property Name is used to put the actual service name invoked in the program, conventionally written as similarly to the class name. Please see the source code in JdonFrameworkEJB or Ioc under Traning directory.

<!—common java class configuration also called POJO à

<pojoService name="testService" class="com.jdon.framework.test.service.TestServicePOJOImp"/>


Common class configuration

Not all of classes are servered for the client directly (jsp/Servlet), that is to say some classes are not invoked by jsp/servlet or presentation frame layer, but invoked by service classes, these kinds of class we called component class annotated as component in configuration file. Note: in EJB framework, component class is managed by EJB container, so you do not need to any configuration in JdonFramework any more.

Here is a common example.



<!—jdbcDAO is invoked by TestServiceImp and serving for it, -->

<component class="com.jdon.framework.test.dao.JdbcDAO" name="jdbcDAO"/>



We often need to define some constants and parameters in some classes, so we can do like this:

<component class="com.jdon.framework.test.dao.JdbcDAO" name="jdbcDAO">

<constructor value="java:/TestDS"/>

</ component >

As you can see, JdbcDao’s constructor has a string parameter. When you initialize an instance of JdbcDao, String “java:/TestDs” will be passed into constructor automatically.



By taking advantage of good point above, we can conveniently utilize xml file to define business logic. For example, we can defined the email format in jdonframework.xml so that email content could be altered easily according the customers’ needs. It is much better and flexible than get this information hard coded in the program.



Here is an example:

<component name="emailDefine"

class="com.jdon.jivejdon.service.imp.account.EmailDefine">

<constructor value="Jdon:username and password"/>

<constructor value="hello:your username and password for jdon.com is listed as follows:"/>

<constructor value="Jdon.com --- clarify your confusions and answer your questions"/>

<constructor value="Jdon.com"/>

<constructor value="admin@jdon.com"/>

</component>










相關文章