Merge "Issue #232 - Added JAXB serialization support" into 11-Collaboration

Former-commit-id: 4073ba7e7d [formerly 978b76066c] [formerly ed44b0d93f [formerly 096bb25790809f6f0919d518a29dca4f36bbd7f7]]
Former-commit-id: ed44b0d93f
Former-commit-id: 8b06b02281
This commit is contained in:
Nate Jensen 2012-03-27 08:32:19 -05:00 committed by Gerrit Code Review
commit d62fc78291
5 changed files with 210 additions and 116 deletions

View file

@ -5,12 +5,14 @@ Bundle-SymbolicName: com.raytheon.uf.viz.collaboration
Bundle-Version: 1.0.0.qualifier Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.raytheon.uf.viz.collaboration.Activator Bundle-Activator: com.raytheon.uf.viz.collaboration.Activator
Bundle-Vendor: RAYTHEON Bundle-Vendor: RAYTHEON
Eclipse-RegisterBuddy: com.raytheon.uf.viz.core
Require-Bundle: org.eclipse.core.runtime, Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf;bundle-version="3.1.300", org.eclipse.ecf;bundle-version="3.1.300",
org.eclipse.ecf.presence;bundle-version="2.0.0", org.eclipse.ecf.presence;bundle-version="2.0.0",
org.eclipse.ecf.provider.xmpp;bundle-version="3.2.0", org.eclipse.ecf.provider.xmpp;bundle-version="3.2.0",
com.google.guava;bundle-version="1.0.0", com.google.guava;bundle-version="1.0.0",
com.raytheon.uf.common.serialization;bundle-version="1.12.1174" com.raytheon.uf.common.serialization;bundle-version="1.12.1174",
com.raytheon.uf.viz.core;bundle-version="1.12.1174"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.uf.viz.collaboration, Export-Package: com.raytheon.uf.viz.collaboration,

View file

@ -0,0 +1 @@
com.raytheon.uf.viz.collaboration.comm.provider.session.TestJAXBObject

View file

@ -19,8 +19,7 @@
**/ **/
package com.raytheon.uf.viz.collaboration.comm.provider; package com.raytheon.uf.viz.collaboration.comm.provider;
import java.util.regex.Matcher; import javax.xml.bind.JAXBException;
import java.util.regex.Pattern;
import org.eclipse.ecf.core.IContainer; import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.util.Base64; import org.eclipse.ecf.core.util.Base64;
@ -49,11 +48,20 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
public abstract class Tools { public abstract class Tools {
private static final String ENV_THRIFT = "[[COMMAND#" + SerializationMode.THRIFT.name() + "]]"; private static final String ENV_THRIFT = "[[COMMAND#"
private static final String ENV_JAXB = "[[COMMAND#" + SerializationMode.JAXB.name() + "]]"; + SerializationMode.THRIFT.name() + "]]";
private static final String ENV_STRING = "[[COMMAND#" + SerializationMode.STRING.name() + "]]";
private static final String ENV_JAVA = "[[COMMAND#" + SerializationMode.JAVA.name() + "]]"; private static final String ENV_JAXB = "[[COMMAND#"
private static final String ENV_NONE = "[[COMMAND#" + SerializationMode.NONE.name() + "]]"; + SerializationMode.JAXB.name() + "]]";
private static final String ENV_STRING = "[[COMMAND#"
+ SerializationMode.STRING.name() + "]]";
private static final String ENV_JAVA = "[[COMMAND#"
+ SerializationMode.JAVA.name() + "]]";
private static final String ENV_NONE = "[[COMMAND#"
+ SerializationMode.NONE.name() + "]]";
public static final String VENUE_SUBJECT_PROP = "subject"; public static final String VENUE_SUBJECT_PROP = "subject";
@ -63,7 +71,6 @@ public abstract class Tools {
public static final String RESOURCE_DELIM = "/"; public static final String RESOURCE_DELIM = "/";
/** /**
* *
* @param <T> * @param <T>
@ -72,7 +79,8 @@ public abstract class Tools {
* @return * @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getPresenceContainerAdapter(IContainer container, Class<T> c) { public static <T> T getPresenceContainerAdapter(IContainer container,
Class<T> c) {
return (T) container.getAdapter(c); return (T) container.getAdapter(c);
} }
@ -83,10 +91,10 @@ public abstract class Tools {
*/ */
public static String parseName(String id) { public static String parseName(String id) {
String name = null; String name = null;
if(id != null) { if (id != null) {
int delimPos = id.indexOf(NAME_DELIM); int delimPos = id.indexOf(NAME_DELIM);
if(delimPos >= 0) { if (delimPos >= 0) {
name = id.substring(0,delimPos); name = id.substring(0, delimPos);
} }
} }
return name; return name;
@ -99,27 +107,27 @@ public abstract class Tools {
*/ */
public static String parseHost(String id) { public static String parseHost(String id) {
String host = null; String host = null;
if(id != null) { if (id != null) {
int delimPos = id.indexOf(NAME_DELIM); int delimPos = id.indexOf(NAME_DELIM);
if(delimPos >= 0) { if (delimPos >= 0) {
// Ok we have the start of the host name // Ok we have the start of the host name
int start = delimPos + 1; int start = delimPos + 1;
int stop = start; int stop = start;
delimPos = id.indexOf(PORT_DELIM); delimPos = id.indexOf(PORT_DELIM);
if(delimPos > stop) { if (delimPos > stop) {
// ok we have a port so grab anything in between // ok we have a port so grab anything in between
stop = delimPos; stop = delimPos;
} else { } else {
// no port delimiter, so check for the resource // no port delimiter, so check for the resource
delimPos = id.indexOf(RESOURCE_DELIM); delimPos = id.indexOf(RESOURCE_DELIM);
if(delimPos > stop) { if (delimPos > stop) {
// we have the resource delimiter // we have the resource delimiter
stop = delimPos; stop = delimPos;
} else { } else {
stop = id.length(); stop = id.length();
} }
} }
host = id.substring(start,stop); host = id.substring(start, stop);
} }
} }
return host; return host;
@ -132,23 +140,23 @@ public abstract class Tools {
*/ */
public static String parsePort(String id) { public static String parsePort(String id) {
String host = null; String host = null;
if(id != null) { if (id != null) {
int delimPos = id.indexOf(NAME_DELIM); int delimPos = id.indexOf(NAME_DELIM);
if(delimPos >= 0) { if (delimPos >= 0) {
// Ok we have the start of the host name // Ok we have the start of the host name
int start = delimPos + 1; int start = delimPos + 1;
int stop = start; int stop = start;
delimPos = id.indexOf(PORT_DELIM); delimPos = id.indexOf(PORT_DELIM);
if(delimPos > stop) { if (delimPos > stop) {
// ok we have a port so grab anything in between // ok we have a port so grab anything in between
start = delimPos + 1; start = delimPos + 1;
delimPos = id.indexOf(RESOURCE_DELIM); delimPos = id.indexOf(RESOURCE_DELIM);
if(delimPos > start) { if (delimPos > start) {
stop = delimPos; stop = delimPos;
} else { } else {
stop = id.length(); stop = id.length();
} }
host = id.substring(start,stop); host = id.substring(start, stop);
} }
} }
} }
@ -162,15 +170,15 @@ public abstract class Tools {
*/ */
public static String parseResource(String id) { public static String parseResource(String id) {
String resource = null; String resource = null;
if(id != null) { if (id != null) {
int delimPos = id.indexOf(NAME_DELIM); int delimPos = id.indexOf(NAME_DELIM);
// Ensure that the name delimiter is there first. // Ensure that the name delimiter is there first.
if(delimPos >= 0) { if (delimPos >= 0) {
int start = delimPos+1; int start = delimPos + 1;
delimPos = id.indexOf(RESOURCE_DELIM); delimPos = id.indexOf(RESOURCE_DELIM);
if(delimPos > start) { if (delimPos > start) {
delimPos++; delimPos++;
if(delimPos < id.length()) { if (delimPos < id.length()) {
resource = id.substring(delimPos); resource = id.substring(delimPos);
} }
} }
@ -181,7 +189,9 @@ public abstract class Tools {
/** /**
* Converts from an IPresence.Type to ECF Presence Type. * Converts from an IPresence.Type to ECF Presence Type.
* @param type A type to convert. *
* @param type
* A type to convert.
* @return The converted type. * @return The converted type.
*/ */
public static org.eclipse.ecf.presence.Presence.Type convertPresenceType( public static org.eclipse.ecf.presence.Presence.Type convertPresenceType(
@ -232,19 +242,22 @@ public abstract class Tools {
/** /**
* Decode Base64 encoded String data into a byte array. * Decode Base64 encoded String data into a byte array.
*
* @param message * @param message
* @return The decoded byte array data. * @return The decoded byte array data.
*/ */
public static byte [] decodeFromBase64(String message) { public static byte[] decodeFromBase64(String message) {
return Base64.decode(message); return Base64.decode(message);
} }
/** /**
* Encode byte array data into a Base64 String for transmission. * Encode byte array data into a Base64 String for transmission.
* @param message The message to encode. *
* @param message
* The message to encode.
* @return The encoded data as a String. * @return The encoded data as a String.
*/ */
public static String encodeToBase64(byte [] message) { public static String encodeToBase64(byte[] message) {
return Base64.encode(message); return Base64.encode(message);
} }
@ -268,11 +281,21 @@ public abstract class Tools {
sb.append(ENV_THRIFT); sb.append(ENV_THRIFT);
} catch (SerializationException e) { } catch (SerializationException e) {
throw new CollaborationException( throw new CollaborationException(
"Could not serialize object"); "[THRIFT] Could not serialize object");
} }
break; break;
} }
case JAXB: { case JAXB: {
try {
String s = SerializationUtil.marshalToXml(data);
if (s != null) {
sb.append(ENV_JAXB);
sb.append(s);
}
} catch (JAXBException je) {
throw new CollaborationException(
"[JAXB] Could not serialize object");
}
break; break;
} }
case JAVA: { case JAVA: {
@ -306,29 +329,36 @@ public abstract class Tools {
* @return * @return
* @throws CollaborationException * @throws CollaborationException
*/ */
public static Object unMarshallData(String data) throws CollaborationException { public static Object unMarshallData(String data)
throws CollaborationException {
Object unMarshalledData = null; Object unMarshalledData = null;
if(data != null) { if (data != null) {
// look for the envelope header first // look for the envelope header first
if(data.startsWith(ENV_THRIFT)) { if (data.startsWith(ENV_THRIFT)) {
String s = data.substring(ENV_THRIFT.length()); String s = data.substring(ENV_THRIFT.length());
try { try {
byte [] b = decodeFromBase64(s); byte[] b = decodeFromBase64(s);
unMarshalledData = SerializationUtil.transformFromThrift(b); unMarshalledData = SerializationUtil.transformFromThrift(b);
} catch (SerializationException e) { } catch (SerializationException e) {
throw new CollaborationException("Could not deserialize object"); throw new CollaborationException(
"Could not deserialize object");
} }
} else if(data.startsWith(ENV_JAXB)) { } else if (data.startsWith(ENV_JAXB)) {
throw new CollaborationException("Could not deserialize object"); String s = data.substring(ENV_JAXB.length());
} else if(data.startsWith(ENV_STRING)) { try {
unMarshalledData = SerializationUtil.unmarshalFromXml(s);
} catch (JAXBException je) {
throw new CollaborationException(
"[JAXB] Could not deserialize object");
}
} else if (data.startsWith(ENV_STRING)) {
unMarshalledData = data.substring(ENV_STRING.length()); unMarshalledData = data.substring(ENV_STRING.length());
} else if(data.startsWith(ENV_JAVA)) { } else if (data.startsWith(ENV_JAVA)) {
throw new CollaborationException("Could not deserialize object"); throw new CollaborationException("Could not deserialize object");
} else if(data.startsWith(ENV_NONE)) { } else if (data.startsWith(ENV_NONE)) {
throw new CollaborationException("Could not deserialize object"); throw new CollaborationException("Could not deserialize object");
} }
} }
return unMarshalledData; return unMarshalledData;
} }
} }

View file

@ -0,0 +1,70 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.comm.provider.session;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.raytheon.uf.common.serialization.ISerializableObject;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IRenderable;
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class TestJAXBObject implements IRenderable, ISerializableObject {
@XmlElement
protected String item_1 = null;
@XmlElement
private Integer value = -1;
public TestJAXBObject() {
}
/**
* @return the item_1
*/
public String getItem_1() {
return item_1;
}
/**
* @param item_1 the item_1 to set
*/
public void setItem_1(String item_1) {
this.item_1 = item_1;
}
/**
* @return the value
*/
public Integer getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(Integer value) {
this.value = value;
}
}

View file

@ -225,61 +225,45 @@ public class VenueSession extends BaseSession implements IVenueSession,
} finally { } finally {
initListeners(); initListeners();
} }
// Runnable r = new Runnable() {
Runnable r = new Runnable() { // @Override
@Override // public void run() {
public void run() { // try {
for (int i = 0; i < 10; i++) { // Thread.sleep(20000);
//
IRenderable r = new TestObject("Test1"); // TestJAXBObject j = new TestJAXBObject();
((TestObject) r).setValue(i); // j.setItem_1("This is an object");
// j.setValue(5);
try { // sendRenderableObject(j);
System.out.println("Sending renderable " + i); // } catch (Exception e) {
sendRenderableObject(r); // System.out.println("Error sending RenderableObject");
if (i == 5) { // }
sendTextMessage(Tools // }
.marshallData("This is a text message as a String")); // };
// Thread t = new Thread(r);
// t.start();
// registerEventHandler(this);
} }
} catch (CollaborationException ce) { // @Subscribe
ce.printStackTrace(); // public void handle(IRenderable renderable) {
} // System.out.println("Renderable found");
try { // if(renderable instanceof TestJAXBObject) {
Thread.sleep(10000); // TestJAXBObject j = (TestJAXBObject) renderable;
} catch (InterruptedException ie) { // if(j.getValue() < 100) {
} // System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue()));
} // j.setValue(j.getValue() + 200);
} // j.setItem_1("Now for the return trip");
}; // try {
Thread t = new Thread(r); // sendRenderableObject(j);
t.start(); // } catch (CollaborationException ce) {
// System.out.println("Error sending RenderableObject");
registerEventHandler(this); // }
} // } else {
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue()));
@Subscribe // }
public void handle(IRenderable renderable) { // }
System.out.println("IRenderable " + renderable.getClass().getName() // }
+ " was received");
}
@Subscribe
public void handle(IDisplayEvent event) {
System.out.println("IDisplayEvent " + event.getClass().getName()
+ " was received");
}
@Subscribe
public void handle(String string) {
System.out.println("String \"" + string + "\" was received");
}
@Subscribe
public void handle(IVenueParticipantEvent event) {
System.out.println("IVenueParticipantEvent " + event.getEventType()
+ " was received");
}
/** /**
* *
@ -628,6 +612,13 @@ public class VenueSession extends BaseSession implements IVenueSession,
// ISharedDisplaySession // ISharedDisplaySession
// *************************** // ***************************
/**
*
* @param participant
* @param initData
* @throws CollaborationException
* @see com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession#sendInitData(com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID, com.raytheon.uf.viz.collaboration.comm.identity.event.IInitData)
*/
@Override @Override
public void sendInitData( public void sendInitData(
com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID participant, com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID participant,