Search in sources :

Example 1 with Unit

use of javax.measure.unit.Unit in project ma-core-public by infiniteautomation.

the class UnitBeanConverter method convertOutbound.

/* (non-Javadoc)
	 * @see org.directwebremoting.extend.Converter#convertOutbound(java.lang.Object, org.directwebremoting.extend.OutboundContext)
	 */
@Override
public OutboundVariable convertOutbound(Object paramObject, OutboundContext paramOutboundContext) throws MarshallException {
    // Convert from Unit to String
    // Check to see if we have done this one already
    OutboundVariable ov = paramOutboundContext.get(paramObject);
    if (ov != null) {
        // So the object as been converted already, we just need to refer to it.
        return ov.getReferenceVariable();
    }
    if (paramObject instanceof Unit<?>) {
        Unit<?> unit = (Unit<?>) paramObject;
        String unitString = UnitUtil.formatLocal(unit);
        if (unit == unit.ONE)
            unitString = "ONE";
        return new SimpleOutboundVariable("'" + unitString + "';", paramOutboundContext, false);
    } else {
        throw new MarshallException(paramObject.getClass());
    }
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Unit(javax.measure.unit.Unit) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable)

Aggregations

Unit (javax.measure.unit.Unit)1 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)1 MarshallException (org.directwebremoting.extend.MarshallException)1 OutboundVariable (org.directwebremoting.extend.OutboundVariable)1