001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * matic 016 */ 017package org.nuxeo.ecm.platform.management.adapters; 018 019import java.io.IOException; 020import java.util.Collection; 021import java.util.HashSet; 022import java.util.Set; 023 024import org.nuxeo.ecm.core.api.NuxeoException; 025import org.nuxeo.runtime.RuntimeService; 026import org.nuxeo.runtime.api.Framework; 027import org.nuxeo.runtime.model.ComponentName; 028import org.nuxeo.runtime.model.RegistrationInfo; 029 030/** 031 * @author Stephane Lacoin (Nuxeo EP Software Engineer) 032 */ 033public class RuntimeInventoryAdapter implements RuntimeInventoryMBean { 034 035 protected final RuntimeService runtimeService = Framework.getRuntime(); 036 037 protected final RuntimeInventoryFactory factory; 038 039 public RuntimeInventoryAdapter(RuntimeInventoryFactory factory) { 040 this.factory = factory; 041 } 042 043 protected Collection<RegistrationInfo> availableComponents() { 044 return runtimeService.getComponentManager().getRegistrations(); 045 } 046 047 protected Collection<ComponentName> pendingComponentsName() { 048 return runtimeService.getComponentManager().getActivatingRegistrations(); 049 } 050 051 public Set<String> getAvailableComponents() { 052 Set<String> names = new HashSet<String>(); 053 for (RegistrationInfo info : availableComponents()) { 054 names.add(info.getName().getRawName()); 055 } 056 return names; 057 } 058 059 public int getAvailableComponentsCount() { 060 return runtimeService.getComponentManager().getRegistrations().size(); 061 } 062 063 public int getPendingComponentsCount() { 064 return pendingComponentsName().size(); 065 } 066 067 public Set<String> getPendingComponentsName() { 068 Set<String> names = new HashSet<String>(); 069 for (ComponentName componentName : pendingComponentsName()) { 070 names.add(componentName.getRawName()); 071 } 072 return names; 073 } 074 075 public String getDescription() { 076 return runtimeService.getDescription(); 077 } 078 079 public String getHome() { 080 try { 081 return runtimeService.getHome().getCanonicalPath(); 082 } catch (IOException e) { 083 throw new NuxeoException("cannot get path", e); 084 } 085 } 086 087 public String getName() { 088 return runtimeService.getName(); 089 } 090 091 public String getVersion() { 092 return runtimeService.getVersion().toString(); 093 } 094 095 protected boolean isTreeBound = false; 096 097 public boolean isTreeBound() { 098 return isTreeBound; 099 } 100 101 public void bindTree() { 102 if (isTreeBound) { 103 throw new IllegalArgumentException("tree already bound"); 104 } 105 isTreeBound = true; 106 factory.bindTree(); 107 } 108 109 public void unbindTree() { 110 if (!isTreeBound) { 111 throw new IllegalArgumentException("tree not bound"); 112 } 113 isTreeBound = false; 114 factory.unbindTree(); 115 } 116 117}