Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.virgo.management.fragment')
-rw-r--r--org.eclipse.virgo.management.fragment/.settings/com.springsource.server.ide.bundlor.core.prefs3
-rw-r--r--org.eclipse.virgo.management.fragment/.settings/org.eclipse.wst.common.project.facet.core.xml4
-rw-r--r--org.eclipse.virgo.management.fragment/.settings/org.springframework.ide.eclipse.beans.core.prefs3
-rw-r--r--org.eclipse.virgo.management.fragment/build.xml9
-rw-r--r--org.eclipse.virgo.management.fragment/ivy.xml22
-rw-r--r--org.eclipse.virgo.management.fragment/src/main/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslator.java50
-rw-r--r--org.eclipse.virgo.management.fragment/src/test/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslatorTests.java77
-rw-r--r--org.eclipse.virgo.management.fragment/template.mf13
8 files changed, 181 insertions, 0 deletions
diff --git a/org.eclipse.virgo.management.fragment/.settings/com.springsource.server.ide.bundlor.core.prefs b/org.eclipse.virgo.management.fragment/.settings/com.springsource.server.ide.bundlor.core.prefs
new file mode 100644
index 00000000..61ee8a9b
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/.settings/com.springsource.server.ide.bundlor.core.prefs
@@ -0,0 +1,3 @@
+#Mon Jul 06 09:06:52 BST 2009
+com.springsource.server.ide.bundlor.core.template.properties.files=../build.properties;../build.versions
+eclipse.preferences.version=1
diff --git a/org.eclipse.virgo.management.fragment/.settings/org.eclipse.wst.common.project.facet.core.xml b/org.eclipse.virgo.management.fragment/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 00000000..92aa2909
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="org.eclipse.virgo.server.bundle" version="1.0"/>
+</faceted-project>
diff --git a/org.eclipse.virgo.management.fragment/.settings/org.springframework.ide.eclipse.beans.core.prefs b/org.eclipse.virgo.management.fragment/.settings/org.springframework.ide.eclipse.beans.core.prefs
new file mode 100644
index 00000000..e68da314
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/.settings/org.springframework.ide.eclipse.beans.core.prefs
@@ -0,0 +1,3 @@
+#Mon Jul 06 16:49:15 BST 2009
+eclipse.preferences.version=1
+org.springframework.ide.eclipse.beans.core.ignoreMissingNamespaceHandler=false
diff --git a/org.eclipse.virgo.management.fragment/build.xml b/org.eclipse.virgo.management.fragment/build.xml
new file mode 100644
index 00000000..aaabed2e
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/build.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="org.eclipse.virgo.management.fragment">
+
+ <property name="clover.enforce" value="false"/>
+ <property file="${basedir}/../build.properties"/>
+ <property file="${basedir}/../build.versions"/>
+ <import file="${basedir}/../virgo-build/standard/default.xml"/>
+
+</project>
diff --git a/org.eclipse.virgo.management.fragment/ivy.xml b/org.eclipse.virgo.management.fragment/ivy.xml
new file mode 100644
index 00000000..dfb1c39a
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/ivy.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" version="2.0">
+
+ <info organisation="org.eclipse.virgo.management" module="${ant.project.name}"/>
+
+ <configurations>
+ <include file="${virgo.build.dir}/common/default-ivy-configurations.xml"/>
+ </configurations>
+
+ <publications>
+ <artifact name="${ant.project.name}"/>
+ <artifact name="${ant.project.name}-sources" type="src" ext="jar"/>
+ </publications>
+
+ <dependencies>
+ <dependency org="org.eclipse.gemini" name="org.eclipse.gemini.management" rev="${org.eclipse.gemini.management}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.eclipse.equinox.region" rev="${org.eclipse.equinox.region}" conf="compile->runtime" />
+ <dependency org="org.junit" name="com.springsource.org.junit" rev="${org.junit}" conf="test->runtime"/>
+ <dependency org="org.easymock" name="com.springsource.org.easymock" rev="${org.easymock}" conf="test->runtime"/>
+ </dependencies>
+
+</ivy-module>
diff --git a/org.eclipse.virgo.management.fragment/src/main/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslator.java b/org.eclipse.virgo.management.fragment/src/main/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslator.java
new file mode 100644
index 00000000..c69c293d
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/src/main/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslator.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.management.fragment;
+
+import java.util.Hashtable;
+
+import javax.management.ObjectName;
+
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.eclipse.gemini.management.ObjectNameTranslator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class VirgoObjectNameTranslator implements ObjectNameTranslator{
+
+ private static final String REGION_KEY = "region";
+
+ private final String regionName;
+
+ public VirgoObjectNameTranslator(BundleContext context) {
+ ServiceReference<RegionDigraph> serviceReference = context.getServiceReference(RegionDigraph.class);
+ RegionDigraph service = context.getService(serviceReference);
+ Region region = service.getRegion(context.getBundle().getBundleId());
+ this.regionName = region.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ObjectName translate(ObjectName originalName) {
+ Hashtable<String, String> keyPropertyList = originalName.getKeyPropertyList();
+ keyPropertyList.put(REGION_KEY, regionName);
+ try {
+ return new ObjectName(originalName.getDomain(), keyPropertyList);
+ } catch (Exception e) {
+ throw new RuntimeException("Error modifying ObjectName for '" + originalName.getCanonicalName() + "'", e);
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.management.fragment/src/test/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslatorTests.java b/org.eclipse.virgo.management.fragment/src/test/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslatorTests.java
new file mode 100644
index 00000000..8b8c4b4a
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/src/test/java/org/eclipse/virgo/management/fragment/VirgoObjectNameTranslatorTests.java
@@ -0,0 +1,77 @@
+package org.eclipse.virgo.management.fragment;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Hashtable;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.easymock.EasyMock;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class VirgoObjectNameTranslatorTests {
+
+ private static final String MOCK_REGION_NAME = "testRegion";
+
+ private ObjectName testObjectName;
+
+ private ObjectName testObjectNameTranslation;
+
+ private BundleContext mockContext;
+
+ private ServiceReference<RegionDigraph> mockServiceReference;
+
+ private Bundle mockBundle;
+
+ private RegionDigraph mockRegionDigraph;
+
+ private Region mockRegion;
+
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setup() throws MalformedObjectNameException, NullPointerException{
+ Hashtable<String, String> table = new Hashtable<String, String>();
+ table.put("testKey", "testValue");
+ testObjectName = ObjectName.getInstance("testDomain", table);
+ table.put("region", MOCK_REGION_NAME);
+ testObjectNameTranslation = ObjectName.getInstance("testDomain", table);
+ mockContext = EasyMock.createMock(BundleContext.class);
+ mockServiceReference = (ServiceReference<RegionDigraph>) EasyMock.createMock(ServiceReference.class);
+ mockBundle = EasyMock.createMock(Bundle.class);
+ mockRegionDigraph = EasyMock.createMock(RegionDigraph.class);
+ mockRegion = EasyMock.createMock(Region.class);
+ EasyMock.expect(mockContext.getServiceReference(RegionDigraph.class)).andReturn(mockServiceReference);
+ EasyMock.expect(mockContext.getService(mockServiceReference)).andReturn(mockRegionDigraph);
+ EasyMock.expect(mockContext.getBundle()).andReturn(mockBundle);
+ EasyMock.expect(mockBundle.getBundleId()).andReturn(5l);
+ EasyMock.expect(mockRegionDigraph.getRegion(5l)).andReturn(mockRegion);
+ EasyMock.expect(mockRegion.getName()).andReturn(MOCK_REGION_NAME);
+ }
+
+ private void replayMocks() {
+ EasyMock.replay(mockContext, mockServiceReference, mockBundle, mockRegionDigraph, mockRegion);
+ }
+
+ @After
+ public void tearDown() {
+ EasyMock.verify(mockContext, mockServiceReference, mockBundle, mockRegionDigraph, mockRegion);
+ }
+
+ @Test
+ public void test() {
+ replayMocks();
+ VirgoObjectNameTranslator virgoObjectNameTranslator = new VirgoObjectNameTranslator(mockContext);
+ ObjectName translatedObjectName = virgoObjectNameTranslator.translate(testObjectName);
+ assertEquals(testObjectNameTranslation, translatedObjectName);
+ }
+
+}
diff --git a/org.eclipse.virgo.management.fragment/template.mf b/org.eclipse.virgo.management.fragment/template.mf
new file mode 100644
index 00000000..86241942
--- /dev/null
+++ b/org.eclipse.virgo.management.fragment/template.mf
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Virgo Management Fragment
+Fragment-Host: org.eclipse.gemini.management;bundle-version="${geminiManagementVersion:[=.=.=, =.+1)}"
+Bundle-SymbolicName: org.eclipse.virgo.management.fragment
+Bundle-Version: ${version}
+GeminiManagement-ObjectNameTranslator: org.eclipse.virgo.management.fragment.VirgoObjectNameTranslator
+Import-Package:
+ org.eclipse.equinox.region;version="${equinoxRegionVersion:[=.=.=, =.+1)}",
+ javax.management;version="0",
+ org.osgi.framework;version="0"
+Excluded-Imports: org.eclipse.gemini.management
+Excluded-Exports: *

Back to the top