Merge "Issue #232 - Added JAXB serialization support" into 11-Collaboration
Former-commit-id:978b76066c
[formerly978b76066c
[formerly 096bb25790809f6f0919d518a29dca4f36bbd7f7]] Former-commit-id:ed44b0d93f
Former-commit-id:8b06b02281
This commit is contained in:
commit
0805c13d39
5 changed files with 210 additions and 116 deletions
|
@ -5,12 +5,14 @@ Bundle-SymbolicName: com.raytheon.uf.viz.collaboration
|
|||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.raytheon.uf.viz.collaboration.Activator
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Eclipse-RegisterBuddy: com.raytheon.uf.viz.core
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.ecf;bundle-version="3.1.300",
|
||||
org.eclipse.ecf.presence;bundle-version="2.0.0",
|
||||
org.eclipse.ecf.provider.xmpp;bundle-version="3.2.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-ActivationPolicy: lazy
|
||||
Export-Package: com.raytheon.uf.viz.collaboration,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
com.raytheon.uf.viz.collaboration.comm.provider.session.TestJAXBObject
|
|
@ -19,8 +19,7 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.collaboration.comm.provider;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.eclipse.ecf.core.IContainer;
|
||||
import org.eclipse.ecf.core.util.Base64;
|
||||
|
@ -34,36 +33,44 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
|
|||
* TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 7, 2012 jkorman Initial creation
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @author jkorman
|
||||
* @version 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public abstract class Tools {
|
||||
|
||||
private static final String ENV_THRIFT = "[[COMMAND#" + SerializationMode.THRIFT.name() + "]]";
|
||||
private static final String ENV_JAXB = "[[COMMAND#" + 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() + "]]";
|
||||
|
||||
private static final String ENV_THRIFT = "[[COMMAND#"
|
||||
+ SerializationMode.THRIFT.name() + "]]";
|
||||
|
||||
private static final String ENV_JAXB = "[[COMMAND#"
|
||||
+ 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 NAME_DELIM = "@";
|
||||
|
||||
|
||||
public static final String PORT_DELIM = ":";
|
||||
|
||||
|
||||
public static final String RESOURCE_DELIM = "/";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
|
@ -72,7 +79,8 @@ public abstract class Tools {
|
|||
* @return
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
|
@ -83,10 +91,10 @@ public abstract class Tools {
|
|||
*/
|
||||
public static String parseName(String id) {
|
||||
String name = null;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
int delimPos = id.indexOf(NAME_DELIM);
|
||||
if(delimPos >= 0) {
|
||||
name = id.substring(0,delimPos);
|
||||
if (delimPos >= 0) {
|
||||
name = id.substring(0, delimPos);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
|
@ -99,27 +107,27 @@ public abstract class Tools {
|
|||
*/
|
||||
public static String parseHost(String id) {
|
||||
String host = null;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
int delimPos = id.indexOf(NAME_DELIM);
|
||||
if(delimPos >= 0) {
|
||||
if (delimPos >= 0) {
|
||||
// Ok we have the start of the host name
|
||||
int start = delimPos + 1;
|
||||
int stop = start;
|
||||
delimPos = id.indexOf(PORT_DELIM);
|
||||
if(delimPos > stop) {
|
||||
if (delimPos > stop) {
|
||||
// ok we have a port so grab anything in between
|
||||
stop = delimPos;
|
||||
} else {
|
||||
// no port delimiter, so check for the resource
|
||||
delimPos = id.indexOf(RESOURCE_DELIM);
|
||||
if(delimPos > stop) {
|
||||
if (delimPos > stop) {
|
||||
// we have the resource delimiter
|
||||
stop = delimPos;
|
||||
} else {
|
||||
stop = id.length();
|
||||
}
|
||||
}
|
||||
host = id.substring(start,stop);
|
||||
host = id.substring(start, stop);
|
||||
}
|
||||
}
|
||||
return host;
|
||||
|
@ -132,29 +140,29 @@ public abstract class Tools {
|
|||
*/
|
||||
public static String parsePort(String id) {
|
||||
String host = null;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
int delimPos = id.indexOf(NAME_DELIM);
|
||||
if(delimPos >= 0) {
|
||||
if (delimPos >= 0) {
|
||||
// Ok we have the start of the host name
|
||||
int start = delimPos + 1;
|
||||
int stop = start;
|
||||
delimPos = id.indexOf(PORT_DELIM);
|
||||
if(delimPos > stop) {
|
||||
if (delimPos > stop) {
|
||||
// ok we have a port so grab anything in between
|
||||
start = delimPos + 1;
|
||||
delimPos = id.indexOf(RESOURCE_DELIM);
|
||||
if(delimPos > start) {
|
||||
if (delimPos > start) {
|
||||
stop = delimPos;
|
||||
} else {
|
||||
stop = id.length();
|
||||
}
|
||||
host = id.substring(start,stop);
|
||||
host = id.substring(start, stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
|
@ -162,15 +170,15 @@ public abstract class Tools {
|
|||
*/
|
||||
public static String parseResource(String id) {
|
||||
String resource = null;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
int delimPos = id.indexOf(NAME_DELIM);
|
||||
// Ensure that the name delimiter is there first.
|
||||
if(delimPos >= 0) {
|
||||
int start = delimPos+1;
|
||||
if (delimPos >= 0) {
|
||||
int start = delimPos + 1;
|
||||
delimPos = id.indexOf(RESOURCE_DELIM);
|
||||
if(delimPos > start) {
|
||||
if (delimPos > start) {
|
||||
delimPos++;
|
||||
if(delimPos < id.length()) {
|
||||
if (delimPos < id.length()) {
|
||||
resource = id.substring(delimPos);
|
||||
}
|
||||
}
|
||||
|
@ -178,10 +186,12 @@ public abstract class Tools {
|
|||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static org.eclipse.ecf.presence.Presence.Type convertPresenceType(
|
||||
|
@ -228,26 +238,29 @@ public abstract class Tools {
|
|||
}
|
||||
|
||||
return sType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Base64 encoded String data into a byte array.
|
||||
* Decode Base64 encoded String data into a byte array.
|
||||
*
|
||||
* @param message
|
||||
* @return The decoded byte array data.
|
||||
*/
|
||||
public static byte [] decodeFromBase64(String message) {
|
||||
public static byte[] decodeFromBase64(String message) {
|
||||
return Base64.decode(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static String encodeToBase64(byte [] message) {
|
||||
public static String encodeToBase64(byte[] message) {
|
||||
return Base64.encode(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
|
@ -268,11 +281,21 @@ public abstract class Tools {
|
|||
sb.append(ENV_THRIFT);
|
||||
} catch (SerializationException e) {
|
||||
throw new CollaborationException(
|
||||
"Could not serialize object");
|
||||
"[THRIFT] Could not serialize object");
|
||||
}
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
case JAVA: {
|
||||
|
@ -299,36 +322,43 @@ public abstract class Tools {
|
|||
}
|
||||
return marshalledData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
* @throws CollaborationException
|
||||
*/
|
||||
public static Object unMarshallData(String data) throws CollaborationException {
|
||||
public static Object unMarshallData(String data)
|
||||
throws CollaborationException {
|
||||
Object unMarshalledData = null;
|
||||
if(data != null) {
|
||||
if (data != null) {
|
||||
// look for the envelope header first
|
||||
if(data.startsWith(ENV_THRIFT)) {
|
||||
if (data.startsWith(ENV_THRIFT)) {
|
||||
String s = data.substring(ENV_THRIFT.length());
|
||||
try {
|
||||
byte [] b = decodeFromBase64(s);
|
||||
byte[] b = decodeFromBase64(s);
|
||||
unMarshalledData = SerializationUtil.transformFromThrift(b);
|
||||
} catch (SerializationException e) {
|
||||
throw new CollaborationException("Could not deserialize object");
|
||||
throw new CollaborationException(
|
||||
"Could not deserialize object");
|
||||
}
|
||||
} else if(data.startsWith(ENV_JAXB)) {
|
||||
throw new CollaborationException("Could not deserialize object");
|
||||
} else if(data.startsWith(ENV_STRING)) {
|
||||
} else if (data.startsWith(ENV_JAXB)) {
|
||||
String s = data.substring(ENV_JAXB.length());
|
||||
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());
|
||||
} else if(data.startsWith(ENV_JAVA)) {
|
||||
} else if (data.startsWith(ENV_JAVA)) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
return unMarshalledData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -225,62 +225,46 @@ public class VenueSession extends BaseSession implements IVenueSession,
|
|||
} finally {
|
||||
initListeners();
|
||||
}
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
IRenderable r = new TestObject("Test1");
|
||||
((TestObject) r).setValue(i);
|
||||
|
||||
try {
|
||||
System.out.println("Sending renderable " + i);
|
||||
sendRenderableObject(r);
|
||||
if (i == 5) {
|
||||
sendTextMessage(Tools
|
||||
.marshallData("This is a text message as a String"));
|
||||
}
|
||||
|
||||
} catch (CollaborationException ce) {
|
||||
ce.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
|
||||
registerEventHandler(this);
|
||||
}
|
||||
|
||||
@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");
|
||||
// Runnable r = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// Thread.sleep(20000);
|
||||
//
|
||||
// TestJAXBObject j = new TestJAXBObject();
|
||||
// j.setItem_1("This is an object");
|
||||
// j.setValue(5);
|
||||
// sendRenderableObject(j);
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// Thread t = new Thread(r);
|
||||
// t.start();
|
||||
// registerEventHandler(this);
|
||||
}
|
||||
|
||||
// @Subscribe
|
||||
// public void handle(IRenderable renderable) {
|
||||
// System.out.println("Renderable found");
|
||||
// if(renderable instanceof TestJAXBObject) {
|
||||
// TestJAXBObject j = (TestJAXBObject) renderable;
|
||||
// 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 {
|
||||
// sendRenderableObject(j);
|
||||
// } catch (CollaborationException ce) {
|
||||
// System.out.println("Error sending RenderableObject");
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(String.format("%s %d Renderable", j.getItem_1(), j.getValue()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws ECFException
|
||||
|
@ -628,6 +612,13 @@ public class VenueSession extends BaseSession implements IVenueSession,
|
|||
// 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
|
||||
public void sendInitData(
|
||||
com.raytheon.uf.viz.collaboration.comm.identity.user.IChatID participant,
|
||||
|
|
Loading…
Add table
Reference in a new issue