pdf417 java Avoiding hardcoded XDoclet tag values in Java

Maker PDF 417 in Java Avoiding hardcoded XDoclet tag values

Avoiding hardcoded XDoclet tag values
Creating PDF417 In Java
Using Barcode creator for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Recognizing PDF417 In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Recipe
Linear Barcode Generation In Java
Using Barcode generation for Java Control to generate, create Linear 1D Barcode image in Java applications.
www.OnBarcode.com
Encode GS1-128 In Java
Using Barcode maker for Java Control to generate, create UCC.EAN - 128 image in Java applications.
www.OnBarcode.com
Use Ant properties in your XDoclet tags. Examine listing 2.12, which contains a subsection from a build.xml file. This subsection defines a property and the <ejbdoclet/> task.
Generate Barcode In Java
Using Barcode creation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
DataMatrix Encoder In Java
Using Barcode maker for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
www.OnBarcode.com
Listing 2.12 Sample Build.xml
GS1 - 13 Drawer In Java
Using Barcode printer for Java Control to generate, create EAN-13 Supplement 5 image in Java applications.
www.OnBarcode.com
Printing ITF In Java
Using Barcode printer for Java Control to generate, create ANSI/AIM ITF 25 image in Java applications.
www.OnBarcode.com
<property name="user.bean.jndi" value="ejb/session/UserBean"/>
PDF 417 Generator In Java
Using Barcode generation for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
PDF 417 Generator In None
Using Barcode maker for Microsoft Word Control to generate, create PDF-417 2d barcode image in Office Word applications.
www.OnBarcode.com
Creates an Ant property
Making PDF-417 2d Barcode In None
Using Barcode printer for Excel Control to generate, create PDF417 image in Office Excel applications.
www.OnBarcode.com
UPC-A Creation In C#.NET
Using Barcode encoder for .NET framework Control to generate, create UPC Code image in VS .NET applications.
www.OnBarcode.com
<target name="ejbdoclet" depends="init"> <taskdef name="ejbdoclet" classname="xdoclet.modules.ejb.EjbDocletTask"> <classpath> <fileset dir="${xdoclet.lib.dir}" includes="*.jar"/> </classpath> </taskdef> <ejbdoclet destdir="${src}" ejbspec="2.0" >
DataMatrix Generation In Java
Using Barcode drawer for Android Control to generate, create Data Matrix ECC200 image in Android applications.
www.OnBarcode.com
Barcode Scanner In Visual Basic .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
<fileset dir="${src}"> <include name="**/*Bean.java" /> </fileset> <remoteinterface pattern="{0}Remote"/> <homeinterface/> <localhomeinterface/> <homeinterface/> <entitypk/>
Code 3 Of 9 Creation In None
Using Barcode creation for Font Control to generate, create Code 3/9 image in Font applications.
www.OnBarcode.com
DataMatrix Reader In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Completes the remaining task
Generate QR In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create QR image in ASP.NET applications.
www.OnBarcode.com
Draw EAN / UCC - 13 In None
Using Barcode encoder for Software Control to generate, create GTIN - 13 image in Software applications.
www.OnBarcode.com
<deploymentdescriptor destdir="${build}/ejb/META-INF" /> </ejbdoclet> </target>
Generating UPCA In Objective-C
Using Barcode maker for iPhone Control to generate, create GTIN - 12 image in iPhone applications.
www.OnBarcode.com
Barcode Generator In C#.NET
Using Barcode generation for VS .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
Notice the property user.bean.jndi at the top of the file. Now examine the class declaration for the UserBean; it uses the Ant property in the JNDI attribute of the @ejb.bean tag:
/** * @ejb.bean type="Stateful" * view-type="both" * jndi-name="${user.bean.jndi}" * */ public class UserBean implements SessionBean{
Code generation with XDoclet
Discussion
When XDoclet attempts to generate the home interface for this bean, it will see that for the JNDI name it should use the value specified in the Ant property user.bean.jndi. Ant replaces the named property in the source file with the value contained in the build.xml file. Using this system, you can replace every hardcoded value in your source XDoclet JavaDoc tags with Ant property names. The advantage of this system is that it centralizes all of your property values into your build.xml file, and you no longer have to alter source code to change a value. XDoclet allows you to specify everything about a bean in its source file. Not everything is included in this chapter, but the list includes security roles, EJB relationships, method permission, transactions, and more. By moving all the values of these various elements into Ant properties in the build.xml file, you create a centralized control of the various values that can be changed at build time in a single file.
See also
2.1 Generating home, remote, local, and local home interfaces 2.2 Adding and customizing the JNDI name for the home interface 2.3 Keeping your EJB deployment descriptor current
2.7 Facilitating bean lookup with a utility object
Problem
You want to generate a utility object to help with looking up the home interface of an EJB.
Background
Two often-repeated tasks in an EJB application are the lookup of a bean s home interface and the subsequent creation of the bean. Developers sometimes handle these tasks by creating a static method that contains the lookup code for a particular bean. However, it is possible that this code also must change as a bean changes. The generated class will encapsulate all the code necessary for looking up the home interface of its parent EJB.
Facilitating bean lookup with a utility object
Recipe
To generate a utility object, use the @ejb.util tag in the class-level JavaDoc of your bean and modify your <ejbdoclet/> task to include the <utilityobject/> subtask. This works for both entity and session beans. For example, examine the class declaration of the UserBean:
package ch2; import javax.ejb.*; /** * @ejb.bean type="Stateful" * view-type="both" * * @ejb.util * */ public class UserBean implements SessionBean{
Listing 2.13 contains the build.xml used to generate the utility object.
Listing 2.13 Sample Build.xml
<target name="ejbdoclet" depends="init"> <taskdef name="ejbdoclet" classname="xdoclet.modules.ejb.EjbDocletTask" > <classpath> <fileset dir="${xdoclet.lib.dir}" includes="*.jar"/> </classpath> </taskdef> <ejbdoclet destdir="${src}" ejbspec="2.0" >
<fileset dir="${src}"> <include name="**/*Bean.java" /> </fileset> <utilobject cacheHomes="true" /> </ejbdoclet> </target>
b Adds the utility
object subtask
The <utilobject/> subtask tells XDoclet to search for source files containing the @ejb.util class-level JavaDoc tag and generate a utility object. Notice the subtask specifies an attribute cacheHomes equal to true. This attribute tells XDoclet to generate a utility object that caches the home object after the first lookup in order to improve performance. Listing 2.14 shows the generated utility class for this example (reformatted for this chapter).
Code generation with XDoclet
Listing 2.14 UserUtil.java, generated by XDoclet
/* * Generated by XDoclet - Do not edit! */ package ch2; import javax.rmi.PortableRemoteObject; import javax.naming.NamingException; import javax.naming.InitialContext; import java.util.Hashtable; /** * Utility class for ch2.User. */ public class UserUtil { /** Cached remote home (EJBHome). Uses lazy loading to obtain its value (loaded by getHome() methods). */ private static ch2.UserHome cachedRemoteHome = null; /** Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). */ private static ch2.UserLocalHome cachedLocalHome = null; // Home interface lookup methods /** * Obtain remote home interface from default initial context * @return Home interface for ch2.User. Lookup using COMP_NAME */ public static ch2.UserHome getHome() throws NamingException { if (cachedRemoteHome == null) { // Obtain initial context InitialContext initialContext = new InitialContext(); try { java.lang.Object objRef = initialContext.lookup(ch2.UserHome.COMP_NAME); cachedRemoteHome = (ch2.UserHome) PortableRemoteObject.narrow(objRef, ch2.UserHome.class); } finally { initialContext.close(); } } return cachedRemoteHome; } /** * Obtain remote home interface from parameterised initial context * @param environment Parameters to use for creating initial context * @return Home interface for ch2.User. Lookup using COMP_NAME
Copyright © OnBarcode.com . All rights reserved.