001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.entityproperties;
007:
008: import org.jasig.portal.ChannelDefinition;
009: import org.jasig.portal.ChannelRegistryStoreFactory;
010: import org.jasig.portal.EntityIdentifier;
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013:
014: /**
015: * A finder implementation to provide channel properties derived from the
016: * ChannelRegistryManager
017: *
018: * @author Alex Vigdor av317@columbia.edu
019: * @version $Revision: 34797 $
020: */
021: public class ChannelRegistryPropertyFinder implements
022: IEntityPropertyFinder {
023:
024: private static final Log log = LogFactory
025: .getLog(ChannelRegistryPropertyFinder.class);
026:
027: protected static String[] names;
028: protected static Class chan = null;
029: protected static boolean INITIALIZED = false;
030:
031: /**
032: * Lazily initialize the static variables.
033: */
034: public static void init() {
035: if (INITIALIZED) {
036: return;
037: }
038: /* this array should hold the desired attributes of a channel element
039: as defined in channelRegistry.dtd
040: */
041: names = new String[5];
042: names[0] = "Name";
043: names[1] = "Title";
044: names[2] = "Description";
045: names[3] = "Functional Name";
046: names[4] = "Timeout";
047: try {
048: chan = Class.forName("org.jasig.portal.ChannelDefinition");
049: } catch (Exception e) {
050: log.error("ChannelRegistryPropertyFinder - static:", e);
051: }
052: INITIALIZED = true;
053: }
054:
055: public ChannelRegistryPropertyFinder() {
056: init();
057: }
058:
059: public String[] getPropertyNames(EntityIdentifier entityID) {
060: return names;
061: }
062:
063: public String getProperty(EntityIdentifier entityID, String name) {
064: String r = null;
065: if (entityID.getType().equals(chan)) {
066: try {
067: //Element c = ChannelRegistryManager.getChannel("chan"+entityID.getKey());
068: //r = c.getAttribute(name);
069: ChannelDefinition cd = ChannelRegistryStoreFactory
070: .getChannelRegistryStoreImpl()
071: .getChannelDefinition(
072: Integer.parseInt(entityID.getKey()));
073: if (name.equals("Name")) {
074: r = cd.getName();
075: }
076: if (name.equals("Title")) {
077: r = cd.getTitle();
078: }
079: if (name.equals("Description")) {
080: r = cd.getDescription();
081: }
082: if (name.equals("Functional Name")) {
083: r = cd.getFName();
084: }
085: if (name.equals("Timeout")) {
086: r = String.valueOf(cd.getTimeout());
087: }
088: if (name.equals("Secure")) {
089: r = String.valueOf(cd.isSecure());
090: }
091: } catch (Exception e) {
092: log.error("ChannelRegistryPropertyFinder.getProperty("
093: + entityID.getKey() + "-"
094: + entityID.getType().getName() + "," + name
095: + ") :", e);
096: }
097: }
098: return r;
099: }
100: }
|