You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by aw...@apache.org on 2009/11/30 00:22:56 UTC
svn commit: r885292 - in
/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx:
agent/ codec/ framework/ permissionadmin/
Author: awojtuniak
Date: Sun Nov 29 23:22:55 2009
New Revision: 885292
URL: http://svn.apache.org/viewvc?rev=885292&view=rev
Log:
ARIES-30 ARIES-32 ARIES-50 implement Framework MBean, PackageState MBean, PermissionAdmin MBean
Added:
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java (with props)
Modified:
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java
Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java?rev=885292&r1=885291&r2=885292&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java (original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java Sun Nov 29 23:22:55 2009
@@ -33,6 +33,8 @@
import org.apache.aries.jmx.Logger;
import org.apache.aries.jmx.MBeanHandler;
import org.apache.aries.jmx.MBeanServiceTracker;
+import org.apache.aries.jmx.framework.FrameworkMBeanHandler;
+import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
@@ -76,9 +78,10 @@
*/
public void start() {
logger.log(LogService.LOG_INFO, "Starting JMX OSGi agent");
- //MBeanHandler frameworkHandler = new FrameworkMBeanHandler(bc, logger);
- //frameworkHandler.open();
- //mbeansHandlers.add(frameworkHandler);
+ BundleContext bc = agentContext.getBundleContext();
+ MBeanHandler frameworkHandler = new FrameworkMBeanHandler(bc, logger);
+ frameworkHandler.open();
+ mbeansHandlers.add(frameworkHandler);
mbeanServiceTracker = new MBeanServiceTracker(agentContext);
mbeanServiceTracker.open();
}
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.codec;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.OpenDataException;
+
+import org.osgi.jmx.framework.FrameworkMBean;
+
+/**
+ * <p>
+ * <tt>BatchInstallResult</tt> represents codec for resulting CompositeData of batch operations
+ * made on bundle via FrameworkMBean.
+ * It's converting batch install results to CompositeData {@link #toCompositeData()}
+ * and from CompositeData to this BatchActionResult {@link #from(CompositeData)}.
+ * It provides also constructors to build BatchActionResult.
+ * Structure of compositeData is as defined in compositeType @see {@link FrameworkMBean#BATCH_ACTION_RESULT_TYPE}.
+ * </p>
+ * @see BatchResult
+ *
+ * @version $Rev$ $Date$
+ */
+public class BatchActionResult extends BatchResult{
+
+ /**
+ * @see FrameworkMBean#REMAINING_ID_ITEM
+ * @see FrameworkMBean#REMAINING_LOCATION_ITEM
+ */
+ private long[] remainingItems;
+ /**
+ * @see FrameworkMBean#BUNDLE_IN_ERROR_ID_ITEM
+ * @see FrameworkMBean#BUNDLE_IN_ERROR
+ */
+ private long bundleInError;
+
+ /**
+ * Constructs new BatchActionResult with completedItems array.
+ * Newly created object represents successful batch result.
+ * @param completedItems containing the list of bundles completing the batch operation.
+ */
+ public BatchActionResult(long[] completedItems){
+ this.completed = completedItems;
+ success = true;
+ }
+
+ /**
+ * Constructs new BatchActionResult with error message.
+ * Newly created object represents failed batch result.
+ * @param error containing the error message of the batch operation.
+ */
+ public BatchActionResult(String error){
+ this.error = error;
+ success = false;
+ }
+
+ /**
+ * Constructs new BatchActionResult.
+ * Newly created object represents failed batch result.
+ *
+ * @param completedItems containing the list of bundles completing the batch operation.
+ * @param error containing the error message of the batch operation.
+ * @param remainingItems remaining bundles unprocessed by the
+ * failing batch operation.
+ * @param bundleInError containing the bundle which caused the error during the batch
+ * operation.
+ */
+ public BatchActionResult(long[] completedItems, String error, long[] remainingItems, long bundleInError){
+ this(completedItems,error,remainingItems,false,bundleInError);
+ }
+
+ /**
+ * Constructs new BatchActionResult.
+ *
+ * @param completedItems containing the list of bundles completing the batch operation.
+ * @param error containing the error message of the batch operation.
+ * @param remainingItems remaining bundles unprocessed by the
+ * failing batch operation.
+ * @param success indicates if this operation was successful.
+ * @param bundleInError containing the bundle which caused the error during the batch
+ * operation.
+ */
+ public BatchActionResult(long[] completedItems, String error, long[] remainingItems, boolean success, long bundleInError){
+ this.bundleInError = bundleInError;
+ this.completed = completedItems;
+ this.error = error;
+ this.remainingItems = remainingItems;
+ this.success = success;
+ }
+
+ /**
+ * Translates BatchActionResult to CompositeData represented by
+ * compositeType {@link FrameworkMBean#BATCH_ACTION_RESULT_TYPE}.
+ *
+ * @return translated BatchActionResult to compositeData.
+ */
+ public CompositeData toCompositeData(){
+ try {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(FrameworkMBean.BUNDLE_IN_ERROR, bundleInError);
+ items.put(FrameworkMBean.COMPLETED, toLongArray(completed));
+ items.put(FrameworkMBean.ERROR, error);
+ items.put(FrameworkMBean.REMAINING, toLongArray(remainingItems));
+ items.put(FrameworkMBean.SUCCESS, success);
+ return new CompositeDataSupport(FrameworkMBean.BATCH_ACTION_RESULT_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Can't create CompositeData" + e);
+ }
+ }
+
+ /**
+ * Static factory method to create BatchActionResult from CompositeData object.
+ *
+ * @param data {@link CompositeData} instance.
+ * @return BatchActionResult instance.
+ */
+ public static BatchActionResult from(CompositeData data){
+ if(data == null){
+ return null;
+ }
+ long bundleInError = (Long) data.get(FrameworkMBean.BUNDLE_IN_ERROR);
+ // need to convert primitive array to wrapper type array
+ // compositeData accept only wrapper type array
+ long[] completedItems = toLongPrimitiveArray((Long[])data.get(FrameworkMBean.COMPLETED));
+ long[] remainingItems = toLongPrimitiveArray((Long[]) data.get(FrameworkMBean.REMAINING));
+ String error = (String) data.get(FrameworkMBean.ERROR);
+ Boolean success = (Boolean) data.get(FrameworkMBean.SUCCESS);
+ return new BatchActionResult(completedItems, error, remainingItems, success, bundleInError);
+ }
+
+ /**
+ * Gets remaining items id's.
+ * @return the remainingItems.
+ */
+ public long[] getRemainingItems() {
+ return remainingItems;
+ }
+
+ /**
+ * Gets bundle in error id.
+ * @return the bundleInError.
+ */
+ public long getBundleInError() {
+ return bundleInError;
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchActionResult.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,163 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.codec;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.OpenDataException;
+
+import org.osgi.jmx.framework.FrameworkMBean;
+
+/**
+ * <p>
+ * <tt>BatchInstallResult</tt> represents codec for resulting CompositeData of
+ * FrameworkMBean installBundles methods.
+ * It converting batch install results to CompositeData {@link #toCompositeData()}
+ * and from CompositeData to this BatchInstallResult {@link #from(CompositeData)}.
+ * It provides also constructors to build BatchInstallResult.
+ * Structure of compositeData as defined in compositeType @see {@link FrameworkMBean#BATCH_INSTALL_RESULT_TYPE}.
+ * </p>
+ * @see BatchResult
+ *
+ * @version $Rev$ $Date$
+ */
+public class BatchInstallResult extends BatchResult {
+
+ /**
+ * @see FrameworkMBean#REMAINING_LOCATION_ITEM
+ * @see FrameworkMBean#REMAINING
+ */
+ private String[] remainingLocationItems;
+
+ /**
+ * @see FrameworkMBean#BUNDLE_IN_ERROR_LOCATION_ITEM
+ * @see FrameworkMBean#BUNDLE_IN_ERROR
+ */
+ private String bundleInError;
+
+ /**
+ * Constructs new BatchInstallResult with completedItems array.
+ * Newly created object represents successful batch result.
+ * @param completedItems containing the list of bundles completing the batch operation.
+ */
+ public BatchInstallResult(long[] completedItems) {
+ this.completed = completedItems;
+ success = true;
+ }
+
+ /**
+ * Constructs new BatchInstallResult with error message.
+ * Newly created object represents failed batch result.
+ * @param error containing the error message of the batch operation.
+ */
+ public BatchInstallResult(String error){
+ this.error = error;
+ success = false;
+ }
+ /**
+ * Constructs new BatchInstallResult.
+ * Newly created object represents failed batch result.
+ *
+ * @param completedItems containing the list of bundles completing the batch operation.
+ * @param error containing the error message of the batch operation.
+ * @param remainingLocationItems remaining bundles unprocessed by the
+ * failing batch operation.
+ * @param bundleInError containing the bundle which caused the error during the batch
+ * operation.
+ */
+ public BatchInstallResult(long[] completedItems, String error, String[] remainingLocationItems, String bundleInError) {
+ this(completedItems, error, remainingLocationItems, false, bundleInError);
+ }
+
+ /**
+ * Constructs new BatchInstallResult.
+ *
+ * @param completedItems containing the list of bundles completing the batch operation.
+ * @param error containing the error message of the batch operation.
+ * @param remainingLocationItems remaining bundles unprocessed by the
+ * failing batch operation.
+ * @param success indicates if this operation was successful.
+ * @param bundleInError containing the bundle which caused the error during the batch
+ * operation.
+ */
+ public BatchInstallResult(long[] completedItems, String error, String[] remainingLocationItems, boolean success,
+ String bundleInError) {
+ this.bundleInError = bundleInError;
+ this.completed = completedItems;
+ this.error = error;
+ this.remainingLocationItems = remainingLocationItems;
+ this.success = success;
+ }
+
+ /**
+ * Translates BatchInstallResult to CompositeData represented by
+ * compositeType {@link FrameworkMBean#BATCH_INSTALL_RESULT_TYPE}.
+ *
+ * @return translated BatchInstallResult to compositeData.
+ */
+ public CompositeData toCompositeData() {
+ try {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(FrameworkMBean.BUNDLE_IN_ERROR, bundleInError);
+ items.put(FrameworkMBean.COMPLETED, toLongArray(completed));
+ items.put(FrameworkMBean.ERROR, error);
+ items.put(FrameworkMBean.REMAINING, remainingLocationItems);
+ items.put(FrameworkMBean.SUCCESS, success);
+ return new CompositeDataSupport(FrameworkMBean.BATCH_INSTALL_RESULT_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Can't create CompositeData" + e);
+ }
+ }
+
+ /**
+ * Static factory method to create BatchInstallResult from CompositeData object.
+ *
+ * @param data {@link CompositeData} instance.
+ * @return BatchInstallResult instance.
+ */
+ public static BatchInstallResult from(CompositeData data) {
+ if(data == null){
+ return null;
+ }
+ String bundleInError = (String) data.get(FrameworkMBean.BUNDLE_IN_ERROR);
+ long[] completedItems = toLongPrimitiveArray((Long[]) data.get(FrameworkMBean.COMPLETED));
+ String[] remainingLocationItems = (String[]) data.get(FrameworkMBean.REMAINING);
+ String error = (String) data.get(FrameworkMBean.ERROR);
+ boolean success = (Boolean) data.get(FrameworkMBean.SUCCESS);
+ return new BatchInstallResult(completedItems, error, remainingLocationItems, success, bundleInError);
+ }
+
+ /**
+ * Gets remaining location items.
+ * @return array of String with locations.
+ */
+ public String[] getRemainingLocationItems() {
+ return remainingLocationItems;
+ }
+
+ /**
+ * Gets bundle in error location.
+ * @return the bundleInError.
+ */
+ public String getBundleInError() {
+ return bundleInError;
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchInstallResult.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.codec;
+
+import org.osgi.jmx.framework.FrameworkMBean;
+
+/**
+ * <p>
+ * <tt>BatchResult</tt> represents abstract class for BatchResults.
+ * It contains common data structure of batch result:
+ * <ul>
+ * <li>completed containing the list of bundles completing the batch operation.</li>
+ * <li>error containing the error message of the batch operation.</li>
+ * <li>success indicates if this operation was successful.</li>
+ * </ul>
+ * </p>
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BatchResult {
+
+ /**
+ * @see FrameworkMBean#COMPLETED_ITEM
+ * @see FrameworkMBean#COMPLETED
+ */
+ protected long[] completed;
+ /**
+ * @see FrameworkMBean#ERROR_ITEM
+ * @see FrameworkMBean#ERROR
+ */
+ protected String error;
+ /**
+ * @see FrameworkMBean#SUCCESS_ITEM
+ * @see FrameworkMBean#SUCCESS
+ */
+ protected boolean success;
+
+ /**
+ * Gets completed item id's.
+ * @return completed items id's.
+ */
+ public long[] getCompleted() {
+ return completed;
+ }
+
+ /**
+ * Gets error message.
+ * @return error message.
+ */
+ public String getError() {
+ return error;
+ }
+
+ /**
+ * Gets success value.
+ * @return true if success false if not.
+ */
+ public boolean isSuccess() {
+ return success;
+ }
+
+ /**
+ * Converts primitive array of strings to Long array.
+ *
+ * @param primitiveArray primitive long array.
+ * @return Long array.
+ */
+ protected Long[] toLongArray(long[] primitiveArray) {
+ if (primitiveArray == null) {
+ return null;
+ }
+ Long[] converted = new Long[primitiveArray.length];
+ for (int i = 0; i < primitiveArray.length; i++) {
+ converted[i] = primitiveArray[i];
+ }
+
+ return converted;
+ }
+
+ /**
+ * Converts Long array to primitive array of long.
+ *
+ * @param wrapperArray Long array.
+ * @return primitive long array.
+ */
+ protected static long[] toLongPrimitiveArray(Long[] wrapperArray) {
+ if (wrapperArray == null) {
+ return null;
+ }
+ long[] converted = new long[wrapperArray.length];
+ for (int i = 0; i < wrapperArray.length; i++) {
+ converted[i] = wrapperArray[i];
+ }
+
+ return converted;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResult.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,219 @@
+package org.apache.aries.jmx.codec;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.osgi.framework.Bundle;
+import org.osgi.jmx.framework.PackageStateMBean;
+import org.osgi.service.packageadmin.ExportedPackage;
+
+/**
+ * <p>
+ * <tt>Package</tt>represents PackageType @see {@link PackageStateMBean#PACKAGE_TYPE}.
+ * It is a codec for the composite data representing an OSGi ExportedPackage.
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class Package {
+
+ /**
+ * {@link PackageStateMBean#EXPORTING_BUNDLE}
+ */
+ long exportingBundle;
+
+ /**
+ * {@link PackageStateMBean#IMPORTING_BUNDLES}
+ */
+ long[] importingBundles;
+
+ /**
+ * {@link PackageStateMBean#NAME}
+ */
+ String name;
+
+ /**
+ * {@link PackageStateMBean#REMOVAL_PENDING}
+ */
+ boolean removalPending;
+
+ /**
+ * {@link PackageStateMBean#VERSION}
+ */
+ String version;
+
+ /**
+ * Constructs new Package with provided ExportedPackage.
+ * @param exportedPackage @see {@link ExportedPackage}.
+ */
+ public Package(ExportedPackage exportedPackage) {
+ this(exportedPackage.getExportingBundle().getBundleId(), toBundleIds(exportedPackage.getImportingBundles()),
+ exportedPackage.getName(), exportedPackage.isRemovalPending(), exportedPackage.getVersion().toString());
+
+ }
+
+ /**
+ * Constructs new Package.
+ *
+ * @param exportingBundle the bundle the package belongs to.
+ * @param importingBundles the importing bundles of the package.
+ * @param name the package name.
+ * @param removalPending whether the package is pending removal.
+ * @param version package version.
+ */
+ public Package(long exportingBundle, long[] importingBundles, String name, boolean removalPending, String version) {
+ this.exportingBundle = exportingBundle;
+ this.importingBundles = importingBundles;
+ this.name = name;
+ this.removalPending = removalPending;
+ this.version = version;
+ }
+
+ /**
+ * Translates Package to CompositeData represented by
+ * compositeType {@link PackageStateMBean#PACKAGE_TYPE}.
+ *
+ * @return translated Package to compositeData.
+ */
+ public CompositeData toCompositeData() {
+ try {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(PackageStateMBean.EXPORTING_BUNDLE, exportingBundle);
+ items.put(PackageStateMBean.IMPORTING_BUNDLES, toLongArray(importingBundles));
+ items.put(PackageStateMBean.NAME, name);
+ items.put(PackageStateMBean.REMOVAL_PENDING, removalPending);
+ items.put(PackageStateMBean.VERSION, version);
+ return new CompositeDataSupport(PackageStateMBean.PACKAGE_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Can't create CompositeData" + e);
+ }
+ }
+
+ /**
+ * Static factory method to create Package from CompositeData object.
+ *
+ * @param data {@link CompositeData} instance.
+ * @return Package instance.
+ */
+ public static Package from(CompositeData data) {
+ if(data == null){
+ return null;
+ }
+ long exportingBundle = (Long) data.get(PackageStateMBean.EXPORTING_BUNDLE);
+ long[] importingBundles = toLongPrimitiveArray((Long[]) data.get(PackageStateMBean.IMPORTING_BUNDLES));
+ String name = (String) data.get(PackageStateMBean.NAME);
+ boolean removalPending = (Boolean) data.get(PackageStateMBean.REMOVAL_PENDING);
+ String version = (String) data.get(PackageStateMBean.VERSION);
+ return new Package(exportingBundle,importingBundles,name, removalPending,version);
+ }
+
+ /**
+ * Creates {@link TabularData} for set of Package's.
+ *
+ * @param packages set of Package's
+ * @return {@link TabularData} instance.
+ */
+ public static TabularData tableFrom(Set<Package> packages){
+ TabularData table = new TabularDataSupport(PackageStateMBean.PACKAGES_TYPE);
+ for(Package pkg : packages){
+ table.put(pkg.toCompositeData());
+ }
+ return table;
+ }
+
+ /**
+ * Converts array of bundles to array of bundle id's.
+ *
+ * @param bundles array of Bundle's.
+ * @return array of bundle id's.
+ */
+ public static long[] toBundleIds(Bundle[] bundles) {
+ if (bundles != null) {
+ long[] importingBundles = new long[bundles.length];
+ for (int i = 0; i < bundles.length; i++) {
+ importingBundles[i] = bundles[i].getBundleId();
+ }
+ return importingBundles;
+ }
+ return null;
+ }
+
+ /**
+ * Converts primitive array of strings to Long array.
+ *
+ * @param primitiveArray primitive long array.
+ * @return Long array.
+ */
+ protected Long[] toLongArray(long[] primitiveArray) {
+ if (primitiveArray == null) {
+ return null;
+ }
+ Long[] converted = new Long[primitiveArray.length];
+ for (int i = 0; i < primitiveArray.length; i++) {
+ converted[i] = primitiveArray[i];
+ }
+
+ return converted;
+ }
+
+ /**
+ * Converts Long array to primitive array of long.
+ *
+ * @param wrapperArray Long array.
+ * @return primitive long array.
+ */
+ protected static long[] toLongPrimitiveArray(Long[] wrapperArray) {
+ if (wrapperArray == null) {
+ return null;
+ }
+ long[] converted = new long[wrapperArray.length];
+ for (int i = 0; i < wrapperArray.length; i++) {
+ converted[i] = wrapperArray[i];
+ }
+
+ return converted;
+ }
+
+ /**
+ * @return the exportingBundle
+ */
+ public long getExportingBundle() {
+ return exportingBundle;
+ }
+
+ /**
+ * @return the importingBundles
+ */
+ public long[] getImportingBundles() {
+ return importingBundles;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the removalPending
+ */
+ public boolean isRemovalPending() {
+ return removalPending;
+ }
+
+ /**
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/Package.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,504 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.management.openmbean.CompositeData;
+
+import org.apache.aries.jmx.codec.BatchActionResult;
+import org.apache.aries.jmx.codec.BatchInstallResult;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+
+/**
+ * <p>
+ * <tt>Framework</tt> represents {@link FrameworkMBean} implementation.
+ * </p>
+ * @see FrameworkMBean
+ *
+ * @version $Rev$ $Date$
+ */
+public class Framework implements FrameworkMBean {
+
+ private StartLevel startLevel;
+ private PackageAdmin packageAdmin;
+ private BundleContext context;
+
+ /**
+ * Constructs new FrameworkMBean.
+ *
+ * @param context bundle context of jmx bundle.
+ * @param startLevel @see {@link StartLevel} service reference.
+ * @param packageAdmin @see {@link PackageAdmin} service reference.
+ */
+ public Framework(BundleContext context, StartLevel startLevel, PackageAdmin packageAdmin) {
+ this.context = context;
+ this.startLevel = startLevel;
+ this.packageAdmin = packageAdmin;
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#getFrameworkStartLevel()
+ */
+ public int getFrameworkStartLevel() throws IOException {
+ return startLevel.getStartLevel();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#getInitialBundleStartLevel()
+ */
+ public int getInitialBundleStartLevel() throws IOException {
+ return startLevel.getInitialBundleStartLevel();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#installBundle(java.lang.String)
+ */
+ public long installBundle(String location) throws IOException {
+ try {
+ Bundle bundle = context.installBundle(location);
+ return bundle.getBundleId();
+ } catch (BundleException e) {
+ throw new IOException("Can't install bundle with location" + location);
+ }
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#installBundle(java.lang.String, java.lang.String)
+ */
+ public long installBundle(String location, String url) throws IOException {
+ InputStream inputStream;
+ try {
+ inputStream = new URL(url).openStream();
+ Bundle bundle = context.installBundle(location, inputStream);
+ return bundle.getBundleId();
+ } catch (BundleException e) {
+ throw new IOException("Can't install bundle with location" + location);
+ }
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#installBundles(java.lang.String[])
+ */
+ public CompositeData installBundles(String[] locations) throws IOException {
+ if(locations == null){
+ return new BatchInstallResult("Failed to install bundles locations can't be null").toCompositeData();
+ }
+ long[] ids = new long[locations.length];
+ for (int i = 0; i < locations.length; i++) {
+ try {
+ long id = installBundle(locations[i]);
+ ids[i] = id;
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(ids, 0, completed, 0, i);
+ String[] remaining = new String[locations.length - i - 1];
+ System.arraycopy(locations, i + 1, remaining, 0, remaining.length);
+ return new BatchInstallResult(completed, t.toString(), remaining, locations[i]).toCompositeData();
+ }
+ }
+
+ return new BatchInstallResult(ids).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#installBundles(java.lang.String[], java.lang.String[])
+ */
+ public CompositeData installBundles(String[] locations, String[] urls) throws IOException {
+ if(locations == null || urls == null){
+ return new BatchInstallResult("Failed to install bundles arguments can't be null").toCompositeData();
+ }
+
+ if(locations != null && locations != null && locations.length != urls.length){
+ return new BatchInstallResult("Failed to install bundles size of arguments should be same").toCompositeData();
+ }
+ long[] ids = new long[locations.length];
+ for (int i = 0; i < locations.length; i++) {
+ // check index
+ try {
+ long id = installBundle(locations[i], urls[i]);
+ ids[i] = id;
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(ids, 0, completed, 0, i);
+ String[] remaining = new String[locations.length - i - 1];
+ System.arraycopy(locations, i + 1, remaining, 0, remaining.length);
+ return new BatchInstallResult(completed, t.toString(), remaining, locations[i]).toCompositeData();
+ }
+ }
+ return new BatchInstallResult(ids).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#refreshPackages(long)
+ */
+ public void refreshPackages(long bundleIdentifier) throws IOException {
+ Bundle bundle = getBundle(bundleIdentifier);
+ packageAdmin.refreshPackages(new Bundle[] { bundle });
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#refreshPackages(long[])
+ */
+ public CompositeData refreshPackages(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ return new BatchActionResult("Failed to refresh packages bundle id's can't be null").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ refreshPackages(bundleIdentifiers[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#resolveBundle(long)
+ */
+ public boolean resolveBundle(long bundleIdentifier) throws IOException {
+ Bundle bundle = getBundle(bundleIdentifier);
+ return packageAdmin.resolveBundles(new Bundle[] { bundle });
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#resolveBundles(long[])
+ */
+ public boolean resolveBundles(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ throw new IllegalArgumentException("Failed to resolve bundles id's can't be null");
+ }
+ Bundle[] bundles = new Bundle[bundleIdentifiers.length];
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ bundles[i] = getBundle(bundleIdentifiers[i]);
+ }
+
+ return packageAdmin.resolveBundles(bundles);
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#restartFramework()
+ */
+ public void restartFramework() throws IOException {
+ Bundle bundle = context.getBundle(0);
+ try {
+ bundle.update();
+ } catch (BundleException be) {
+ throw new IOException("Failed to restart framework " + be);
+ }
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#setBundleStartLevel(long, int)
+ */
+ public void setBundleStartLevel(long bundleIdentifier, int newlevel) throws IOException {
+ Bundle bundle = getBundle(bundleIdentifier);
+ startLevel.setBundleStartLevel(bundle, newlevel);
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#setBundleStartLevels(long[], int[])
+ */
+ public CompositeData setBundleStartLevels(long[] bundleIdentifiers, int[] newlevels) throws IOException {
+ if(bundleIdentifiers == null || newlevels == null){
+ return new BatchActionResult("Failed to setBundleStartLevels arguments can't be null").toCompositeData();
+ }
+
+ if(bundleIdentifiers != null && newlevels != null && bundleIdentifiers.length != newlevels.length){
+ return new BatchActionResult("Failed to setBundleStartLevels size of arguments should be same").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ setBundleStartLevel(bundleIdentifiers[i], newlevels[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#setFrameworkStartLevel(int)
+ */
+ public void setFrameworkStartLevel(int newlevel) throws IOException {
+ startLevel.setStartLevel(newlevel);
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#setInitialBundleStartLevel(int)
+ */
+ public void setInitialBundleStartLevel(int newlevel) throws IOException {
+ startLevel.setInitialBundleStartLevel(newlevel);
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#shutdownFramework()
+ */
+ public void shutdownFramework() throws IOException {
+ Bundle bundle = context.getBundle(0);
+ try {
+ bundle.stop();
+ } catch (BundleException be) {
+ throw new IOException("Failed to shutdown framework " + be);
+ }
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#startBundle(long)
+ */
+ public void startBundle(long bundleIdentifier) throws IOException {
+ Bundle bundle = context.getBundle(bundleIdentifier);
+ if (bundle != null) {
+ try {
+ bundle.start();
+ } catch (BundleException be) {
+ throw new IOException("Failed to start bundle with id " + bundleIdentifier);
+ }
+ }
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#startBundles(long[])
+ */
+ public CompositeData startBundles(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ return new BatchActionResult("Failed to start bundles, bundle id's can't be null").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ startBundle(bundleIdentifiers[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#stopBundle(long)
+ */
+ public void stopBundle(long bundleIdentifier) throws IOException {
+ Bundle bundle = context.getBundle(bundleIdentifier);
+ if (bundle != null) {
+ try {
+ bundle.stop();
+ } catch (BundleException e) {
+ throw new IOException("Failed to stop bundle with id " + bundleIdentifier);
+ }
+ }
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#stopBundles(long[])
+ */
+ public CompositeData stopBundles(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ return new BatchActionResult("Failed to stop bundles, bundle id's can't be null").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ stopBundle(bundleIdentifiers[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#uninstallBundle(long)
+ */
+ public void uninstallBundle(long bundleIdentifier) throws IOException {
+ Bundle bundle = context.getBundle(bundleIdentifier);
+ if (bundle != null) {
+ try {
+ bundle.uninstall();
+ } catch (BundleException be) {
+ throw new IOException("Failed to uninstall bundle with id " + bundleIdentifier);
+ }
+ }
+
+ throw new IllegalArgumentException("Can't find bundle with id " + bundleIdentifier);
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#uninstallBundles(long[])
+ */
+ public CompositeData uninstallBundles(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ return new BatchActionResult("Failed uninstall bundles, bundle id's can't be null").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ uninstallBundle(bundleIdentifiers[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#updateBundle(long)
+ */
+ public void updateBundle(long bundleIdentifier) throws IOException {
+ Bundle bundle = getBundle(bundleIdentifier);
+
+ try {
+ bundle.update();
+ } catch (BundleException be) {
+ throw new IOException("Failed to update bundle with id " + bundleIdentifier);
+ }
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#updateBundle(long, java.lang.String)
+ */
+ public void updateBundle(long bundleIdentifier, String url) throws IOException {
+ Bundle bundle = getBundle(0);
+ InputStream inputStream = null;
+ try {
+ inputStream = new URL(url).openStream();
+ bundle.update(inputStream);
+ } catch (BundleException be) {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ioe) {
+
+ }
+ }
+ throw new IOException("Can't update system bundle " + be);
+ }
+
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#updateBundles(long[])
+ */
+ public CompositeData updateBundles(long[] bundleIdentifiers) throws IOException {
+ if(bundleIdentifiers == null){
+ return new BatchActionResult("Failed to update bundles, bundle id's can't be null").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ updateBundle(bundleIdentifiers[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#updateBundles(long[], java.lang.String[])
+ */
+ public CompositeData updateBundles(long[] bundleIdentifiers, String[] urls) throws IOException {
+ if(bundleIdentifiers == null || urls == null){
+ return new BatchActionResult("Failed to update bundles arguments can't be null").toCompositeData();
+ }
+
+ if(bundleIdentifiers != null && urls != null && bundleIdentifiers.length != urls.length){
+ return new BatchActionResult("Failed to update bundles size of arguments should be same").toCompositeData();
+ }
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ updateBundle(bundleIdentifiers[i], urls[i]);
+ } catch (Throwable t) {
+ long[] completed = new long[i];
+ System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
+ long[] remaining = new long[completed.length - i - 1];
+ System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
+ return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i])
+ .toCompositeData();
+ }
+ }
+ return new BatchActionResult(bundleIdentifiers).toCompositeData();
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.FrameworkMBean#updateFramework()
+ */
+ public void updateFramework() throws IOException {
+ Bundle bundle = getBundle(0);
+ try {
+ bundle.update();
+ } catch (BundleException be) {
+ throw new IOException("Failed to update system bundle " + be);
+ }
+
+ }
+
+ /**
+ * Gets bundle with provided bundleId.
+ *
+ * @param bundleIdentifier bundle id.
+ * @return {@link Bundle} instance.
+ */
+ private Bundle getBundle(long bundleIdentifier) {
+ Bundle bundle = context.getBundle(bundleIdentifier);
+ if (bundle != null) {
+ return bundle;
+ }
+ throw new IllegalArgumentException("Can't find bundle with id " + bundleIdentifier);
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import org.apache.aries.jmx.Logger;
+import org.apache.aries.jmx.MBeanHandler;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+
+/**
+ * <p>
+ * <tt>FrameworkMBeanHandler</tt> represents MBeanHandler which
+ * holding information about {@link FrameworkMBean}.</p>
+ *
+ * @see MBeanHandler
+ *
+ * @version $Rev$ $Date$
+ */
+public class FrameworkMBeanHandler implements MBeanHandler {
+
+ private String name;
+ private StandardMBean mbean;
+ private BundleContext context;
+ private Logger logger;
+
+ /**
+ * Constructs new FrameworkMBeanHandler.
+ *
+ * @param context bundle context of JMX bundle.
+ * @param logger @see {@link Logger}.
+ */
+ public FrameworkMBeanHandler(BundleContext context, Logger logger) {
+ this.context = context;
+ this.name = FrameworkMBean.OBJECTNAME;
+ this.logger = logger;
+ }
+
+ /**
+ * @see org.apache.aries.jmx.MBeanHandler#getMbean()
+ */
+ public StandardMBean getMbean() {
+ return mbean;
+ }
+
+ /**
+ * @see org.apache.aries.jmx.MBeanHandler#open()
+ */
+ public void open() {
+ ServiceReference adminRef = context.getServiceReference(PackageAdmin.class.getCanonicalName());
+ PackageAdmin packageAdmin = (PackageAdmin) context.getService(adminRef);
+ ServiceReference startLevelRef = context.getServiceReference(StartLevel.class.getCanonicalName());
+ StartLevel startLevel = (StartLevel) context.getService(startLevelRef);
+ FrameworkMBean framework = new Framework(context, startLevel, packageAdmin);
+ try {
+ mbean = new StandardMBean(framework, FrameworkMBean.class);
+ } catch (NotCompliantMBeanException e) {
+ logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
+ }
+ }
+
+ /**
+ * @see org.apache.aries.jmx.MBeanHandler#close()
+ */
+ public void close() {
+ //not used
+ }
+
+ /**
+ * @see org.apache.aries.jmx.MBeanHandler#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/FrameworkMBeanHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.codec.Package;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.jmx.framework.PackageStateMBean;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * <p>
+ * <tt>PackageState</tt> represents implementation of PackageStateMBean.
+ * </p>
+ *
+ * @see PackageStateMBean
+ *
+ * @version $Rev$ $Date$
+ */
+public class PackageState implements PackageStateMBean {
+
+ /**
+ * {@link PackageAdmin} service reference.
+ */
+ private PackageAdmin packageAdmin;
+ private BundleContext context;
+
+ /**
+ * Constructs new PackagesState MBean.
+ *
+ * @param context bundle context.
+ * @param packageAdmin {@link PackageAdmin} service reference.
+ */
+ public PackageState(BundleContext context, PackageAdmin packageAdmin) {
+ this.context = context;
+ this.packageAdmin = packageAdmin;
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.PackageStateMBean#getExportingBundle(java.lang.String, java.lang.String)
+ */
+ public long getExportingBundle(String packageName, String version) throws IOException {
+ ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(packageName);
+ if (exportedPackages != null) {
+ Version ver = Version.parseVersion(version);
+ for (ExportedPackage exportedPackage : exportedPackages) {
+ if (exportedPackage.getVersion().equals(ver)) {
+ return exportedPackage.getExportingBundle().getBundleId();
+ }
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.PackageStateMBean#getImportingBundles(java.lang.String, java.lang.String)
+ */
+ public long[] getImportingBundles(String packageName, String version) throws IOException {
+ ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(packageName);
+ if (exportedPackages != null) {
+ Version ver = Version.parseVersion(version);
+ for (ExportedPackage exportedPackage : exportedPackages) {
+ if (exportedPackage.getVersion().equals(ver)) {
+ Bundle[] bundles = exportedPackage.getImportingBundles();
+ if (bundles != null) {
+ long[] importingBundles = new long[bundles.length];
+ for (int i = 0; i < bundles.length; i++) {
+ importingBundles[i] = bundles[i].getBundleId();
+ }
+ return importingBundles;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.PackageStateMBean#isRemovalPending(java.lang.String, java.lang.String)
+ */
+ public boolean isRemovalPending(String packageName, String version) throws IOException {
+ ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(packageName);
+ if (exportedPackages != null) {
+ Version ver = Version.parseVersion(version);
+ for (ExportedPackage exportedPackage : exportedPackages) {
+ if (exportedPackage.getVersion().equals(ver) && exportedPackage.isRemovalPending()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see org.osgi.jmx.framework.PackageStateMBean#listPackages()
+ */
+ public TabularData listPackages() throws IOException {
+ Set<Package> packages = new HashSet<Package>();
+ for (Bundle bundle : context.getBundles()) {
+ ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
+ for (ExportedPackage exportedPackage : exportedPackages) {
+ packages.add(new Package(exportedPackage));
+ }
+
+ }
+ return Package.tableFrom(packages);
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/PackageState.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java?rev=885292&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java Sun Nov 29 23:22:55 2009
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.permissionadmin;
+
+import java.io.IOException;
+
+import org.osgi.jmx.service.permissionadmin.PermissionAdminMBean;
+import org.osgi.service.permissionadmin.PermissionInfo;
+
+/**
+ * <p>
+ * <tt>PermissionAdmin</tt> represents implementation of PermissionAdminMBean.
+ * </p>
+ * @see PermissionAdminMBean
+ *
+ * @version $Rev$ $Date$
+ */
+public class PermissionAdmin implements PermissionAdminMBean {
+
+ /**
+ * {@link org.osgi.service.permissionadmin.PermissionAdmin} service.
+ */
+ private org.osgi.service.permissionadmin.PermissionAdmin permAdmin;
+
+ /**
+ * Constructs new PermissionAdmin MBean.
+ *
+ * @param permAdmin {@link org.osgi.service.permissionadmin.PermissionAdmin} service reference.
+ */
+ public PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin permAdmin) {
+ this.permAdmin = permAdmin;
+ }
+
+ /**
+ * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#getPermissions(java.lang.String)
+ */
+ public String[] getPermissions(String location) throws IOException {
+ PermissionInfo[] permissions = permAdmin.getPermissions(location);
+ if (permissions != null) {
+ String[] encoded = new String[permissions.length];
+ for (int i = 0; i < permissions.length; i++) {
+ PermissionInfo info = permissions[i];
+ encoded[i] = info.getEncoded();
+ }
+ return encoded;
+ }
+ return null;
+ }
+
+ /**
+ * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#listDefaultPermissions()
+ */
+ public String[] listDefaultPermissions() throws IOException {
+ PermissionInfo[] permissions = permAdmin.getDefaultPermissions();
+ if (permissions != null) {
+ String[] encoded = new String[permissions.length];
+ for (int i = 0; i < permissions.length; i++) {
+ PermissionInfo info = permissions[i];
+ encoded[i] = info.getEncoded();
+ }
+ return encoded;
+ }
+ return null;
+ }
+
+ /**
+ * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#listLocations()
+ */
+ public String[] listLocations() throws IOException {
+ return permAdmin.getLocations();
+ }
+
+ /**
+ * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#setDefaultPermissions(java.lang.String[])
+ */
+ public void setDefaultPermissions(String[] encodedPermissions) throws IOException {
+ if(encodedPermissions == null){
+ //default permissions are to be removed
+ permAdmin.setDefaultPermissions(null);
+ }
+ PermissionInfo[] permissions = new PermissionInfo[encodedPermissions.length];
+ for (int i = 0; i < encodedPermissions.length; i++) {
+ permissions[i] = new PermissionInfo(encodedPermissions[i]);
+ }
+ permAdmin.setDefaultPermissions(permissions);
+
+ }
+
+ /**
+ * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#setPermissions(java.lang.String,
+ * java.lang.String[])
+ */
+ public void setPermissions(String location, String[] encodedPermissions) throws IOException {
+ if(encodedPermissions == null){
+ //default permissions are to be removed
+ permAdmin.setPermissions(location, null);
+ }
+ PermissionInfo[] permissions = new PermissionInfo[encodedPermissions.length];
+ for (int i = 0; i < encodedPermissions.length; i++) {
+ permissions[i] = new PermissionInfo(encodedPermissions[i]);
+ }
+ permAdmin.setPermissions(location, permissions);
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/permissionadmin/PermissionAdmin.java
------------------------------------------------------------------------------
svn:keywords = Revision Date