geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r883991 [2/2] - in /geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/blueprint/ s...
Date Wed, 25 Nov 2009 06:28:21 GMT
Added: geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl/src/main/java/org/apache/geronimo/blueprint/jmx/impl/codec/Util.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl/src/main/java/org/apache/geronimo/blueprint/jmx/impl/codec/Util.java?rev=883991&view=auto
==============================================================================
--- geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl/src/main/java/org/apache/geronimo/blueprint/jmx/impl/codec/Util.java
(added)
+++ geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl/src/main/java/org/apache/geronimo/blueprint/jmx/impl/codec/Util.java
Wed Nov 25 06:28:19 2009
@@ -0,0 +1,145 @@
+package org.apache.geronimo.blueprint.jmx.impl.codec;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.management.openmbean.CompositeData;
+
+import org.apache.geronimo.blueprint.jmx.BlueprintMetadataMBean;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.IdRefMetadata;
+import org.osgi.service.blueprint.reflect.MapMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.NullMetadata;
+import org.osgi.service.blueprint.reflect.PropsMetadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceListMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceMetadata;
+import org.osgi.service.blueprint.reflect.ServiceMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+
+public class Util {
+
+	public static BPMetadata metadata2BPMetadata(Metadata metadata)
+	{
+		//target first
+		if(metadata instanceof BeanMetadata)
+			return new BPBeanMetadata((BeanMetadata)metadata);
+		
+		if(metadata instanceof ReferenceMetadata)
+			return new BPReferenceMetadata((ReferenceMetadata)metadata);
+		
+		if(metadata instanceof RefMetadata)
+			return new BPRefMetadata((RefMetadata)metadata);
+		
+		//others
+		if(metadata instanceof CollectionMetadata)
+			return new BPCollectionMetadata((CollectionMetadata)metadata);
+		
+		if(metadata instanceof ServiceMetadata)
+			return new BPServiceMetadata((ServiceMetadata)metadata);
+		
+		if(metadata instanceof ReferenceListMetadata)
+			return new BPReferenceListMetadata((ReferenceListMetadata)metadata);
+		
+		if(metadata instanceof IdRefMetadata)
+			return new BPIdRefMetadata((IdRefMetadata)metadata);
+		
+		if(metadata instanceof MapMetadata)
+			return new BPMapMetadata((MapMetadata)metadata);
+		
+		if(metadata instanceof PropsMetadata)
+			return new BPPropsMetadata((PropsMetadata)metadata);
+		
+		if(metadata instanceof ValueMetadata)
+			return new BPValueMetadata((ValueMetadata)metadata);
+		
+		//null last
+		if(metadata instanceof NullMetadata)
+			return new BPNullMetadata((NullMetadata)metadata);
+		
+		throw new RuntimeException("Unknown metadata type");
+	}
+	
+	public static BPMetadata binary2BPMetadata(byte [] buf)
+	{
+		ByteArrayInputStream inBytes = new ByteArrayInputStream(buf);
+        ObjectInputStream inObject;
+        CompositeData metadata;
+		try {
+			inObject = new ObjectInputStream(inBytes);
+			metadata = (CompositeData)inObject.readObject();
+	        inObject.close();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+			return null;
+		}
+        
+        
+        String typename = metadata.getCompositeType().getTypeName();
+        
+		//target first
+		if(typename.equals(BlueprintMetadataMBean.BEAN_METADATA))
+			return new BPBeanMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.REFERENCE_METADATA))
+			return new BPReferenceMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.REF_METADATA))
+			return new BPRefMetadata(metadata);
+		
+		//others
+		if(typename.equals(BlueprintMetadataMBean.COLLECTION_METADATA))
+			return new BPCollectionMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.SERVICE_MATADATA))
+			return new BPServiceMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.REFERENCE_LIST_METADATA))
+  		    return new BPReferenceListMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.ID_REF_METADATA))
+			return new BPIdRefMetadata(metadata);
+
+		if(typename.equals(BlueprintMetadataMBean.MAP_METADATA))
+			return new BPMapMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.PROPS_METADATA))
+			return new BPPropsMetadata(metadata);
+		
+		if(typename.equals(BlueprintMetadataMBean.VALUE_METADATA))
+			return new BPValueMetadata(metadata);
+		
+		//null last
+		if(metadata instanceof NullMetadata)
+			return new BPNullMetadata(metadata);
+		
+		return null;
+	}
+	
+	public static byte [] bpMetadata2Binary(BPMetadata metadata)
+	{
+		if(!(metadata instanceof TransferObject))
+			throw new RuntimeException("Non-TransferObject metadata can not be translated into byte
array");
+		
+		TransferObject data = (TransferObject)metadata;
+		
+		ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+		ObjectOutputStream outObject;
+		try {
+			outObject = new ObjectOutputStream(outBytes);
+			outObject.writeObject(data.asCompositeData());
+			outObject.close();
+		} catch (IOException e) {//there is no io op
+			throw new RuntimeException(e);
+		}
+		
+		return outBytes.toByteArray();
+	}
+}

Propchange: geronimo/sandbox/rex/org.apache.geronimo.blueprint.jmx.impl/src/main/java/org/apache/geronimo/blueprint/jmx/impl/codec/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message