1 package org.unitedfront2.domain.communication;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.unitedfront2.domain.DomainFactory;
6
7 /**
8 * ブログ記事のファクトリクラスです。
9 *
10 * @author kurokkie
11 *
12 */
13 public class BlogEntryTable {
14
15 /** ログ */
16 protected final Log logger = LogFactory.getLog(getClass());
17
18 /** メッセージテーブル */
19 private MessageTable messageTable;
20
21 /** ドメインファクトリ */
22 private DomainFactory domainFactory;
23
24 /**
25 * ブログ記事を取得します。
26 *
27 * @param id ブログ記事 ID
28 * @return ブログ記事
29 */
30 public BlogEntry find(int id) {
31 Message entry = messageTable.find(id);
32 if (entry == null) {
33 return null;
34 }
35 return domainFactory.prototype(new BlogEntry(entry));
36 }
37
38 /**
39 * ブログ記事を取得します。
40 *
41 * @param id ブログ記事 ID
42 * @return ブログ記事
43 * @throws IllegalArgumentException 指定した ID が存在しない。
44 */
45 public BlogEntry get(int id) throws IllegalArgumentException {
46 BlogEntry entry = find(id);
47 if (entry == null) {
48 String message = "The blog entry ID '" + id + "' not found.";
49 logger.error(message);
50 throw new IllegalArgumentException(message);
51 }
52 return entry;
53 }
54
55 /**
56 * 記事コードを持つブログ記事を取得します。
57 *
58 * @param code 記事コード(メッセージコード)
59 * @return ブログ記事、見つからなければ <code>null</code>
60 */
61 public BlogEntry findByCode(String code) {
62 Message entry = messageTable.findByCode(code);
63 if (entry == null) {
64 return null;
65 }
66 return domainFactory.prototype(new BlogEntry(entry));
67 }
68
69 public void setMessageTable(MessageTable messageTable) {
70 this.messageTable = messageTable;
71 }
72
73 public void setDomainFactory(DomainFactory domainFactory) {
74 this.domainFactory = domainFactory;
75 }
76 }