Package: VirgoObjectNameTranslator

VirgoObjectNameTranslator

nameinstructionbranchcomplexitylinemethod
VirgoObjectNameTranslator(BundleContext)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
translate(ObjectName)
M: 16 C: 16
50%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.management.fragment;
13:
14: import java.util.Hashtable;
15:
16: import javax.management.ObjectName;
17:
18: import org.eclipse.equinox.region.Region;
19: import org.eclipse.equinox.region.RegionDigraph;
20: import org.eclipse.gemini.management.ObjectNameTranslator;
21: import org.osgi.framework.BundleContext;
22: import org.osgi.framework.ServiceReference;
23:
24: public class VirgoObjectNameTranslator implements ObjectNameTranslator{
25:
26:         private static final String REGION_KEY = "region";
27:         
28:         private final String regionName;
29:
30:         public VirgoObjectNameTranslator(BundleContext context) {
31:                 ServiceReference<RegionDigraph> serviceReference = context.getServiceReference(RegionDigraph.class);
32:                 RegionDigraph service = context.getService(serviceReference);
33:                 Region region = service.getRegion(context.getBundle().getBundleId());
34:                 this.regionName = region.getName();
35:         }
36:         
37:         /**
38:          * {@inheritDoc}
39:          */
40:         public ObjectName translate(ObjectName originalName) {
41:                 Hashtable<String, String> keyPropertyList = originalName.getKeyPropertyList();
42:                 keyPropertyList.put(REGION_KEY, regionName);
43:                 try {
44:                         return new ObjectName(originalName.getDomain(), keyPropertyList);
45:                 } catch (Exception e) {
46:                         throw new RuntimeException("Error modifying ObjectName for '" + originalName.getCanonicalName() + "'", e);
47:                 }
48:         }
49:
50: }