XDoclet: EJB development good helper

zhaozj2021-02-16  140

XDoclet: EJB development good helper

2002-06-06 14:22:56

Using XDoclet, you can work more efficiently in the J2EE environment. The relationship between Bean and Bean will be more simple, many complicated things will be away from your EJB development process. This article discusses how to use and extend the xDoclet. In this article, we will create a session bean that uses Javadoc tags and then uses xdoclet to process this bean. First, what is the development of the EJBDoclet tool created from Rickard Oberg, which is easy to think: avoid providing multiple files for each EJB, but all information needed from the single bean class file. So how is this realized? Java is not .NET boasted "attribute", but Java has a JavaDoc tag. We can put a special @ tag into the Javadoc comment and let a Doclet tool handle these tags. The appropriate XML descriptor file and interface file are generated by the tool for the specified bean. XDoclets are based on EJBDoclet ideas, but the scope of application is no longer limited to EJB. Now, we can use XDoclet to generate web services, web application descriptor, and even expand it to meet your own special needs. @ Mark has a standard format, contains a "namespace" and a "tag name" belonging to this name space. The marked properties are specified in the mark in the form of "name = value". Here is an example: / ** * @namespace: tag name = "value" name2 = "value2" ... * / Currently available namespace includes: EJB standard EJB information (non-vendor private information) JBOSS face JBoss Application server information. WebLogic information for the BEA WebLogic application server. WebSphere provides information for IBM WebSphere Application Servers. Orion is an ORION Application Server (Oracle). Castor generates mapping information for the Castor framework. MVCSoft generates files for the MVCSoft EJB 2.0 persistent manager. SOAP generates a SOAP descriptor. Struts generate struts-config.xml. Web generates a web.xml configuration file for a web application. JSP generates tag library extension descriptor information. As can be seen from the list, in addition to EJB, XDoclet also provides many other support (so its name is also XDCOLET from EJBDoclet). Second, use the Javadoc tag labeling session bean before we discussed the basic situation of the xdoclet tool, look at an instance below. We started from a session EJB. This EJB is part of the XBeans framework, but for this article, what kind of features of Beans have no critical. We care about how to use the Javadoc tag for proper labeling on the basis of the Bean class, then use the xdoclet to generate various files we need. The ReceiverBean.java file contains a DocumentReady (Document Doc) method, which receives a DOM document and passes it to the next Xbean on the chain. 2.1 Definitions at the class at the level at this level, we must define: Declare the type of beans, this example is a stateless session bean. JNDI name. Environment variable. For vendor's information (such as WebLogic buffer pool information). 2.1.1 @EJB: Bean Mark This Mark This Mark This Mark is to tell XDoclet with the name of the BEAN.

In addition, we will also define the type of bean, JNDi name and display name (Display-name): / ** * this is the ejb receiver xbean * * @EJB: bean type = "stateless" * name = "ejbreceiver" * JNDI-Name = "org.xbeans.ejb.receiver.receiver" * Display-name = "EJB Receiver Xbean" * * ... Other Javadoc tags ... * / public class receiverbean imports sessionbean, domsource {EJB: bean tag The most common attribute is: Name EJB's name (for the descriptor). Type defines the type of bean. For session beans, the type of bean is stateful or stateless; for entity beans, it is CMP or BMP. JNDI-NAME provides a BEAN's JNDI name that will be used for vendor's private deployment descriptor (for remote interface). Local-jndi-name is the same as JNDI-NAME, but used for local interfaces. View-Type indicates which "view" should be supported. Can be Remote or Local, or Both. To see a full description of all tags, visit the xdoclet's documentation. 2.1.2 @ejb: Env-entry tag This tag defines environment variables that will be configured in JAVA: Comp / ENV context in JNDI. Below we will define an environment variable, bean uses it to find the next Xbean: / ** * this is the ejb receiver xbean * * ... Other Javadoc tags ... * * @EJB: env-entry name = "ChannelBean" type = "java.lang.string" * value = "com.your.channelbean" * * ... Other Javadoc tags ... * / public class receiverbean imports sessionbean, domsource {2.1.3 @Weblogic: Pool Marks Let's configure buffer pool features facing specific vendors, we will use WebLogic for easy discussion. To indicate that the statement is only valid for a particular manufacturer, we first declare the WebLogic namespace: / ** * this is the ejb receiver xbean * * ... Other Javadoc tags ... * * @Weblogic: pool max-beans-in-free -pool = "1000" initial-beans-in-free-pool = "10" * * ... Other Javadoc tags ... * / public class receiverbean imports sessionbean, domsource {This tag will be deployed for WebLogic deployment description Configure the buffer pool parameters in WebLogic-EJB-JAR.XML. There are many other tags of this level, which makes we adjust any options that can be specified in the deployment descriptor. The following summary introduces some "standard" tags that may be used during deployment procedures: @ejb: bean: The only required tag configures basic information about Beans.

@ejb: Home: Provides information about the HOME interface. You can ask XDoclet to extend a custom interface or put the interface into the specified package, and so on. @Ejb: interface: Similar to the Home tag, but is used to configure information related to the component interface (remote and / or local). @Ejb: finder: Define the Finder method on the entity bean home interface. @EJB: SELECT: Define the Select method on the entity Bean Home interface. @EJB: PK: Defines the primary key for entity beans. XDoclets can generate primary key classes. @Ejb: data-object: Data object (that is, value object) can be automatically generated by this tag. @Ejb: EJB-REF: Configure EJB references. @EJB: EJB-External-Ref: Configure reference to EJB in other applications, here you must specify the type of bean. @EJB: Resource-Ref: Configure resource references. @Ejb: security-role-ref: Configure a secure role reference. @Ejb: Transaction: Defines transaction properties for all methods in the current bean's Home interface and Remote interface. It can be covered by transaction markers provided for a single method. @Ejb: permission: Allows the roles specified in Role-name call all methods of this bean's Home interface and Remote interface. @EJB: Security-Identity: Specifies whether to perform EJB by the caller's security identifier or use another specific security identifier. 2.2 Definitions at this level below Let's take a look at the method level markers. To make a method a part of the remote interface, we only need to tell xdoclet: / ** * the method "@ejb: interface-method view-type =" Remote "* / public void DocumentReady (Document IncomingDocument) {This tag is often used. In general, we check each method in the bean class in turn, if a method should make the client to call, then add this tag in front of the method declared. If you want the client to access this method through the local interface, simply change the view-type value to local. Below is a few other commonly used EJB method-level tags: @ejb: rate: Define a relationship for EJB 2.0 CMP entity beans. @Ejb: Home-method: Define the method as an EJBHOME * method. @EJB: PK-Field: Labeled the main key domain. @Ejb: Transaction: Defines transaction behavior for current methods (specifying a legitimate transaction property: NotSupported, Supports, Required, RequiresNew, Mandatory, or Never). @Ejb: permission: Defines the permission permission to the method (give a list that allows access to the role of the method, separated by comma). Third, run xdoclet Now we have completed the work of adding the xdoclet tag for ReceiverBean.java. Below we are going to run xDoclets, let it generate files needed when you deploy beans. The best way to run the xdoclet tool is to perform through Jakarta-Ant.

Ant is a wide application Java construction system, now almost everyone is using it. See the Jakarta website for a detailed description of Ant. The XDoclet author writes a Ant task that can be placed directly into the ANT.xml. The task is mainly divided into two categories: EJBDoclet and WebDoclet. Since we are processing a EJB, let's take a closer look at the EJBDoclet section in the build file: This file is large Information, so we have to break it, discuss it by. 3.1 Tag first, we want to tell the ANT constructor information about the tag. We define the name of the tag, specify the class that implements the tag, and the ClassPath available. Here, we use the attributes that point to each library file in front of the build.xml file: 3.2 Tags the outermost tag tells Ant to run the EJBDoclet task.

We specify the location of the code in the tag, where to generate an XML descriptor, and our EJB specification version (same, the previously defined properties): 3.3 tag instruction tells Where to find the bean code. This example will look for ReceiverBean.java: 3.5 Marking the vendor: Interface and XML Deployment Descriptor Last set of markers to generate a vendor's deployment descriptor. If you only deploy EJB on one server, we only need to set it. But here we assume that the Xbean EJB can be deployed on the application server as possible, so join all the manufacturers' tags. It is a wonderful thing that can be generated without understanding the specific details of these application servers. now, to generate various files for Xbean EJB, we only need to execute Ant on the directory where the build file is located. When running Ant, you must ensure that Ant's library files (Ant.jar, Jaxp.jar, and XML parsers) and xdoclet.jar files are in classpath. For example, assume that in a Windows environment:% set classpath =% classpath%; c: /lib/ant.jar; c: /lib/jaxp.jar; c: /lib/xerces.jar; c: / lib / xdoclet. Jar; c; /lib/log4j.jar; c: /lib/ejb.jar% ANT EJBDoclet See the complete build.xml file in this article download code. Fourth, XDoclet's scalability xDoclet has good scalability.

转载请注明原文地址:https://www.9cbs.com/read-9062.html

New Post(0)