⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib0071.html

📁 java外企软件工程师就业班 J2EE方向 《J2EE架构师手册》 电子书
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Architect's Exercise: ProjectTrak</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0070.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0072.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch10"></a>
<div class="section">
<h2 class="first-section-title"><a name="332"></a><a name="ch10lev1sec4"></a>Architect's Exercise: ProjectTrak</h2><p class="first-para">For the ProjectTrak application, which we've been working on in the "Architect's Exercises" throughout this book, we will use CementJ and its <span class="fixed">ValueObject</span> for all value objects. <a class="internaljump" href="#ch10ex10">Listing 10.10</a> has code from the <span class="fixed">ProjectVO</span> class of ProjectTrak. You may recall that we identified this object in <a href="LiB0038.html#184" target="_parent" class="chapterjump">chapter 6</a>.</p>
<div class="example">
<span class="example-title"><span class="example-titlelabel">Listing 10.10: </span>Sample ProjectVO Class from ProjectTrak</span><a name="333"></a><a name="ch10ex10"></a>
<div class="formalbody">
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="Start example" border="0"></b></font></td>
</tr>
</table>
<div class="informalexample">
<pre class="literallayout">
   1:package com.dvt.app.project.vo;
   2:
   3:import org.cementj.base.ValueObject;
   4:import java.util.Date;
   5:import java.io.Serializable;
   6:
   7:/**
   8: * VO representing information about a project.  This
   9: * class is part of the ProjectTrak application.
  10: * &lt;p&gt;Copyright:  Delta Vortex Technologies, 2003.
  11: */
  12:public class ProjectVO
  13:    extends ValueObject
  14:    implements Serializable, Comparable
  15:{
  16:
  17:  public ProjectVO() {}<a name="334"></a><a name="IDX-135"></a>
  18:
  19:  public String getProjectName()
  20:  {
  21:      return _projectName;
  22:  }
  23:  public void setProjectName(String name)
  24:  {
  25:    if (name == null)
  26:    {
  27:        throw new IllegalArgumentException
  28:                ("Null project name not allowed.");
  29:    }
  30:    if (name.equals(""))
  31:    {
  32:        throw new IllegalArgumentException
  33:                ("Blank project name not allowed.");
  34:    }
  35:    _projectName = name;
  36:  }
  37:
  38:  public String[] getProjectBaselineNames()
  39:  {
  40:      return _projectBaselines;
  41:  }
  42:  public void setProjectBaselineNames(String[] name)
  43:  {
  44:    _projectBaselines = name;
  45:  }
  46:
  47:  public Date getDateCreated()
  48:  {
  49:      return _dateCreated;
  50:  }
  51:  public void setDateCreated(Date dateCreated)
  52:  {
  53:    if (dateCreated == null)
  54:    {
  55:        throw new IllegalArgumentException
  56:                ("Null dateCreated not allowed.");
  57:    }
  58:    _dateCreated = dateCreated;
  59:  }
  60:
  61:  public Date getDateModified()
  62:  {
  63:      return _dateLastModified;
  64:  }
  65:  public void setDateModified(Date dateLastModified)
  66:  {<a name="335"></a><a name="IDX-136"></a>
  67:    if (dateLastModified == null)
  68:    {
  69:        throw new IllegalArgumentException
  70:                ("Null dateLastModified not allowed.");
  71:    }
  72:    _dateLastModified = dateLastModified;
  73:  }
  74:
  75:  public Date getProjectStart()
  76:  {
  77:      return _projectStart;
  78:  }
  79:  public void setProjectStart(Date start)
  80:  {
  81:    _projectStart = start;
  82:  }
  83:
  84:  public Date getProjectEnd()
  85:  {
  86:      return _projectEnd;
  87:  }
  88:  public void setProjectEnd(Date end)
  89:  {
  90:    _projectEnd = end;
  91:  }
  92:
  93:  public ResourceVO[] getAssignedResources()
  94:  {
  95:      return _assignedResources;
  96:  }
  97:  public void setAssignedResources(
  98:                      ResourceVO[] assignedResources)
  99:  {
 100:   if (assignedResources == null)
 101:   {
 102:       throw new IllegalArgumentException
 103:             ("Null assignedResources not allowed.");
 104:   }
 105:   _assignedResources = assignedResources;
 106:  }
 107:
 108:  public ProjectTaskVO[] getProjectTasks()
 109:  {
 110:      return _projectTasks;
 111:  }
 112:  public void setProjectTasks(
 113:                          ProjectTaskVO[] projectTasks)
 114:  {
 115:    if (projectTasks == null)<a name="336"></a><a name="IDX-137"></a>
 116:    {
 117:        throw new IllegalArgumentException
 118:                ("Null projectTasks not allowed.");
 119:    }
 120:    _projectTasks = projectTasks;
 121:  }
 122:
 123:  public int compareTo(Object obj)
 124:  {
 125:      int comparator = 0;
 126:       if (obj == null)
 127:       {
 128:           throw new IllegalArgumentException
 129:               ("Null object not allowed.");
 130:       }
 131:     if (! (obj instanceof ProjectVO))
 132:     {
 133:         throw new IllegalArgumentException
 134:             ( "Invalid Object Type: " +
 135:              obj.getClass().getName());
 136:     }
 137:
 138:     ProjectVO pvo = (ProjectVO) obj;
 139:     comparator = _projectName.compareTo(
 140:                        pvo._projectName);
 141:     if (comparator == 0)
 142:     {
 143:        comparator = _dateLastModified.compareTo(
 144:                           pvo._dateLastModified);
 145:     }
 146:
 147:     return comparator;
 148:  }
 149:
 150:  private String            _projectName = null;
 151:  private String[]          _projectBaselines = null;
 152:  private Date              _dateCreated = null;
 153:  private Date              _dateLastModified = null;
 154:  private ResourceVO[]     _assignedResources = null;
 155:  private ProjectTaskVO[]  _projectTasks = null;
 156:  private Date              _projectStart = null;
 157:  private Date              _projectEnd = null;
 158:
 159:}
</pre>
</div>
<p class="last-para">
<i class="emphasis">Source</i>: /src/com/dvt/app/project/vo/ProjectVO.java</p>
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="End example" border="0"></b></font></td>
</tr>
</table>
<table class="BlankSpace" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="16"></td>
</tr>
</table>
</div>
</div>
<p class="para">In addition to implementing all the coding recommendations presented in this chapter, I suggest you check the arguments to mutators to catch illegal variable assignments early. This practice reduces the likelihood that you'll get a derivative <span class="fixed">NullPointerException</span> of something else that's relatively time consuming to debug.</p>
<a name="337"></a><a name="IDX-138"></a>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0070.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0072.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -