1 16 17 package org.apache.cocoon.samples.tour.beans; 18 19 import java.util.LinkedList ; 20 import java.util.Date ; 21 import java.util.List ; 22 import java.util.Iterator ; 23 24 28 29 public class DatabaseFacade { 30 31 private static final DatabaseFacade m_instance = new DatabaseFacade(); 32 33 34 private final LinkedList m_tasks = new LinkedList (); 35 36 37 final String title [] = { 38 "Design DB interface", 39 "Load test data", 40 "User interface design", 41 "Usability test", 42 "Market acceptance study", 43 "Investors demo", 44 "Public press release", 45 "TV interview", 46 "Local radio interview", 47 "Location shooting for promo video", 48 "Government group demo", 49 "Test users screening", 50 "Promo video casting", 51 "Promo video editing", 52 "Audio sweetening", 53 "Sound design", 54 "Games rules evaluation" 55 }; 56 57 58 final String name [] = { 59 "Donald Duck", 60 "Miles Davis", 61 "Leonardo DaVinci", 62 "Rodney Curtis", 63 "Foad Zee" 64 }; 65 66 67 final String commentText [] = { 68 "Revised with management", 69 "Checked budget", 70 "Called Mr.Smith about it, he's ok with the current state", 71 "Asked Fred Flintstone for a budget extension", 72 "Looked at the planning, logistics says we won't make it" 73 }; 74 75 private DatabaseFacade() { 76 loadTestData(); 77 } 78 79 public static DatabaseFacade getInstance() { 80 return m_instance; 81 } 82 83 84 public List getTasks() { 85 return m_tasks; 86 } 87 88 89 public TaskBean getTaskBeanById(int id) throws Exception { 90 TaskBean result = null; 92 for(Iterator it=m_tasks.iterator(); it.hasNext(); ) { 93 final TaskBean tb = (TaskBean)it.next(); 94 if(tb.getId() == id) { 95 result = tb; 96 break; 97 } 98 } 99 100 if(result == null) { 101 throw new Exception ("Not found: TaskBean having id=" + id); 102 } 103 return result; 104 } 105 106 107 private void loadTestData() { 108 for(int i=0; i < title.length; i++) { 109 m_tasks.add(generateTask(title[i],i)); 110 } 111 } 112 113 114 private TaskBean generateTask(String title,int index) { 115 final TaskBean tb = new TaskBean(); 116 tb.setTaskName(title); 117 tb.setAssignedTo(name[index % name.length]); 118 119 final int nComments = (int)(Math.random() * 20); 120 final long MSEC_OFFSET = (1000L * 3600L * 24L) + (1000L * 60 * 12); 121 long timestamp = new Date ().getTime() - nComments * MSEC_OFFSET; 122 for(int i=0; i < nComments; i++) { 123 final TaskCommentBean tcb = new TaskCommentBean(); 124 tcb.setDate(new Date (timestamp)); 125 tcb.setComment(commentText[i % commentText.length]); 126 tb.addComment(tcb); 127 timestamp += MSEC_OFFSET; 128 } 129 130 return tb; 131 } 132 133 134 public String getVersion() { 135 return "$Id: DatabaseFacade.java 30932 2004-07-29 17:35:38Z vgritsenko $"; 136 } 137 } 138 | Popular Tags |