System and method for generating Enterprise Java Bean code

Information

  • Patent Application
  • 20040111701
  • Publication Number
    20040111701
  • Date Filed
    December 05, 2002
    23 years ago
  • Date Published
    June 10, 2004
    21 years ago
Abstract
A system and method for generating code for an Enterprise Java Bean comprising generating at least one output based on a description of at least one Enterprise Java Bean, wherein the description is attended by at least one annotation. A system and method for generating an annotated description of an Enterprise Java Bean based on at least one input, wherein the description can be used to generate the at least one input.
Description


CROSS REFERENCES

[0001] The following related documents are hereby incorporated by reference in their entirety: BEAWEBLOGIC SERVER®: ASSEMBLING AND CONFIGURING WEB APPLICATIONS (Release 7.0, Jun. 28, 2002); BEAWEBLOGIC SERVER®: PROGRAMMING WEBLOGIC ENTERPRISE JAVABEANS (Release 7.0, Jun. 28, 2002); BEAWEBLOGIC SERVER®: DEVELOPING WEBLOGIC SERVER APPLICATIONS (Release 7.0, Jun. 28, 2002); BEAWEBLOGIC SERVER®: WEBLOGIC BUILDER ONLINE HELP (Release 7.0, Jun. 28, 2002); BEAWEBLOGIC SERVER®: PROGRAMMING WEBLOGIC XML (Release 7.0, Jun. 28, 2002); BEAWEBLOGIC SERVER®: PROGRAMMING WEBLOGIC WEB SERVICES (Release 7.0, Jun. 28, 2002); BEAWebLogic Server®: Programming WebLogic Enterprise JavaBeans (Release 7.0, Jun. 28, 2002).



COPYRIGHT NOTICE

[0002] A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.



FIELD OF THE DISCLOSURE

[0003] The present invention disclosure relates to the field of automatic code generation, in particular, automatic generation of Enterprise Java™ Bean source code files from an annotated class definition and the reverse.



BACKGROUND

[0004] Enterprise Java™ Beans are reusable software components written in the Java™ programming language. An Enterprise Java™ Bean (EJB) is typically declared in a number of separate source files which define various aspects of the EJB, such as its class, interfaces and deployment behavior. Each time a modification is made to one EJB source file, the other associated EJB source files must also be modified accordingly. This activity is cumbersome and error prone, since the changes must be manually propagated to different files. What is needed is a way to generate source files for EJB's with minimal editing and duplication of information.







BRIEF DESCRIPTION OF THE DRAWINGS

[0005]
FIG. 1 is a block diagram of an EJB code generation system in accordance to one embodiment of the invention.


[0006]
FIG. 2 is a block diagram of a reverse EJB code generation system in accordance to one embodiment of the invention.







DETAILED DESCRIPTION

[0007] The invention is illustrated by way of example and not by way of limitation in the figures of the accompanying drawings in which like references indicate similar elements. It should be noted that references to “an” or “one” embodiment in this disclosure are not necessarily to the same embodiment, and such references mean at least one.


[0008] In one embodiment, instead of having to edit and maintain several EJB files for each EJB (e.g., the bean class, remote and home classes, deployment descriptors, etc.), editing is limited to a single file that contains an annotated description of one or more EJB class definitions. EJB's are declared in the Java™ programming language. The Java™ programming language and run-time environment are available from Sun Microsystems, Inc., of Palo Alto, Calif. The annotated description file is processed in accordance to one embodiment and the EJB files required for deployment on a server are automatically generated. Annotations are directives that contain information needed to create an EJB's source files. In one embodiment, annotations are interspersed between Java™ source code statements. In another embodiment, annotations are embedded in Java™ comments. In yet another embodiment, an annotation is a Javadoc tag. Javadoc is the tool for generating source code documentation in hypertext markup language (“HTML”) format from tags embedded in Java™ source code comments. Javadoc is available from Sun Microsystems, Inc. In another embodiment, annotations are provided separately from the description of one or more EJB classes. For example, annotations can be provided in a graphical user interface, a separate file, or created dynamically based on run-time properties a user has associated with an EJB.


[0009] In one embodiment, by way of example, annotations can take the form: @ejbgen-name [attribute[=expression]] . . . attribute[=expression]], where items in square brackets are optional arguments. Name can be the type of annotation and the optional attribute=expression list can be comprised of one or more attribute-expression pairs. In one embodiment, attribute is the name of a required or optional parameter associated with an annotation and the optional expression can be, for example, an infix, postfix or prefix expression that evaluates to a constant (e.g., a number or an alpha-numeric string). In another embodiment, an expression's operators can be arithmetic, logical and string-based. For example, the following Java™ code segment has a comment block that contains three annotations:
1/** * @ejbgen:cmp-field column = acct_id * @ejbgen:primkey-field * @ejbgen:remote-method transaction-attribute = Required */abstract public String getAccountId( );


[0010] Conventionally, an EJB's abstract accessor methods define container-managed persistence (“CMP”) data fields of the same name. For example, in the code segment above, assuming the accessor method getAccountId( ) was an EJB method, a corresponding data field called “accountId” would be defined upon deployment of the EJB. In one embodiment, the annotation “@ejbgen:cmp-field” specifies that the Accountld CMP field will be stored in column named “acct_id” of a database upon deployment of the EJB. The annotation “@ejbgen:primkey-field” indicates that Accountld will be a primary key in the database. Finally, the annotation “@ejbgen:remote-method” specifies that transaction isolation is required for the method getAccountId( ). All three annotations can be considered method annotations since they come before the declaration of a method.


[0011]
FIG. 1 is a block diagram in accordance to one embodiment of the invention. An annotated description 1 is processed by analyzer 2. Annotated description 1 can include one or more EJB definitions. In one embodiment, annotated description 1 can reside in a computer file. In another embodiment, annotated description 1 can reside in a computer memory. In yet a further embodiment, annotated description 1 can be transmitted via a computer network (not shown) to analyzer 2. Analyzer 2 employs parser 4 to divide the Java™ source text in annotated description 1 into discrete units and extract annotations therefrom. Analyzer 2 may perform preprocessing of annotated description 1 before making use of parser 4. In one embodiment, parser 4 can exploit the doclet application programming interface available in Javadoc. The Javadoc doclet interface provides programmatic access to a parsed representation of a Java™ source file. In one embodiment, parser 4 can process the entire annotated description 1 at once. In another embodiment, parser 4 can be employed repeatedly by analyzer 2 to incrementally process annotated description 1. Each annotation is verified by comparing what was found in the annotated description 1 with a formal definition in annotation library 5. In one embodiment, by way of example, annotation library 5 can be a database that includes the definition of each annotation (e.g., its required and optional parameters, permissible values, etc.). In another embodiment, annotation library 5 can be implemented as a cache, tree or any other suitable data structure without departing from the spirit or scope of the present disclosure.


[0012] If the annotation and its arguments are proper, analyzer 2 evaluates any attribute-expression arguments provided. The can be done during the validation of each annotation, or in another embodiment, after all annotations have been verified. Values for variable names that occur in expressions are retrieved from variable library 6. In one embodiment, variable library 6 can be implemented in a similar fashion to annotation library 5. In a further embodiment, variable names can be constructed dynamically from expressions using string concatenation operators. In one embodiment, each attribute-expression is evaluated, comparing the value of the expression to permissible values allowed for a given attribute as dictated by annotation library 5. If an expression's value is out of range or erroneous, an error can be declared. In another embodiment, a suitable default value can be provided in place of the errant expression. The form of expressions can be, for example, infix, postfix and prefix. Means for parsing and evaluating such expressions are well known in the art. Based on the parsed annotations, code generator 3 emits the classes or files 7 necessary to deploy the EJB(s) described in annotated description 1.


[0013] In one embodiment, annotations can be described in terms of their attributes, their scope (e.g., class or method) and the type of EJB they are applicable to (e.g., message, stateless session, stateful session, entity, etc.). Annotations having class scope come before a class declaration and annotations having method scope come before a method declaration. Annotations can also be adjacent to or associated with other Java™ elements such as fields or variables. In a further embodiment, and by way of illustration, annotations can be defined as in the following tables. The Annotation/Attribute column contains the annotation name in the first row of each table and any associated attribute names in the subsequent rows. The Description column contains a description of the annotation or attribute. The For column indicates whether the annotation is applicable to a class or a method. Finally, the EJB Type column indicates the type of EJB the annotation is applicable to (e.g., session, message, entity, etc.). It will be apparent to those skilled in the art that many such annotations are possible and therefore this illustration is illustrative and should not be construed to be limiting in any respect.
2EJBAnnotation/AttributeDescriptionForType@ejbgen:automatic-key-Automatically generate database keys for newClassEntitygenerationentity objects.cache-sizeThe size of the key cache. (Required)NameThe name of the key generator. (Required)TypeThe type of the key generator. (Required)@ejbgen:cmp-fieldSpecifies a container-managed field.MethodEntityColumnThe column where this CMP field will be mapped.(Required)column-type(OracleClob|OracleBlob) The type of this column.group-namesThe names of the groups this field belongs to,separated by commas.ordering-number(0..n) The number where this field mustappear in signatures and constructors. For thisordering to work, all CMR and CMP fields musthave this attribute to a distinct numeric value.@ejbgen:cmr-fieldSpecifies a container-managed relationship.MethodEntitygroup-namesThe names of the groups this field belongs toseparated by commas.ordering-number(0..n) The number where this field mustappear in signatures and constructors. For thisordering to work, all CMR and CMP fields musthave this attribute to a distinct numeric value.@ejbgen:create-default-Automatically create required database tables.ClassEntityrdbms-tables@ejbgen:ejb-client-jarSpecify the name of the jar file to generate.ClassAllfile-nameThe name of the client jar to generate. If more thanone EJB's have this tag, only one of the specifiedjar files will be included in the deploymentdescriptor. (Required)@ejbgen:ejb-local-refDeclare a reference to an EJB that is in the sameClassAllcontainer and EJB JAR file.HomeLogal class of the bean.jndi-nameThe JNDI name of the reference.LinkLink of the bean.LocalHome class of the bean.NameName of the reference.Type(Entity|Session)@ejbgen:ejb-refDefine a reference to another EJB within theClassAllJava ™ Naming and Directory Interface (“JNDI”)Environment Naming Context (“ENC”).HomeHome class of the bean.jndi-nameThe JNDI name of the reference.LinkLink of the bean.NameName of the reference.RemoteRemote class of the bean.Type(Entity|Session)@ejbgen:entityDeclare an entity bean.ClassEntityejb-nameThe name of this Entity bean. (Required)prim-key-classThe Java ™ class of the primary key. In case of acompound primary key, this class will begenerated. (Required)Sometimes, a simple (e.g. java.lang.String)primary key class will not be enough to identify anEJB uniquely. In such a case, a primary key isneeded. A primary key is a custom Java classcontaining several fields. All of the fields togetheridentify an EJB uniquely.There are certain constraints associated with thecompound primary key class (e.g it must beSerializable, implement hashCode( ), equals( ), etc.).A compound primary key class can contain fieldsthat form a subset of the CMP fields of the EJB. Inorder to define a compound primary key class:Annotate each CMP field that should be part of theprimary key class with @primkey-field.abstract-schema-nameThe abstract schema name for this EJB. If notspecified, the ejb-name value will be used.cache-between-(True|False) Whether to cache the persistent datatransactionsof an entity bean across (between) transactions.check-exists-on-method(True|False) Whether the container checks for theexistence of a bean for each method call.concurrency-strategy(Read Only|Exclusive|Database) Defines theconcurrency strategy for this bean.data-source-nameThe name of the data source (as it was declared inconfig.xml).database-typeThe type of the database.db-is-shared(True|False) Whether the database is shared.default-transactionThe transaction attribute to be applied to allmethods that do not have a more specifictransaction attribute setting.delay-database-insert-(ejb Create|ejbPost Create)untildelay-updates-until-end-(True|False) Whether updates will be sent after theof-txtransaction has committed.enable-dynamic-queries(True|False) Whether dynamic queries are enabled.finders-load-bean(True|False) If this is set to True, the beans willimmediately be loaded into the cache by the finder.home-call-router-class-Class to be used for routing home method calls.namehome-is-clusterable(True|False) Whether this bean can be deployedfrom multiple servers in a cluster.home-load-algorithm(Round|Robin|Random|WeightBased) Thealgorithm to use for load-balancing betweenreplicas of this home.idle-timeout-secondsMaximum duration an EJB should stay in thecache.invalidation-targetThe ejb-name of a read-only Entity bean thatshould be invalidated when this Container-Managed Persistence Entity EJB has beenmodified.max-beans-in-cacheThe maximum number of beans in the cache.Optimistic-columnThe column that holds the time stamp foroptimistic concurrencypersistence-type(cmp|bmp) The type of this Entity bean (default:cmp)prim-key-class-nogen(True|False). If this keyword is specified, EJBGenwill not generate the primary key class.read-timeout-secondsThe number of seconds between each ejbLoad( )call on a Read-Only Entity bean.reentrant(True|False) Whether the class methods arereentrant.run-asSpecifies the role-name for this EJB.run-as identity-principalThe name of the principal in case the role maps toseveral principals.table-nameThe name of the table this Entity bean is mappedto.trans-timeout-secondsThe transaction timeout (in seconds).use-caller-identity(True|False) Whether this EJB uses caller'sidentity.verify-columns(Read|Modified|Version|Timestamp) Howoptimistic concurrency verifies that the columnsmodified during the transactions have not beenmodified.@ejbgen:env-entryDeclare an environment entry to be made availableClassAllthrough JNDI ENC.NameThe name of this environment entry. (Required)TypeThe Java type for this environment entry (must befully qualified, even if java.lang). (Required)ValueThe value for this environment entry. (Required)@ejbgen:file-generationControl which files are generated.ClassAlllocal-class(True|False) Whether to generate the localinterface for this EJB.local-home(True|False) Whether to generate the local homeinterface for this EJB.pk-class(True|False) Whether to generate the primary keyclass for this EJB.remote-class(True|False) Whether to generate the remoteinterface for this EJB.remote-home(True|False) Whether to generate the remote homeinterface for this EJB.value-class(True|False) Whether to generate the value classfor this EJB@ejbgen:finderSpecify finder method attributes.ClassEntitycaching-nameThe name of an eager relationship caching.ejb-qlThe EJB QL request as it will appear in thedeployment descriptor.group-nameName of the group for the WebLogic queryinclude-updates(True|False) Whether updates made during thecurrent transaction must be reflected in the resultof a query.isolation-levelThe type of transaction isolation for this method.max-elementsThe maximum number of elements that should bereturned by a multi-valued query.SignatureIt must match exactly the signature generated onthe Home class.sql-select-distinct(True|False) Whether the generated SQL‘SELECT’ will contain a ‘DISTINCT’ qualifier.transaction-attributeThe transaction attribute for this local method. Ifnot specified, the default transaction attribute willbe used. Methods with this tag will be generated onthe Local class.Weblogic-ejb-qlThe Weblogic EJB QL request as it will appear inthe deployment descriptor.@ejbgen:foreign jms-Specify the provider of a Java ™ Message ServiceClassMessage-provider(“JMS”)Drivenconnection-factory-jndi-The connection factory JNDI name. (Required)nameinitial context-factoryThe initial JNDI context factory. (Required)provider-urlThe provider URL. (Required)@ejbgen:isolation-Specify transaction isolation level in the server.ClassAlllevel patternisolation-levelThe isolation level for the methods specified in thepattern tag. (Required)PatternThe pattern that matches all methods that willreceive this isolation level (e.g. “*”). (Required)@ejbgen:jndi-nameSpecify the JNDI name of this bean.ClassAllLocalThe local JNDI name of this EJB. If not specified,local interfaces will not be generated.RemoteThe remote JNDI name of this EJB. If notspecified, remote interfaces will not be generated.@ejbgen:local-homeSpecify attributes of this local home method.MethodEntity,methodSessionRolesComma-separated list of roles that are allowed toinvoke this method.transaction-attributeThe transaction attribute for this local method. Ifnot specified, the default transaction attribute willbe used. Methods with this tag will be generated onthe Local class.@ejbgen:local-methodSpecify attributes of this local method.MethodEntity,Sessionisolation-levelThe type of transaction isolation for this method.RolesComma-separated list of roles that are allowed toinvoke this method.transaction-attributeThe transaction attribute for this local method. Ifnot specified, the default transaction attribute willbe used. Methods with this tag will be generated onthe Local class.@ejbgen:message-drivenDeclare a message-driven EJB.ClassMessage-Drivendestination-jndi-nameThe JNDI name of the destination. (Required)ejb-nameThe name of this Message-Driven bean.(Required)acknowledge-mode(auto-acknowledge-ok-acknowledge) Theacknowledgement mode.default-transactionThe transaction attribute to be applied to allmethods that do not have a more specifictransaction attribute setting.destination-type(javax.jms.Queue|javax.jms.Topic).initial-beans-in-free-poolThe initial number of beans in the free pool.max-beans-in-free-poolThe maximum number of beans in the free pool.message-selectorThe JMS message selector.run-asSpecifies the role-name for this EJB.run-as-identity-principalThe name of the principal in case the role maps toseveral principals.trans-timeout-secondsThe transaction timeout (in seconds).transaction-type(Bean|Container) Who manages the transactionsfor this EJB.use-caller-identity(True|False) Whether this EJB uses caller'sidentity.@ejbgen:method-Specify a permission pattern for this class.ClassAllpermission-patternPatternThe pattern that matches all methods that willreceive this method permission (e.g. “*”).RolesThe roles for the methods specified in the patterntag. Separated by a comma.@ejbgen:primkey-fieldSpecify the primary key field for an entity bean.MethodEntity@ejbgen:relationSpecify an entity bean relationship.ClassEntityUnidirectional relationships are achieved byspecifying only the first three parameters (i.e, nocmr-field, no fk-column, no joint-table).multiplicityMany to many relationships must specify an extratable (“joint-table”) which must contain at leasttwo columns. The names of these columns mustmatch the names of the columns containing theforeign keys of the two EJB's being joined.(one|many) Specifies the multiplicity of therelationship. (Required)NameThe name of the relationship. Use the same nameon both ends of a relationship for the roles to begenerated properly (note that this constraint appliesto unidirectional as well). (Required)target-ejbThe EJB name of the target of this relationship.(Required)cascade-delete(True|False)cmr-fieldThe CMR field where this relationship will bekept. If it not specified, the relationship isunidirectional. If specified, the attribute fk-columnmust be specified as well.db-cascade-delete(True|False) Whether a cascade delete will use thebuilt-in cascade delete facilities of the underlyingdatabase.fk-columnOnly needed in a relationship having at least oneside. In that case, the non-one side EJB mustdeclare a column that it will use to store theprimary key of its counterpart.joint-tableOnly needed in a Many-Many relationship. It mustbe the name of an existing table that will be used tohold the joint table containing the relationships. Ifusing a compound primary key, specify a set ofcorresponding foreign keys separated by commas.role-nameThe name of this role (such as“ParentHasChildren”). If no role name is given,will generate one.@ejbgen:relationship-Specify cache information for relationship.ClassEntitycaching-elementcaching-nameThe name of an eager relationship cashing.(Required)cmr-fieldThe name of the CMR field. (Required)group-nameThe name of the group to be loaded for the CMRfield.@ejbgen:remote-home-Specify roles allowed to invoke this home method.MethodEntity,methodSessionThe method name must start with “ejbHome”.Note: Home Methods do not apply to messageEJB's Beans. The “throws RemoteException” inthe EJB class will be automatically generated inthe home class.RolesComma-separated list of roles that are allowed toinvoke this method.transaction-attributeThe transaction attribute for this remote method. Ifnot specified, the default transaction attribute willbe used. Methods with this tag will be generated onthe Remote class.@ejbgen:remote-methodSpecify a method available in a remote interface.MethodEntity,Sessionisolation-levelThe type of transaction isolation for this method.RolesComma-separated list of roles that are allowed toinvoke this method.transaction-attributeThe transaction attribute for this remote method. Ifnot specified, the default transaction attribute willbe used. Methods with this tag will be generated onthe Remote class.@ejbgen:resource-Specify the name of a resource environmentClassAllenv-refreference.(Required)NameName of the resource environment reference.(Required)TypeType of the environment resource references (e.g.javax.jms.Queue). (Required)jndi-nameJNDI name of the resource.@ejbgen:resource-refSpecify the JNDI name of a resource.ClassAllAuth(Application|Container) (Required)jndi-nameJNDI name of the resource. (Required)NameName of the resource. (Required)TypeTyoe of the resource (e.g. javax.sql.DataSource).(Required)sharing-scope(Shareable|Unshareable)@ejbgen:role-mappingSpecify roles.ClassAllPrincipalsThe names of the principals in this role (separatedby commas). (Required)role-nameThe name of the role. (Required)@ejbgen:selectSpecify attributes of select method.MethodEntityejb-qlThe EJB-QL defining this select method. Note: themethod name must start with ejbSelect. (Required)caching-nameThe name of an eager relationship caching.group-nameName of the group for the WebLogic query.include-updates(True|False) Whether updates made during thecurrent transaction must be reflected in the resultof a query.max-elementsThe maximum number of elements that should bereturned by a multi-valued query.result-type-mapping(Remote|Local) Whether the returned objects aremapped to EJBLocalObject or EJBObject.sql-select-distinct(True|False) Whether the generated SQL‘SELECT’ will contain a ‘DISTINCT’ qualifier.Weblogic-ejb-qlThe Weblogic EJB QL request as it will appear inthe deployment descriptor.@ejbgen:sessionDeclare a session bean.ClassSessionejb-nameThe name of this Session bean. (Required)bean-load-algorithmThe algorithm to use for load-balancing betweenreplicas of this bean.call-router-class-nameClass name to be used for routing home methodcallsdefault-transactionThe transaction attribute to be applied to allmethods that do not have a more specifictransaction attribute setting.home-call-router-class-Class to be used for routing home method calls.namehome-is-clusterable(True|False) Whether this bean can be deployedfrom multiple servers in a cluster.home-load-algorithm(RoundRobin|Random|WeightBased) Thealgorithm to use for load-balancing betweenreplicas of this home.idle-timeout-secondsMaximum duration an EJB should stay in thecacheinitial-beans-in-free-poolThe initial number of beans in the free pool.is-clusterable(True|False) Whether this bean is cluster-able.load-algorithm(RoundRobin|Random|WeightBased) The name ofthe algorithm used to balance replicas of thishome.max-beans-in-cacheThe maximum number of beans in the cache.max-beans-in-free-poolThe maximum number of beans in the free pool.methods-are-idempotent(True|False) Whether the methods for this statelesssession bean are idem potent or not.replication-type(InMemory|None) How to replicate stateful sessionbeans in a cluster.run-asSpecifies the role-name for this EJB.run-as-identity-principalThe name of the principal in case the role maps toseveral principals.trans-timeout-secondsThe transaction timeout (in seconds).transaction-type(Bean|Counter) Who manages the transactions forthis EJB.Type(Stateless|Stateful) The type of the Session bean. Ifthis attribute is not specified, EJBGen will guessthe right type by looking at the ejbCreate( )methods on the class.use-caller-identity(True|False) Whether this EJB uses caller'sidentity.@ejbgen:value-objectSpecify objects to be referenced by the valueClassAllobject class.Reference(Local|Value) Specify what objects the valueobject class should reference when accessing otherEJB's. (Required)


[0014] In one embodiment, by way of example, the following class annotations accompany a Java™ code fragment that declares a stateless session EJB “Trader” having a JNDI name of “ejb20-statelessSession-TraderHome”, and an environment variable “tradeLimit” with a default value of 500.
3/** * @ejbgen:session *  ejb-name = statelessSession *  max-beans-in-free-pool = 100 *  is-clusterable = false *  load-algorithm = Random * * @ejbgen:jndi-name *  remote = ejb20-statelessSession-TraderHome * * @ejbgen:env-entry *  name = tradeLimit *  type = java.lang.Integer *  value = 500 * */public class TraderEJB implements SessionBean { private static final boolean VERBOSE = true; private SessionContext ctx; private int tradeLimit; ejbCreate( );. . .


[0015] The type of session EJB (e.g., stateful or stateless) can be automatically determined. For example, if there is an ejbCreate( ) method having a non-empty parameter list, the EJB is stateful. Otherwise, the EJB is stateless. Two methods associated with this EJB are declared below with method annotations indicating that they are available through a remote interface (i.e., to clients residing outside of the Java™ application server in which this EJB is deployed). Notice that both methods make use of the environment variable “tradeLimit” which was declared in the class annotation.
4 /**  /**  *  Buys shares of a stock for a named customer.  *  *  @ejbgen:remote-method  */ public TradeResult buy(String stockSymbol, int shares) {  if (shares > tradeLimit) {   log(“Attempt to buy “+shares+” is greater than limit of”+tradeLimit);   shares = tradeLimit;  } log(“Buying “+shares+” shares of ”+stockSymbol); return new TradeResult(shares, stockSymbol); } /**  *  Sells shares of a stock for a named customer.  *  *  @ejbgen:remote-method  *  */ public TradeResult sell(String stockSymbol, int shares) {  if (shares > tradeLimit) {   log(“Attempt to sell “+shares+” is greater than limit of”+tradeLimit);   shares = tradeLimit;  }  log(“Selling “+shares+” shares of ”+stockSymbol);  return new TradeResult(shares, stockSymbol); }}


[0016] The @ejbgen:remote-method annotation indicates that a method will be available in a remote interface. A remote interface declares an EJB's methods that are accessible to applications outside of an EJB's container. Two Java™ files and two deployment descriptors are automatically generated in accordance to an embodiment based on the code fragment above:
5File NameContentsTraderHomeimport javax.ejb.CreateException;.javaimport javax.ejb.EJBHome;import javax.ejb.FinderException;import java.rmi.RemoteException;Homeimport java.util.Collection;Interfacepublic interface TraderHome extends EJBHome { public Trader create( )   throws CreateException,RemoteException, CreateException;}Trader.javaimport java.rmi.RemoteException;import javax.ejb.EJBObject;Remotepublic interface Trader extends EJBObject {Interface public TradeResult buy(String stockSymbol, intshares)  throws RemoteException;  public TradeResult sell (String stockSymbol, intshares)   throws RemoteException;}ejb-jar.xml<ejb-jar> <enterprise-beans>  <session>EJB   <ejb-name>statelessSession</ejb-name>Deployment<home>examples.ejb20.basic.statelessSession.DescriptorTraderHome </home><remote>examples.ejb20.basic.statelessSession.Trader</remote>   <ejb-class>examples.ejb20.basic.statelessSession.TraderEJB</ejb-class>   <session-type>Stateless</session-type>   <transaction-type>Container</transaction-type>   <env-entry>    <env-entry-name>INTL</env-entry-name>    <env-entry-type>java.lang.Double</env-entry-type>    <env-entry-value>15.0</env-entry-value>   </env-entry>   <env-entry>    <env-entry-name>tradeLimit</env-entry-name>    <env-entry-type>java.lang.Integer</env-entry-type>    <env-entry-value>500</env-entry-value>   </env-entry>   <env-entry>    <env-entry-name>WEBL</env-entry-name>    <env-entry-type>java.lang.Double</env-entry-type>    <env-entry-value>10.0</env-entry-value>   </env-entry>  </session> </enterprise-beans></ejb-jar>weblogic-<?xml version=“1.0”?>ejb-jar.xml<!DOCTYPE weblogic-ejb-jar PUBLIC “-//BEA Systems,Inc.//DTD WebLogic 6.0.0 EJB//EN”“http://www.bea.com/servers/wls600/dtd/weblogic-ejb-BEAjar.dtd” >WebLogic<weblogic-ejb-jar>Server ® <weblogic-enterprise-bean>Deployment  <ejb-name>statelessSession</ejb-name>Descriptor  <stateless-session-descriptor>   <pool>    <max-beans-in-free-pool>100</max-beans-    in-free-pool>   </pool>   <stateless-clustering>    <stateless-bean-is-clusterable>false</stateless-bean-is-clusterable>   </stateless-clustering>  </stateless-session-descriptor>  <jndi-name>ejb20-statelessSession-TraderHome</jndi-name> </weblogic-enterprise-bean></weblogic-ejb-jar>


[0017] In one embodiment, a value associated with an attribute can be specified with a constant or a variable. In another embodiment, a variable definition can be separate from the EJB definition (e.g., in another file). For example, the variable “remote-jndi-name” can be defined as “Account” as follows:


[0018] remote-jndi-name=Account


[0019] Within the annotated description, variables can be accessed with the delimiters “${“and”}”. For example:


[0020] @ejbgen:jndi-name


[0021] remote=${remote-jndi-name}


[0022] Thus, “remote” would be equal to “Account”.


[0023] In another embodiment, variables can be used anywhere after an annotation and can contain whole annotation definitions. Assuming the following variable definition:


[0024] jndi-name-tag=remote=RemoteAccount local=LocalAccount


[0025] The following annotation:


[0026] @ejbgen:jndi-name


[0027] ${jndi-name-tag}


[0028] would expand to:


[0029] @ejbgen:jndi-name


[0030] remote=RemoteAccount Local=LocalAccount


[0031] In another embodiment, predefined variables are recognized. Predefined variables have default values that can be overridden. In one embodiment, predefined variables can be defined as follows:
6Variable NameDescriptionremote.baseClassThe value of this variable will beused as the base class for all generateremote classes.home.baseClassThe value of this variable will beused as the base class for allgenerated remote home classes.local.baseClassThe value of this variable will beused as the base class for allgenerated local classes.localHome.baseClassThe value of this variable will beused as the base class for allgenerated local home classes.value.baseClassThe value of this variable will beused as the base class for allgenerated value classes.value.packageThe value of this variable will beused as the package for allgenerated value classes.


[0032] In another embodiment, predefined variables can be prefixed with a class name. For example, if the following predefined variables are overridden as follows:


[0033] Account.home-baseClass=BaseAccountHome


[0034] home.baseClass=BaseHome


[0035] value.package=value


[0036] containerManaged.value.package=valuePackageForContainerManaged


[0037] Thus, all home interfaces generated will extend the class BaseHome except the home of EJB “Account”, which will extend BaseAccountHome.


[0038] In another embodiment, EJB annotations can be inherited according to Java™ class inheritance. For example, if an EJB named AccountEJB has a base class BaseAccount:
7/** *  @ejbgen:jndi-name *    remote=“BaseRemote” *  @ejbgen:entity *   max-beans-in-cache = 300*/public class BaseAccount implements EntityBean {. . .}/** *  @ejbgen:entity *   ejb-name = containerManaged *   table-name = ejbAccounts *   data-source-name = examples-dataSource-demoPool *   max-beans-in-cache = 400 **/public class AccountEJB extends BaseAccount {. . .


[0039] The JNDI remote name “BaseRemote” and max-beans-in-cache of 300 that are defined in the class BaseAccount are inherited by the subclass AccountEJB. The subclass can optionally override these values. For example, the value of max-beans-in-cache is overridden to be 400 instead of 300.


[0040] In another embodiment, EJB relations can be inherited if a value for the attribute ‘role-name’ is specified. All “role-name” attributes in the Java™ inheritance path can be merged. For example, the following parent class defines a partial relation:
8/** *  @ejbgen:relation *   name = Many1-Many2 *   role-name = Many1HasMany2 *   multiplicity = many * role-name = Many1HasMany2 *   target-ejb = Many2EJB *   fk-column = many2_fk *   joint-table = join_table */abstract public class BaseMany1 extends BaseEntityBean {


[0041] The following subclass inherits the above relation and completes its definition:
9 *  @ejbgen:relation *   role-name = Many1HasMany2 *   cmr-field = many2 * */abstract public class Many1EJB extends BaseMany1 {


[0042] It will be apparent to those skilled in the art that the process of generating EJB source files from an annotated description of an EJB can be performed in reverse. All of the files or classes needed to deploy an EJB can be reduced into a single annotated description of the EJB which can, in accordance to one embodiment, be used in turn to reproduce the EJB source files. Annotations can be generated automatically based information contained in the class definitions, deployment descriptors and relationships between classes.


[0043]
FIG. 2 is a block diagram in accordance to one embodiment of the invention. A plurality of input files 7 containing EJB classes and deployment information is processed by analyzer 8. Input files 7 can include one or more EJB class definitions. In one embodiment, input files 7 can reside in a single file, such as a Java™ Archive File (“JAR”). In another embodiment, input files 7 can reside in a computer memory. In yet a further embodiment, input files 7 can be transmitted via a computer network (not shown) to analyzer 8. Analyzer 8 employs parser 10 to extract information related to class structure, class relationships and deployment from input files 7. Analyzer 8 may perform preprocessing of input files 7 before making use of parser 10. In one embodiment, parser 10 can exploit the doclet application programming interface available in Javadoc. In one embodiment, parser 10 can process all input files 7 at once. In another embodiment, parser 10 can be employed repeatedly by analyzer 8 to incrementally process input files 7. During or after parsing, analyzer 8 builds an EJB database 11 containing all of the extracted information pertaining to each EJB represented by input files 7. The EJB database 11 information is then examined to identify which annotation(s) from annotation library 5 adequately describe the EJB'S. The these annotations (not shown) along with the EJB database 11 information are provided to code generator 9. Code generator 9 then emits annotated Java™ code 1 to describe the EJB class(s) in input files 7.


[0044] The foregoing description of the preferred embodiments of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. Embodiments were chosen and described in order to best describe the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention, the various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalents.


Claims
  • 1. A method for generating Enterprise Java Beans, comprising: generating at least one output based on a description of at least one Enterprise Java Bean (EJB), wherein the description is attended by at least one annotation and the at least one annotation includes at least one variable.
  • 2 The method of claim 1 wherein: the at least one annotation can be inherited.
  • 3. The method of claim 1 wherein: the at least one output includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 4. The method of claim 1 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 5. The method of claim 4 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 6. The method of claim 1 wherein: the at least one annotation includes at least one attribute.
  • 7. The method of claim 6 wherein: the at least one attribute is associated with at least one expression.
  • 8. The method of claim 2 wherein: annotation inheritance is based on Java class inheritance.
  • 9. The method of claim 1 wherein: the at least one variable is one of user-specified and predefined.
  • 10. The method of claim 9 wherein: the at least one predefined variable can be redefined.
  • 11. The method of claim 9 wherein: the at least one predefined variable can be prefixed with a class name.
  • 12. The method of claim 1 wherein: the at least one annotation is one of a class annotation and a method annotation.
  • 13. The method of claim 1 wherein: the at least one annotation is a Javadoc tag.
  • 14. The method of claim 1 wherein: the at least one variable can be defined separately from the description of the at least one EJB.
  • 15. The method of claim 1 wherein: the at least one output can be used to generate the description of the at least one EJB.
  • 16. A method for generating Enterprise Java Beans, comprising: generating at least one output based on a description of at least one Enterprise Java Bean (EJB), wherein the description includes at least one annotation and the at least one annotation can be inherited.
  • 17. The method of claim 16 wherein: the at least one output includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 18. The method of claim 16 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 19. The method of claim 18 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 20. The method of claim 16 wherein: the at least one annotation includes at least one attribute.
  • 21. The method of claim 20 wherein: the at least one attribute is associated with at least one expression.
  • 22. The method of claim 16 wherein: annotation inheritance is based on Java class inheritance.
  • 23. The method of claim 16 wherein: the at least one annotation includes at least one variable.
  • 24. The method of claim 23 wherein: the at least one variable is one of user-specified and predefined.
  • 25. The method of claim 24 wherein: the at least one predefined variable can be redefined.
  • 26. The method of claim 24 wherein: the at least one predefined variable can be prefixed with a class name.
  • 27. The method of claim 16 wherein: the at least one annotation is one of a class annotation and a method annotation.
  • 28. The method of claim 16 wherein: the at least one annotation is a Javadoc tag.
  • 29. The method of claim 23 wherein: the at least one variable can be defined separately from the description of the at least one EJB.
  • 30. The method of claim 16 wherein: the at least one output can be used to generate the description of the at least one EJB.
  • 31. A method comprising: generating a description of at least one Enterprise Java Bean (EJB) from at least one input, wherein the description includes at least one annotation and the description can be used to generate the at least one input.
  • 32. The method of claim 31 wherein: the at least one annotation can be inherited.
  • 33. The method of claim 31 wherein: the at least one input includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 34. The method of claim 31 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 35. The method of claim 34 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 36. The method of claim 31 wherein: the at least one annotation includes at least one attribute.
  • 37. The method of claim 36 wherein: the at least one attribute is associated with at least one expression.
  • 38. The method of claim 32 wherein: annotation inheritance is based on Java class inheritance.
  • 39. The method of claim 31 wherein: the at least one annotation is one of a class annotation and a method annotation.
  • 40. The method of claim 31 wherein: the at least one annotation is a Javadoc tag.
  • 41. A system for generating Enterprise Java Beans, comprising: an analyzer to process a description of at least one Enterprise Java Beans (EJB); and a code generator coupled to the analyzer, the code generator to generate at least one output; and wherein the description includes at least one annotation and the at least one annotation includes at least one variable.
  • 42. The system of claim 41 wherein: the analyzer includes at least one of a parser, a annotation library, and a variable library.
  • 43. The system of claim 41 wherein: the at least one annotation can be inherited.
  • 44. The system of claim 41 wherein: the at least one output includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 45. The system of claim 41 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 46. The system of claim 45 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 47. The system of claim 41 wherein: the at least one annotation includes at least one attribute.
  • 48. The system of claim 47 wherein: the at least one attribute is associated with at least one expression.
  • 49. The system of claim 43 wherein: annotation inheritance is based on Java class inheritance.
  • 50. The system of claim 41 wherein: the at least one variable is one of user-specified and predefined.
  • 51. The system of claim 50 wherein: the at least one predefined variable can be redefined.
  • 52. The system of claim 50 wherein: the at least one predefined variable can be prefixed with a class name.
  • 53. The system of claim 41 wherein: the at least one annotation is one of a class annotation and a method annotation.
  • 54. The system of claim 41 wherein: the at least one annotation is a Javadoc tag.
  • 55. The system of claim 41 wherein: the at least one variable can be defined separately from the description of the at least one EJB.
  • 56. The system of claim 41 wherein: the at least one output can be used to generate the description of the at least one EJB.
  • 57. A system for generating Enterprise Java Beans, comprising: an analyzer to process a description of at least one Enterprise Java Beans (EJB); and a code generator coupled to the analyzer, the code generator to generate at least one output; and wherein the description includes at least one annotation and the at least one annotation can be inherited.
  • 58. The system of claim 57 wherein: the analyzer includes at least one of a parser, a annotation library, and a variable library.
  • 59. The system of claim 57 wherein: the at least one annotation includes at least one variable.
  • 60. The system of claim 57 wherein: the at least one output includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 61. The system of claim 57 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 62. The system of claim 61 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 63. The system of claim 57 wherein: the at least one annotation includes at least one attribute.
  • 64. The system of claim 63 wherein: the at least one attribute is associated with at least one expression.
  • 65. The system of claim 57 wherein: annotation inheritance is based on Java class inheritance.
  • 66. The system of claim 59 wherein: the at least one variable is one of user-specified and predefined.
  • 67. The system of claim 66 wherein: the at least one predefined variable can be redefined.
  • 68. The system of claim 66 wherein: the at least one predefined variable can be prefixed with a class name.
  • 69. The system of claim 57 wherein: the at least one annotation is one of a class annotation and a method annotation.
  • 70. The system of claim 57 wherein: the at least one annotation is a Javadoc tag.
  • 71. The system of claim 59 wherein: the at least one variable can be defined separately from the description of the at least one EJB.
  • 72. The system of claim 57 wherein: the at least one output can be used to generate the description of the at least one EJB.
  • 73. A system for generating an annotated description of an Enterprise Java Bean, comprising: an analyzer to process at least one input; and a code generator coupled to the analyzer, the code generator to generate a description of at least one Enterprise Java Bean (EJB) from the at least one input; and wherein the description includes at least one annotation; and wherein the description can be used to generate the at least one input.
  • 74. The system of claim 73 wherein: the analyzer includes at least one of a parser, a annotation library, and a database.
  • 75. The system of claim 73 wherein: the at least one annotation can be inherited.
  • 76. The system of claim 73 wherein: the at least one input includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 77. The system of claim 73 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 78. The system of claim 77 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 79. The system of claim 73 wherein: the at least one annotation includes at least one attribute.
  • 80. The system of claim 79 wherein: the at least one attribute is associated with at least one expression.
  • 81. The system of claim 75 wherein: annotation inheritance is based on Java class inheritance.
  • 82. The system of claim 73 wherein: the annotation is one of a class annotation and a method annotation.
  • 83. The system of claim 73 wherein: the annotation is a Javadoc tag.
  • 84. A machine readable medium having instructions stored thereon that when executed by a processor cause a system to: generate at least one output based on a description of at least one Enterprise Java Bean (EJB), wherein the description is attended by at least one annotation and the at least one annotation includes at least one variable.
  • 85 The machine readable medium of claim 84 wherein: the at least one annotation can be inherited.
  • 86. The machine readable medium of claim 84 wherein: the at least one output includes one of a local interface class, a home interface class, a remote interface class, and a deployment descriptor.
  • 87. The machine readable medium of claim 84 wherein: the at least one EJB is one of an entity EJB, a stateful session EJB, a stateless session EJB, and a message driven EJB.
  • 88. The machine readable medium of claim 87 wherein: an entity EJB includes at least one of the following relationships: one-to-one, one-to-many, many-to-many, unidirectional, and bi-directional.
  • 89. The machine readable medium of claim 84 wherein: the at least one annotation includes at least one attribute.
  • 90. The machine readable medium of claim 89 wherein: the at least one attribute is associated with at least one expression.
  • 91. The machine readable medium of claim 85 wherein: annotation inheritance is based on Java class inheritance.
  • 92. The machine readable medium of claim 84 wherein: the at least one variable is one of user-specified and predefined.
  • 93. The machine readable medium of claim 92 wherein: the at least one predefined variable can be redefined.
  • 94. The machine readable medium of claim 92 wherein: the at least one predefined variable can be prefixed with a class name.
  • 95. The machine readable medium of claim 84 wherein: the annotation is one of a class annotation and a method annotation.
  • 96. The machine readable medium of claim 84 wherein: the annotation is a Javadoc tag.
  • 97. The machine readable medium of claim 84 wherein: the at least one variable can be defined separately from the description of the at least one EJB.
  • 98. The machine readable medium of claim 84 wherein: the at least one output can be used to generate the description of the at least one EJB.