001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.saas.ui.wizards;
043:
044: import java.net.URLClassLoader;
045: import java.util.List;
046: import javax.swing.tree.DefaultMutableTreeNode;
047: import org.openide.ErrorManager;
048:
049: /**
050: *
051: * @author David Botterill
052: */
053: public class StructureTypeTreeNode extends AbstractParameterTreeNode {
054: private URLClassLoader urlClassLoader;
055:
056: public StructureTypeTreeNode(TypeNodeData userObject,
057: URLClassLoader inClassLoader) {
058: super (userObject);
059: urlClassLoader = inClassLoader;
060:
061: }
062:
063: /**
064: * This method will use the parameter name of the child to update the value of this Structure.
065: * @param inData - the TypeNodeData of the child that called this method.
066: */
067: public void updateValueFromChildren(TypeNodeData inData) {
068: TypeNodeData data = (TypeNodeData) this .getUserObject();
069: try {
070: Object structObject = data.getTypeValue();
071: String propType = inData.getTypeClass();
072: String propName = inData.getTypeName();
073: Object propObject = inData.getTypeValue();
074:
075: ReflectionHelper.setPropertyValue(structObject, propName,
076: propType, propObject, urlClassLoader);
077: } catch (WebServiceReflectionException wsfe) {
078: Throwable cause = wsfe.getCause();
079: ErrorManager.getDefault().notify(cause);
080: ErrorManager
081: .getDefault()
082: .log(
083: this .getClass().getName()
084: + ": Error trying to update Children of a Structure on: "
085: + data.getRealTypeName()
086: + "WebServiceReflectionException="
087: + cause);
088:
089: }
090: /**
091: * If this node is a member of a structure type, update it's parent.
092: */
093: DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) this
094: .getParent();
095: if (parentNode != null
096: && parentNode instanceof ParameterTreeNode) {
097: ((ParameterTreeNode) parentNode)
098: .updateValueFromChildren(data);
099:
100: }
101: }
102:
103: /**
104: * Update the child nodes based on the value of this UserObject.
105: * Fix for Bug: 5059732
106: * - David Botterill 8/12/2004
107: *
108: */
109: public void updateChildren() {
110: TypeNodeData data = (TypeNodeData) this .getUserObject();
111: Object structObj = data.getTypeValue();
112: if (structObj == null)
113: return;
114:
115: try {
116: String type = data.getTypeClass();
117: List<String> fields = ReflectionHelper.getPropertyNames(
118: type, urlClassLoader);
119:
120: for (int i = 0; i < fields.size(); i++) {
121: String fieldName = fields.get(i);
122: String fieldType = ReflectionHelper.getPropertyType(
123: type, fieldName, urlClassLoader);
124: Object newChildValue = ReflectionHelper
125: .getPropertyValue(structObj, fieldName,
126: urlClassLoader);
127:
128: DefaultMutableTreeNode currentChildNode = null;
129: if (i >= this .getChildCount()) {
130: TypeNodeData childData = ReflectionHelper
131: .createTypeData(fieldType, fieldName);
132: Object defaultChildValue = NodeHelper.getInstance()
133: .getParameterDefaultValue(childData);
134: childData.setTypeValue(defaultChildValue);
135:
136: currentChildNode = NodeHelper.getInstance()
137: .createNodeFromData(childData);
138: this .add(currentChildNode);
139:
140: } else {
141: currentChildNode = (DefaultMutableTreeNode) this
142: .getChildAt(i);
143: }
144:
145: TypeNodeData childData = (TypeNodeData) currentChildNode
146: .getUserObject();
147:
148: childData.setTypeValue(newChildValue);
149: currentChildNode.setUserObject(childData);
150:
151: if (currentChildNode instanceof ParameterTreeNode) {
152: ((ParameterTreeNode) currentChildNode)
153: .updateChildren();
154: }
155: }
156: } catch (WebServiceReflectionException wsfe) {
157: Throwable cause = wsfe.getCause();
158: ErrorManager.getDefault().notify(cause);
159: ErrorManager
160: .getDefault()
161: .log(
162: this .getClass().getName()
163: + ": Error trying to update Children of a Structure on: "
164: + data.getRealTypeName()
165: + "WebServiceReflectionException="
166: + cause);
167: }
168:
169: }
170: }
|