001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.web.model;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.management.ObjectName;
023:
024: import org.apache.servicemix.jbi.framework.ComponentMBean;
025: import org.apache.servicemix.jbi.framework.EndpointMBean;
026: import org.apache.servicemix.jbi.framework.RegistryMBean;
027: import org.apache.servicemix.jbi.framework.ServiceAssemblyMBean;
028: import org.apache.servicemix.jbi.framework.ServiceUnitMBean;
029: import org.apache.servicemix.jbi.framework.SharedLibraryMBean;
030:
031: public class Registry {
032:
033: private final RegistryMBean mbean;
034: private final ProxyManager proxyManager;
035:
036: public Registry(RegistryMBean mbean, ProxyManager proxyManager) {
037: this .mbean = mbean;
038: this .proxyManager = proxyManager;
039: }
040:
041: public List<Component> getComponents() {
042: List<Component> components = new ArrayList<Component>();
043: ObjectName[] names = mbean.getComponentNames();
044: for (int i = 0; i < names.length; i++) {
045: ComponentMBean mbean = proxyManager.getProxy(names[i],
046: ComponentMBean.class);
047: if (!"#SubscriptionManager#".equals(mbean.getName())) {
048: components.add(new Component(this , mbean, names[i]));
049: }
050: }
051: return components;
052: }
053:
054: public Component getComponent(String name) {
055: for (Component component : getComponents()) {
056: if (component.getName().equals(name)) {
057: return component;
058: }
059: }
060: return null;
061: }
062:
063: public List<Component> getComponent(SharedLibrary library) {
064: List<Component> components = new ArrayList<Component>();
065: for (Component component : getComponents()) {
066: // TODO
067: }
068: return null;
069: }
070:
071: public List<Endpoint> getEndpoints() {
072: List<Endpoint> endpoints = new ArrayList<Endpoint>();
073: ObjectName[] names = mbean.getEndpointNames();
074: for (int i = 0; i < names.length; i++) {
075: EndpointMBean mbean = proxyManager.getProxy(names[i],
076: EndpointMBean.class);
077: endpoints.add(new Endpoint(this , mbean, names[i]));
078: }
079: return endpoints;
080: }
081:
082: public Endpoint getEndpoint(ObjectName objectName) {
083: for (Endpoint endpoint : getEndpoints()) {
084: if (endpoint.getObjectName().equals(objectName)) {
085: return endpoint;
086: }
087: }
088: return null;
089: }
090:
091: public List<Endpoint> getEndpoints(Component component)
092: throws Exception {
093: List<Endpoint> endpoints = new ArrayList<Endpoint>();
094: for (Endpoint endpoint : getEndpoints()) {
095: if (component.equals(endpoint.getComponent())) {
096: endpoints.add(endpoint);
097: }
098: }
099: return endpoints;
100: }
101:
102: public List<ServiceUnit> getServiceUnits() {
103: List<ServiceUnit> serviceUnits = new ArrayList<ServiceUnit>();
104: ObjectName[] names = mbean.getServiceUnitNames();
105: for (int i = 0; i < names.length; i++) {
106: ServiceUnitMBean mbean = proxyManager.getProxy(names[i],
107: ServiceUnitMBean.class);
108: serviceUnits.add(new ServiceUnit(this , mbean, names[i]));
109: }
110: return serviceUnits;
111: }
112:
113: public ServiceUnit getServiceUnit(String name) {
114: for (ServiceUnit serviceUnit : getServiceUnits()) {
115: if (serviceUnit.getName().equals(name)) {
116: return serviceUnit;
117: }
118: }
119: return null;
120: }
121:
122: public List<ServiceUnit> getServiceUnits(Component component) {
123: List<ServiceUnit> serviceUnits = new ArrayList<ServiceUnit>();
124: for (ServiceUnit serviceUnit : getServiceUnits()) {
125: if (serviceUnit.getComponent().equals(component)) {
126: serviceUnits.add(serviceUnit);
127: }
128: }
129: return serviceUnits;
130: }
131:
132: public List<ServiceUnit> getServiceUnits(ServiceAssembly assembly) {
133: List<ServiceUnit> serviceUnits = new ArrayList<ServiceUnit>();
134: for (ServiceUnit serviceUnit : getServiceUnits()) {
135: if (serviceUnit.getServiceAssembly().equals(assembly)) {
136: serviceUnits.add(serviceUnit);
137: }
138: }
139: return serviceUnits;
140: }
141:
142: public List<ServiceAssembly> getServiceAssemblies() {
143: List<ServiceAssembly> serviceAssemblies = new ArrayList<ServiceAssembly>();
144: ObjectName[] names = mbean.getServiceAssemblyNames();
145: for (int i = 0; i < names.length; i++) {
146: ServiceAssemblyMBean mbean = proxyManager.getProxy(
147: names[i], ServiceAssemblyMBean.class);
148: serviceAssemblies.add(new ServiceAssembly(this , mbean,
149: names[i]));
150: }
151: return serviceAssemblies;
152: }
153:
154: public ServiceAssembly getServiceAssembly(String name) {
155: List<ServiceAssembly> serviceAssemblies = getServiceAssemblies();
156: for (ServiceAssembly serviceAssembly : serviceAssemblies) {
157: if (serviceAssembly.getName().equals(name)) {
158: return serviceAssembly;
159: }
160: }
161: return null;
162: }
163:
164: public List<SharedLibrary> getSharedLibraries() {
165: List<SharedLibrary> sharedLibraries = new ArrayList<SharedLibrary>();
166: ObjectName[] names = mbean.getSharedLibraryNames();
167: for (int i = 0; i < names.length; i++) {
168: SharedLibraryMBean mbean = proxyManager.getProxy(names[i],
169: SharedLibraryMBean.class);
170: sharedLibraries
171: .add(new SharedLibrary(this , mbean, names[i]));
172: }
173: return sharedLibraries;
174: }
175:
176: public SharedLibrary getSharedLibrary(String name) {
177: for (SharedLibrary sharedLibrary : getSharedLibraries()) {
178: if (sharedLibrary.getName().equals(name)) {
179: return sharedLibrary;
180: }
181: }
182: return null;
183: }
184:
185: }
|