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: package org.netbeans.modules.sun.manager.jbi.nodes;
042:
043: import com.sun.esb.management.common.ManagementRemoteException;
044: import com.sun.jbi.ui.common.JBIComponentInfo;
045: import com.sun.jbi.ui.common.ServiceAssemblyInfo;
046: import com.sun.jbi.ui.common.ServiceUnitInfo;
047: import org.netbeans.modules.sun.manager.jbi.management.JBIComponentType;
048: import java.util.List;
049: import org.netbeans.modules.sun.manager.jbi.management.AppserverJBIMgmtController;
050: import org.netbeans.modules.sun.manager.jbi.management.wrapper.api.RuntimeManagementServiceWrapper;
051: import org.openide.DialogDisplayer;
052: import org.openide.NotifyDescriptor;
053: import org.openide.nodes.Children;
054: import org.openide.nodes.Node;
055:
056: /**
057: *
058: *
059: */
060: public class JBIContainerChildFactory {
061:
062: private AppserverJBIMgmtController controller;
063:
064: /**
065: * Public constructor for factory used to create the children of a given
066: * NodeType.
067: *
068: * @param controller The AppserverMgmtController used as an interface to
069: * the AMX API necessary for determining the existence of certain
070: * components such as resources, apps, etc. on the server.
071: */
072: public JBIContainerChildFactory(
073: AppserverJBIMgmtController controller) {
074: this .controller = controller;
075: }
076:
077: /**
078: * Creates the children for a given NodeType.
079: *
080: * @param type The NodeType typs for a particular node.
081: * @return The Children object containing a Node[] array of children.
082: */
083: public Children getChildren(Node node, NodeType type) {
084: Children children = new Children.Array();
085: try {
086: children.add(getChildrenObject(node, type));
087: } catch (ManagementRemoteException e) {
088: NotifyDescriptor d = new NotifyDescriptor.Message(e
089: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
090: DialogDisplayer.getDefault().notify(d);
091: }
092: return children;
093: }
094:
095: /**
096: *
097: * @param node
098: * @param type
099: * @return
100: */
101: public Node[] getChildrenObject(Node node, NodeType type)
102: throws ManagementRemoteException {
103: Node[] children = new Node[] {};
104:
105: if (NodeType.JBI.equals(type)) {
106: children = createJBIChildren();
107: } else if (NodeType.SERVICE_ASSEMBLIES.equals(type)) {
108: children = createServiceAssembliesChildren();
109: } else if (NodeType.SERVICE_ASSEMBLY.equals(type)) {
110: children = createServiceAssemblyChildren((JBIServiceAssemblyNode) node);
111: } else if (NodeType.SERVICE_ENGINES.equals(type)
112: || NodeType.BINDING_COMPONENTS.equals(type)
113: || NodeType.SHARED_LIBRARIES.equals(type)) {
114: children = createJBIComponentContainerChildren(type);
115: }
116:
117: return children;
118: }
119:
120: /**
121: *
122: * @return
123: */
124: private Node[] createJBIChildren() {
125: return new Node[] {
126: new JBIComponentContainerNode.ServiceEngines(controller),
127: new JBIComponentContainerNode.BindingComponents(
128: controller),
129: new JBIComponentContainerNode.SharedLibraries(
130: controller),
131: new JBIServiceAssembliesNode(controller) };
132: }
133:
134: /**
135: *
136: * @param parentNodeType
137: * @return
138: */
139: private Node[] createJBIComponentContainerChildren(
140: NodeType parentNodeType) throws ManagementRemoteException {
141:
142: RuntimeManagementServiceWrapper runtimeManagementService = controller
143: .getRuntimeManagementServiceWrapper();
144:
145: List<JBIComponentInfo> compList = null;
146:
147: if (NodeType.SERVICE_ENGINES.equals(parentNodeType)) {
148: compList = runtimeManagementService
149: .listServiceEngines(AppserverJBIMgmtController.SERVER_TARGET);
150: } else if (NodeType.BINDING_COMPONENTS.equals(parentNodeType)) {
151: compList = runtimeManagementService
152: .listBindingComponents(AppserverJBIMgmtController.SERVER_TARGET);
153: } else if (NodeType.SHARED_LIBRARIES.equals(parentNodeType)) {
154: compList = runtimeManagementService
155: .listSharedLibraries(AppserverJBIMgmtController.SERVER_TARGET);
156: } else {
157: assert false;
158: }
159:
160: Node[] nodes = new Node[compList.size()];
161:
162: int index = 0;
163: for (JBIComponentInfo comp : compList) {
164: String name = comp.getName();
165: String description = comp.getDescription();
166:
167: Node newNode;
168: if (NodeType.SERVICE_ENGINES.equals(parentNodeType)) {
169: newNode = new JBIComponentNode.ServiceEngine(
170: controller, name, description);
171: } else if (NodeType.BINDING_COMPONENTS
172: .equals(parentNodeType)) {
173: newNode = new JBIComponentNode.BindingComponent(
174: controller, name, description);
175: } else {
176: newNode = new JBIComponentNode.SharedLibrary(
177: controller, name, description);
178: }
179: nodes[index++] = newNode;
180: }
181:
182: return nodes;
183: }
184:
185: /**
186: *
187: * @return
188: */
189: private Node[] createServiceAssembliesChildren()
190: throws ManagementRemoteException {
191:
192: RuntimeManagementServiceWrapper runtimeMgmtService = controller
193: .getRuntimeManagementServiceWrapper();
194:
195: List<ServiceAssemblyInfo> assemblyList = runtimeMgmtService
196: .listServiceAssemblies(AppserverJBIMgmtController.SERVER_TARGET);
197:
198: Node[] nodes = new Node[assemblyList.size()];
199:
200: int index = 0;
201: for (ServiceAssemblyInfo assembly : assemblyList) {
202: String name = assembly.getName();
203: String description = assembly.getDescription();
204: nodes[index++] = new JBIServiceAssemblyNode(controller,
205: name, description);
206: }
207:
208: return nodes;
209: }
210:
211: /**
212: *
213: * @param node
214: * @return
215: */
216: private Node[] createServiceAssemblyChildren(
217: JBIServiceAssemblyNode node) {
218:
219: ServiceAssemblyInfo saInfo = node.getAssemblyInfo();
220: List<ServiceUnitInfo> unitList = saInfo
221: .getServiceUnitInfoList();
222:
223: Node[] nodes = new Node[unitList.size()];
224:
225: int index = 0;
226: for (ServiceUnitInfo unit : unitList) {
227: String unitName = unit.getName();
228: String unitDescription = unit.getDescription();
229: nodes[index++] = new JBIServiceUnitNode(controller,
230: unitName, unitName, unitDescription);
231: }
232:
233: return nodes;
234: }
235: }
|