001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/tool-lib/src/java/org/theospi/portfolio/list/tool/DecoratedEntry.java $
003: * $Id: DecoratedEntry.java 11372 2006-06-29 14:58:30Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 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.theospi.portfolio.list.tool;
021:
022: import java.lang.reflect.InvocationTargetException;
023: import java.util.HashMap;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.commons.beanutils.PropertyUtils;
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.theospi.portfolio.list.intf.ListService;
031: import org.theospi.portfolio.shared.model.OspException;
032:
033: public class DecoratedEntry {
034: protected final transient Log logger = LogFactory
035: .getLog(getClass());
036:
037: private Object entry;
038: private ListService service;
039: private ListTool parent;
040:
041: public DecoratedEntry(Object entry, ListService service,
042: ListTool parent) {
043: this .entry = entry;
044: this .service = service;
045: this .parent = parent;
046: }
047:
048: public Object getEntry() {
049: return entry;
050: }
051:
052: public void setEntry(Object entry) {
053: this .entry = entry;
054: }
055:
056: public String getEntryLink() {
057: return getService().getEntryLink(getEntry());
058: }
059:
060: public ListService getService() {
061: return service;
062: }
063:
064: public void setService(ListService service) {
065: this .service = service;
066: }
067:
068: public String getRedirectUrl() {
069: String link = getService().getEntryLink(getEntry());
070:
071: return link;
072: }
073:
074: public Map getColumnValues() {
075: return new ColumnValuesMap();
076: }
077:
078: public boolean isNewWindow() {
079: return getService().isNewWindow(getEntry());
080: }
081:
082: private class ColumnValuesMap extends HashMap {
083:
084: /**
085: * Returns the value associated with the given key
086: *
087: * @return the value associated with the given key
088: */
089: public Object get(Object key) {
090: int index = Integer.parseInt(key.toString());
091:
092: List current = parent.getCurrentConfig()
093: .getSelectedColumns();
094:
095: if (current.size() <= index) {
096: return null;
097: }
098:
099: String name = (String) current.get(index);
100:
101: try {
102: return PropertyUtils.getNestedProperty(entry, name);
103: } catch (IllegalAccessException e) {
104: logger.error("", e);
105: throw new OspException(e);
106: } catch (InvocationTargetException e) {
107: logger.error("", e);
108: throw new OspException(e);
109: } catch (NoSuchMethodException e) {
110: logger.error("", e);
111: throw new OspException(e);
112: }
113: } //-- get
114: }
115: }
|