01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.channels.groupsmanager.commands;
07:
08: import org.jasig.portal.EntityIdentifier;
09: import org.jasig.portal.channels.groupsmanager.CGroupsManagerSessionData;
10: import org.jasig.portal.channels.groupsmanager.GroupsManagerXML;
11: import org.jasig.portal.services.EntityPropertyRegistry;
12: import org.w3c.dom.Document;
13: import org.w3c.dom.Element;
14:
15: /**
16: * A Groups Manager command to expose properties from the EntityPropertyRegistry
17: * for any entity or group
18: *
19: * @author Alex Vigdor
20: * @version $Revision: 36797 $
21: */
22:
23: public class ShowProperties extends GroupsManagerCommand {
24:
25: public ShowProperties() {
26: }
27:
28: /**
29: * put your documentation comment here
30: * @param sessionData
31: * @throws Exception
32: */
33: public void execute(CGroupsManagerSessionData sessionData)
34: throws Exception {
35: Document model = getXmlDoc(sessionData);
36: String id = this .getCommandArg(sessionData.runtimeData);
37: Element e = GroupsManagerXML.getElementById(model, id);
38: if (e != null) {
39: if (e.getElementsByTagName(PROPERTIES_TAGNAME) != null
40: && e.getElementsByTagName(PROPERTIES_TAGNAME)
41: .getLength() > 0)
42: return;
43: Element props = model.createElement(PROPERTIES_TAGNAME);
44: EntityIdentifier ei = null;
45: try {
46: ei = new EntityIdentifier(e.getAttribute("key"), Class
47: .forName(e.getAttribute("type")));
48: } catch (ClassNotFoundException ce) {
49: throw new RuntimeException(
50: "Unable to instantiate class: type "
51: + e.getAttribute("type") + " unknown");
52: }
53: String[] names = EntityPropertyRegistry
54: .getPropertyNames(ei);
55: //System.out.println("Found "+names.length+" properties");
56: for (int i = 0; i < names.length; i++) {
57: Element prop = model.createElement("property");
58: prop.setAttribute("name", names[i]);
59: prop.setAttribute("value", EntityPropertyRegistry
60: .getProperty(ei, names[i]));
61: props.appendChild(prop);
62: }
63: e.appendChild(props);
64: }
65: }
66: }
|