001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)PropertiesUpdater.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extpropertysheet.ui;
030:
031: import org.openesb.tools.extpropertysheet.IExtProperty;
032: import org.openesb.tools.extpropertysheet.IExtPropertyGroup;
033: import org.openesb.tools.extpropertysheet.IExtPropertyGroupsBean;
034: import org.openesb.tools.extpropertysheet.ui.convertor.PropertyValueConvertor;
035: import com.sun.web.ui.component.TabSet;
036: import java.util.Collection;
037: import java.util.HashMap;
038: import java.util.Iterator;
039: import java.util.logging.Logger;
040: import javax.faces.component.UIComponent;
041: import javax.faces.component.UIInput;
042:
043: /**
044: *
045: * @author rdwivedi
046: */
047: public class PropertiesUpdater {
048: private static Logger mLogger = Logger
049: .getLogger(PropertiesUpdater.class.getName());
050:
051: /** Creates a new instance of PropertiesUpdater */
052: public PropertiesUpdater() {
053: }
054:
055: private void populateUIObjectMap(UIComponent comp, HashMap map) {
056: if (comp.getChildCount() > 0) {
057: Iterator iter = comp.getChildren().iterator();
058: while (iter.hasNext()) {
059: UIComponent compa = (UIComponent) iter.next();
060: map.put(compa.getId(), compa);
061: populateUIObjectMap(compa, map);
062: }
063: }
064: }
065:
066: public void updateChartProperties(TabSet mTS,
067: IExtPropertyGroupsBean b) {
068: HashMap propComponents = new HashMap();
069: populateUIObjectMap(mTS, propComponents);
070: mLogger.info("The size of saved comp " + propComponents.size());
071: if (b != null) {
072: Collection col = b.getAllGroups();
073: if (col != null) {
074: Iterator iter = col.iterator();
075: while (iter.hasNext()) {
076: IExtPropertyGroup g = (IExtPropertyGroup) iter
077: .next();
078: updateChartProperties(g, propComponents);
079: }
080: }
081:
082: }
083: }
084:
085: private void updateChartProperties(IExtPropertyGroup pg,
086: HashMap propComponents) {
087: Collection col = pg.getAllProperties();
088: Iterator iter = col.iterator();
089: IExtProperty prop = null;
090: while (iter.hasNext()) {
091: prop = (IExtProperty) iter.next();
092: String id = prop.getName();
093: String valFromReq = null;
094: Object obj = propComponents.get(id);
095: //mLogger.info("The component recived is " + obj + " for id " + id);
096: if (obj != null) {
097: if (obj instanceof UIInput) {
098: UIInput f = (UIInput) obj;
099: Object o = f.getValue();
100: if (o != null) {
101: valFromReq = f.getValue().toString();
102: }
103:
104: if (valFromReq == null) {
105: mLogger
106: .info("The new value is null so ignoring update");
107: } else {
108: Object val = PropertyValueConvertor
109: .getValueConvertor(prop.getType())
110: .getObjectFromString(valFromReq,
111: prop.getType());
112: prop.setValue(val);
113: }
114: }
115: }
116: mLogger.info("The new value is " + valFromReq
117: + " for comp name = " + id);
118:
119: }
120: }
121:
122: }
|