Enterprise Java and UML 2nd Edition PHẦN 1 ppsx

10 306 0
Enterprise Java and UML 2nd Edition PHẦN 1 ppsx

Đang tải... (xem toàn văn)

Thông tin tài liệu

OMG PRESS CT Arrington, Syed Rayhan Enterprise Java 2nd Edition ™ UML ™ and 1 TimeEntryInt.java TimeEntryLocal.java is the local interface for the TimeEntry entity bean. It defines the locally accessible methods for the TimeEntry entity bean. This is shown in Figure 01. Figure 01 Local interface of the TimeEntry entity bean. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java.util.*; import javax.ejb.*; /** * The TimeEntryInt is the interface that ties the Bean with the Remote <<EntityLocal>> TimeEntryLocal + getHours() : int + getDate() : Date + getChargeCode() : ChargeCodeLocal + getTimecard() : TimecardLocal + setHours(hours : int) + setDate(day : Date) + setChargeCode(code : ChargeCodeLocal) TimeEntryEntityBean 267783 WS01.qxd 5/5/03 9:17 AM Page 1 * interface to provide compile time type checking. */ public interface TimeEntryInt { /** Answers a ChargeCode for this TimeEntry. */ public ChargeCodeLocal getChargeCode(); /** Answers the hour charged in this TimeEntry. */ public int getHours(); /** Answers the day the time is entered for. */ public Date getDate(); /** Answers the timecard it belongs to. */ public TimecardLocal getTimecard(); /** sets a ChargeCode for this TimeEntry. */ public void setChargeCode(ChargeCodeLocal ccode); /** sets the hour charged in this TimeEntry. */ public void setHours(int hours); /** sets the day the time is entered for. */ public void setDate(Date date); } TimeEntryLocal.java TimeEntryLocal.java is the local EJB interface that inherits from TimeEntryInt and hence the body is empty. This is in line with what we have set as our implementation strategy for all of our EJBs. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java.util.*; import javax.ejb.*; /** * The TimeEntry bean holds a single time entry. * TimeEntryLocal is the local interface through which local clients * access the underlying entity bean. */ public interface TimeEntryLocal extends EJBLocalObject, TimeEntryInt { } 2 TimeEntryEntityBean 267783 WS01.qxd 5/5/03 9:17 AM Page 2 TimeEntrytLocalHome.java TimeEntryLocalHome.java is the Home interface for the TimeEntry entity bean. It defines the methods for finding and creating TimeEntry entity beans. This is shown in Figure 02. Figure 02 Local Home interface of the TimeEntry entity bean. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java.util.*; import javax.ejb.*; /** * The TimeEntry bean holds a single time entry. * * TimeEntryLocalHome is the local interface through which local clients * find and create the underlying entity beans. * */ public interface TimeEntryLocalHome extends EJBLocalHome { /** Answers a local reference to the newly created Timecard bean. */ public TimeEntryLocal create(String timeEntryId, Date day, int Æ hours, ChargeCodeLocal code, TimecardLocal tcard) Æ throws CreateException; /** Answers a Collection of references to TimeEntries for a Æ specific Timecard. */ public Collection findByTimecard(String timecardId) throws Æ FinderException; /** Answers a local reference to the specified TimeEntry, if it Æ exists. */ public TimeEntryLocal findByPrimaryKey(TimeEntryPK key) throws Æ FinderException; } <<EntityLocalHome>> TimeEntryLocalHome + create(id : String, hour : int, day : Date, code : ChargeCodeLocal, tcard : TimecardLocal) : TimeEntryLocal + findByPrimaryKey(key : TimeEntryPK) : TimeEntryLocal + findByTimecard(tcardId : String) : Collection TimeEntryEntityBean 3 267783 WS01.qxd 5/5/03 9:17 AM Page 3 TimeEntryPK.java TimeEntryPK.java represents the primary key class of the TimeEntry entity bean. It is important to note here that it implements hashCode() and equals() methods and imple- ments the Serializable interface. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java.io.Serializable; /** * The TimeEntry bean holds a single time entry. * * TimeEntryPK is the primary key class for the underlying entity Æ bean. It is, * id = timecard-id + entry-count-for-timecard */ public class TimeEntryPK implements Serializable { public String id; public TimeEntryPK() { } public TimeEntryPK(String id) { this.id = id; } public String toString() { return id; } public int hashCode() { return id.hashCode(); } public boolean equals(Object key) { if (key == null) { return false; } else { 4 TimeEntryEntityBean 267783 WS01.qxd 5/5/03 9:17 AM Page 4 if (!key.getClass().equals(this.getClass())) { return false; } else { return ((TimeEntryPK)key).id.equals(this.id); } } } } TimeEntryBean.java TimeEntryBean.java is the implementation class for the TimeEntry entity bean. It pro- vides the data and logic for the bean. Again, there is not much to it. Each TimeEntry entity bean holds an ID, total hours worked, the day of the work, a reference to the charge code entity bean, and a reference to the timecard entity bean to which it belongs. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*; import java.util.*; import javax.ejb.*; import javax.naming.*; /** * The TimeEntry bean holds time entries for a date range. * TimeEntryBean is the actual entity bean implementation. */ public abstract class TimeEntryBean extends BasicEntityBean Æ implements TimeEntryInt { /** CMP fields */ public abstract String getId(); public abstract void setId(String id); public abstract long getDay(); public abstract void setDay(long day); public abstract int getHours(); public abstract void setHours(int hours); /** CMR fields */ public abstract TimecardLocal getTimecard(); public abstract void setTimecard(TimecardLocal card); public abstract ChargeCodeLocal getChargeCode(); TimeEntryEntityBean 5 267783 WS01.qxd 5/5/03 9:17 AM Page 5 public abstract void setChargeCode(ChargeCodeLocal code); /** * Create an TimeEntryBean with the specified parameters. This is * never called directly. */ public TimeEntryPK ejbCreate(String timeEntryId, Date day, int hours, ChargeCodeLocal code, TimecardLocal tcard) throws Æ CreateException { System.out.println(“in ejbCreate() of TimeEntryBean!”); // sets the CMP fields setId(timeEntryId); setDay(day.getTime()); setHours(hours); return null; } /** Actions performed after creation. This is never called directly. */ public void ejbPostCreate(String timeEntryId, Date day, int hours, ChargeCodeLocal code, TimecardLocal tcard) { System.out.println(“in ejbPostCreate() of TimeEntryBean!”); //sets CMR fields setChargeCode(code); setTimecard(tcard); } /** Answers the day the time is entered for. */ public Date getDate() { return new Date(getDay()); } /** sets the day the time is entered for. */ public void setDate(Date date) { setDay(date.getTime()); } } 6 TimeEntryEntityBean 267783 WS01.qxd 5/5/03 9:17 AM Page 6 7 ChargeCodeInt.java ChargeCodeInt.java is the local Business interface for the ChargeCode entity bean. It defines all of the locally accessible methods for the ChargeCode entity bean. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import javax.ejb.*; /** * The ChargeCodeInt is the interface that ties the Bean with the Remote * interface to provide compile time type checking. */ public interface ChargeCodeInt { /** Answers the name of this ChargeCode. */ public String getName(); /** Answers the description of this ChargeCode. */ public String getDescription(); /** Answers the parent Project of this ChargeCode. */ public ProjectLocal getProject(); } ChargeCodeEntityBean 267783 WS02.qxd 5/5/03 9:17 AM Page 7 ChargeCodeLocal.java ChargeCodeLocal.java is the local EJB interface for the ChargeCode entity bean that inherits from ChargeCodeInt. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import javax.ejb.*; /** * The ChargeCode bean holds descriptive information about a billable * charge code. Since each ChargeCode is part of a larger project, the * parent project can be accessed from the charge code. * ChargeCodeLocal is the local interface through which local clients * access the underlying entity bean. */ public interface ChargeCodeLocal extends EJBLocalObject, ChargeCodeInt { } ChargeCodeLocalHome ChargeCodeLocalHome.java is the Home interface for the ChargeCode entity bean. It defines the methods for finding and creating ChargeCode entity beans. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java.util.*; import javax.ejb.*; /** * The ChargeCode bean holds simple descriptive information on a common * activity that is performed by development teams. This activity may be * used to create a ChargeCode. * * ChargeCodeLocalHome is the local interface through which local * clients find and create the underlying entity beans. * */ public interface ChargeCodeLocalHome extends EJBLocalHome { /** Answers a Collection containing references to each ChargeCode bean that has the specified project as its parent.*/ public Collection findByProject(long projectId) throws FinderException; /** Answers a local reference to the ChargeCode bean. */ public ChargeCodeLocal findByName(String projectName, String Æ chargeCodeName) throws FinderException; /** Answers a local reference to the ChargeCode bean, if it exists. */ 8 ChargeCodeEntityBean 267783 WS02.qxd 5/5/03 9:17 AM Page 8 public ChargeCodeLocal findByPrimaryKey(ChargeCodePK key) throws Æ FinderException; /** Answers a local reference to the newly created ChargeCode bean. */ public ChargeCodeLocal create(long id, String name, String Æ description, ProjectLocal project) throws Æ CreateException; } ChargeCodeBean.java ChargeCodeBean.java is the implementation class for the ChargeCode entity bean. It provides the data and logic for the bean. Again, there is not much to it. Each Charge- Code entity bean holds an ID, a name, a description, and a reference to the project entity bean to which it belongs. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*; import java.util.*; import java.rmi.*; import javax.ejb.*; import javax.naming.*; /** * The ChargeCode bean holds descriptive information about a billable * charge code. Since each ChargeCode is part of a larger project, the * parent project can be accessed from the charge code. * ChargeCodeBean is the actual entity bean implementation. */ public abstract class ChargeCodeBean extends BasicEntityBean Æ implements ChargeCodeInt { /** CMP fields */ public abstract long getId(); public abstract void setId(long id); public abstract String getName(); public abstract void setName(String name); public abstract String getDescription(); public abstract void setDescription(String desc); /** CMR fields*/ public abstract ProjectLocal getProject(); public abstract void setProject(ProjectLocal project); public ChargeCodeBean() { } ChargeCodeEntityBean 9 267783 WS02.qxd 5/5/03 9:17 AM Page 9 . OMG PRESS CT Arrington, Syed Rayhan Enterprise Java 2nd Edition ™ UML ™ and 1 TimeEntryInt .java TimeEntryLocal .java is the local interface for the TimeEntry entity bean This is shown in Figure 01. Figure 01 Local interface of the TimeEntry entity bean. package com.wiley.compBooks.EJwithUML.TimeCardDomain; import java. util.*; import javax.ejb.*; /** * The TimeEntryInt. TimeEntryEntityBean 267783 WS 01. qxd 5/5/03 9 :17 AM Page 2 TimeEntrytLocalHome .java TimeEntryLocalHome .java is the Home interface for the TimeEntry entity bean. It defines the methods for finding and creating

Ngày đăng: 12/08/2014, 16:21

Từ khóa liên quan

Mục lục

  • Enterprise Java and UML, 2nd Edition

    • TimeEntryEntityBean

    • ChargeCodeEntityBean

Tài liệu cùng người dùng

Tài liệu liên quan