001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/samples/tags/sakai_2-4-1/sample-tool-jsf/src/java/org/sakaiproject/sample/tool/ItemServiceImpl.java $
003: * $Id: ItemServiceImpl.java 17085 2006-10-12 19:38:14Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.sample.tool;
021:
022: import java.util.Collection;
023: import java.util.Vector;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.thread_local.api.ThreadLocalManager;
028:
029: /**
030: * Implementation of the ItemService example service.
031: */
032: public class ItemServiceImpl implements ItemService {
033: /** Our log. */
034: private static Log M_log = LogFactory.getLog(ItemServiceImpl.class);
035:
036: protected ThreadLocalManager m_threadLocalManager = null;
037:
038: public void setThreadLocalManager(ThreadLocalManager manager) {
039: m_threadLocalManager = manager;
040: }
041:
042: protected ThreadLocalManager threadLocalManager() {
043: return m_threadLocalManager;
044: }
045:
046: /**
047: * Implementation of Item
048: */
049: public class MyItem implements Item {
050: protected String id;
051:
052: protected String a;
053:
054: protected String b;
055:
056: protected String c;
057:
058: public MyItem(String id, String a, String b, String c) {
059: this .id = id;
060: this .a = a;
061: this .b = b;
062: this .c = c;
063: }
064:
065: public String getA() {
066: return a;
067: }
068:
069: public String getB() {
070: return b;
071: }
072:
073: public String getC() {
074: return c;
075: }
076:
077: public String getId() {
078: return id;
079: }
080:
081: public void setA(String a) {
082: this .a = a;
083: }
084:
085: public void setB(String b) {
086: this .b = b;
087: }
088:
089: public void setC(String c) {
090: this .c = c;
091: }
092:
093: public void setId(String id) {
094: this .id = id;
095: }
096: }
097:
098: public void init() {
099: M_log.info("init");
100: }
101:
102: public Collection getItems() {
103: M_log.info("getItems");
104:
105: Collection items = new Vector();
106: items.add(getItem("1"));
107: items.add(getItem("2"));
108: items.add(getItem("3"));
109:
110: return items;
111: }
112:
113: public Item getItem(String id) {
114: // cache for the request
115: Item cached = (Item) threadLocalManager().get(
116: "ItemService:" + id);
117: if (cached != null)
118: return cached;
119:
120: M_log.info("getItem: " + id);
121:
122: Item rv = null;
123:
124: if (id.equals("1")) {
125: rv = new MyItem("1", "a", "b", "c");
126: } else if (id.equals("2")) {
127: rv = new MyItem("2", "a2", "b2", "c2");
128: } else if (id.equals("3")) {
129: rv = new MyItem("3", "a3", "b3", "c3");
130: }
131:
132: // cache
133: if (rv != null) {
134: threadLocalManager().set("ItemService:" + id, rv);
135: }
136:
137: return rv;
138: }
139: }
|