Refactoring Enterprise Beans


Software applications evolve over time and require updates, bug fixes, feature enhancements, and so on. To support this type of development activity, NetBeans IDE refactoring features extend to Java enterprise applications.

Enterprise beans are among the types of code most likely to need refactoring during an enterprise software application's lifetime. However, refactoring enterprise beans can be very time consuming as a result of the complexity of changes that may be involved with the refactoring, due to the number of classes and deployment descriptors that may be affected by a refactoring.

For example, a business method rename may require changes not only in the EJB class you are editing, but also in a local interface, remote interface, calling classes (such as a servlet class or a remote client class), and deployment descriptors. NetBeans IDE simplifies this task by applying the refactoring changes to the Java source code, and by making those more difficult changes in deployment descriptors.

Following are some of the things you can do when refactoring your enterprise project source code.

  • Rename an enterprise bean

  • Rename a field or method of an enterprise bean

  • Change method parameters (including parameter names, parameter types, and method visibility), add method parameters, and remove method parameters

  • Encapsulate fields by changing their visibility, adding getter and setter accessors, and determining whether to use accessors even when the field is accessible

NetBeans IDE allows you to review your refactoring changes before applying them. Likewise, you can undo your refactoring changes after having applied them, including any changes that have been made to deployment descriptors.

If you want to undo a refactoring operation, you must call the Undo command from a Java source file. Although Undo affects deployment descriptors, the command cannot be called from a deployment descriptor.


For complete descriptions of the IDE's refactoring features, see Chapter 5. For notes on servlet refactoring, see Chapter 8. Following are some notes regarding the refactoring operations that are specific to Java enterprise applications:

  • For CMP beans, the method rename of a selector or finder automatically updates the EJBQL (Enterprise JavaBeans Query Language) statements and query element in the deployment descriptor. However, the IDE does not allow you to change the method name of a mandatory EJB method such as ejbCreate().

    Even in the case where a renamed method was previously overloaded, a new deployment descriptor entry is made for the refactored method name. For instance, updates to deployment descriptors tagged as primary key fields and composite primary key fields as a result of method rename refactoring are supported. Also, a rename of web service endpoint interfaces are handled by NetBeans IDE by updating the appropriate WSDL.

  • Even in the case of a CMP bean, a field rename refactoring of a primary key results in field accessors deployment descriptors being updated. In addition, if a relationship field is renamed, the cmr-field in the deployment descriptor is updated.

  • Encapsulate fields refactoring in an enterprise bean class works the same way as in standard classes, with the exception of primary keys in CMP enterprise beans, which cannot be refactored in NetBeans IDE.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net