001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.presentation.portlet.session.ui;
051:
052: import org.jaffa.presentation.portlet.FormBase;
053: import org.jaffa.presentation.portlet.widgets.model.TreeModel;
054: import org.jaffa.presentation.portlet.widgets.model.WidgetModel;
055: import org.jaffa.presentation.portlet.widgets.controller.TreeController;
056: import org.apache.log4j.Logger;
057: import org.jaffa.presentation.portlet.widgets.model.GridModel;
058: import org.jaffa.presentation.portlet.widgets.controller.GridController;
059: import org.jaffa.presentation.portlet.session.UserSession;
060: import org.jaffa.presentation.portlet.widgets.model.GridModelRow;
061: import org.jaffa.presentation.portlet.session.SessionManager;
062: import java.util.Iterator;
063: import org.jaffa.presentation.portlet.component.Component;
064: import java.util.HashMap;
065: import org.jaffa.config.Config;
066: import org.jaffa.datatypes.DateTime;
067: import org.jaffa.datatypes.Formatter;
068: import java.beans.PropertyDescriptor;
069: import java.beans.BeanInfo;
070: import java.beans.Introspector;
071: import java.util.Map;
072: import org.jaffa.presentation.portlet.widgets.controller.UserGridController;
073:
074: /**
075: *
076: * @author PaulE
077: * @version 1.0
078: */
079: public class ComponentExplorerForm extends FormBase {
080:
081: private static Logger log = Logger
082: .getLogger(ComponentExplorerForm.class);
083:
084: public static final String NAME = "jaffa_componentExplorerForm";
085:
086: private GridModel w_components = null;
087: private GridModel w_userData = null;
088:
089: /** Holds value of property id. */
090: private String id;
091:
092: /** Holds value of property host. */
093: private String host;
094:
095: /** Holds value of property userId. */
096: private String userId;
097:
098: private UserSession m_userSession = null;
099:
100: public void initForm() {
101: String sessionId = ((SessionExplorerComponent) getComponent())
102: .getSessionId();
103: m_userSession = SessionManager.getSession(sessionId);
104: // Blank out the widgets so it will re-generate them
105: w_components = null;
106: getWidgetCache().addModel("components", null);
107: w_userData = null;
108: getWidgetCache().addModel("userData", null);
109: }
110:
111: public GridModel getComponentListWM() {
112: if (w_components == null) {
113: w_components = (GridModel) getWidgetCache().getModel(
114: "components");
115: if (w_components == null) {
116: w_components = getComponentsModel();
117: getWidgetCache().addModel("components", w_components);
118: }
119: }
120: return w_components;
121: }
122:
123: public void setComponentListWV(String value) {
124: UserGridController.updateModel(value, getComponentListWM(),
125: this );
126: }
127:
128: private GridModel getComponentsModel() {
129: GridModel model = new GridModel();
130: HashMap parents = new HashMap();
131: long time = System.currentTimeMillis();
132:
133: if (m_userSession.getComponents() != null)
134: for (Iterator i = m_userSession.getComponents().iterator(); i
135: .hasNext();) {
136: Component c = (Component) i.next();
137:
138: GridModelRow row = model.newRow();
139: parents.put(c.getComponentId(), row);
140: row.addElement("ID", c.getComponentId());
141: row.addElement("NAME", c.getComponentDefinition()
142: .getComponentName());
143: row.addElement("LAST_ACCESS", Formatter.format(c
144: .returnLastActivityDate()));
145: row.addElement("IDLE", ((time - c
146: .returnLastActivityDate().getTime()) / 1000)
147: + "");
148: row
149: .addElement(
150: "TIMEOUT",
151: Config
152: .getProperty(
153: Config.PROP_PRESENTATION_COMPONENT_GARBAGE_COLLECTION_TIME_OUT_IN_MINUTES,
154: "Undefined"));
155: }
156:
157: // Find parents for all components
158: if (model.getRows() != null)
159: for (Iterator i = model.getRows().iterator(); i.hasNext();) {
160: GridModelRow row = (GridModelRow) i.next();
161: String id = (String) row.getElement("ID");
162: Component c = m_userSession.getComponent(id);
163: if (c.returnChildComponents() != null)
164: for (Iterator i2 = c.returnChildComponents()
165: .iterator(); i2.hasNext();) {
166: Component childComp = (Component) i2.next();
167: // Find this row in the grid, and set its parent
168: GridModelRow child = (GridModelRow) parents
169: .get(childComp.getComponentId());
170: child.addElement("PARENT_ID", id);
171: }
172: }
173:
174: return model;
175: }
176:
177: /** Getter for property id.
178: * @return Value of property id.
179: */
180: public String getId() {
181: return m_userSession.getSessionId();
182: }
183:
184: /** Getter for property host.
185: * @return Value of property host.
186: */
187: public String getHost() {
188: return m_userSession.getUserHostAddr();
189: }
190:
191: /** Getter for property userId.
192: * @return Value of property userId.
193: */
194: public String getUserId() {
195: return m_userSession.getUserId();
196: }
197:
198: public GridModel getUserDataWM() {
199: if (w_userData == null) {
200: w_userData = (GridModel) getWidgetCache().getModel(
201: "userData");
202: if (w_userData == null) {
203: w_userData = getUserDataModel();
204: getWidgetCache().addModel("userData", w_userData);
205: }
206: }
207: return w_userData;
208: }
209:
210: public void setUserDataWV(String value) {
211: GridController.updateModel(value, getUserDataWM());
212: }
213:
214: private GridModel getUserDataModel() {
215: GridModel model = new GridModel();
216:
217: Object userData = m_userSession.getUserData();
218: if (userData == null)
219: return model;
220:
221: // Introspect the User Data Object Now...
222: try {
223: BeanInfo beanInfo = Introspector.getBeanInfo(userData
224: .getClass());
225: PropertyDescriptor[] descriptors = beanInfo
226: .getPropertyDescriptors();
227: if (descriptors != null && descriptors.length != 0)
228: for (int i = 0; i < descriptors.length; i++) {
229: PropertyDescriptor desc = descriptors[i];
230: GridModelRow row = model.newRow();
231: row.addElement("NAME", desc.getName());
232: row.addElement("CLASS", desc.getPropertyType());
233: row.addElement("VALUE", desc.getReadMethod()
234: .invoke(userData, new Object[0]));
235: }
236: } catch (Exception e) {
237: log.error("Can't Introspect UserData Object", e);
238: }
239: return model;
240: }
241:
242: public String getUserDataClass() {
243: if (m_userSession.getUserData() == null)
244: return "None";
245: else
246: return m_userSession.getUserData().getClass().getName();
247: }
248: }
|