Search in sources :

Example 1 with Property

use of cern.laser.source.alarmsysteminterface.impl.message.Property in project ACS by ACS-Community.

the class FaultStateHelper method unmarshal.

/**
   * Unmarshal a generated FaultState into a FaultState instance.
   * 
   * @param generated The generated FaultState
   * @return The FaultState instance
   */
public static FaultState unmarshal(cern.laser.source.alarmsysteminterface.impl.message.FaultState generated) {
    FaultState state = new FaultStateImpl();
    state.setFamily(generated.getFamily());
    state.setMember(generated.getMember());
    state.setCode(generated.getCode());
    state.setDescriptor(generated.getDescriptor());
    Date timestamp;
    try {
        timestamp = IsoDateFormat.parseIsoTimestamp(generated.getUserTimestamp());
        state.setUserTimestamp(new Timestamp(timestamp.getTime()));
    } catch (ParseException pe) {
        System.err.println("Error paring ISO timestamp from " + generated.getUserTimestamp());
        System.err.println("Setting to surrent time! " + generated.getUserTimestamp());
        pe.printStackTrace(System.err);
        state.setUserTimestamp(new Timestamp(System.currentTimeMillis()));
    }
    Properties properties = new Properties();
    if (generated.getUserProperties() != null) {
        Enumeration property_enum = generated.getUserProperties().enumerateProperty();
        while (property_enum.hasMoreElements()) {
            Property property = (Property) property_enum.nextElement();
            properties.setProperty(property.getName(), property.getValue());
        }
    }
    state.setUserProperties(properties);
    return state;
}
Also used : Enumeration(java.util.Enumeration) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ParseException(java.text.ParseException) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) Property(cern.laser.source.alarmsysteminterface.impl.message.Property) Date(java.util.Date)

Example 2 with Property

use of cern.laser.source.alarmsysteminterface.impl.message.Property in project ACS by ACS-Community.

the class FaultStateHelper method marshal.

/**
   * Marshal a FaultState into a generated FaultState for XML transport.
   * 
   * @param state The FaultState instance
   * @return The generated FaultState
   */
public static cern.laser.source.alarmsysteminterface.impl.message.FaultState marshal(FaultState state) {
    cern.laser.source.alarmsysteminterface.impl.message.FaultState generated = new cern.laser.source.alarmsysteminterface.impl.message.FaultState();
    generated.setFamily(state.getFamily());
    generated.setMember(state.getMember());
    generated.setCode(state.getCode());
    generated.setDescriptor(state.getDescriptor());
    generated.setUserTimestamp(IsoDateFormat.formatDate(new Date(state.getUserTimestamp().getTime())));
    cern.laser.source.alarmsysteminterface.impl.message.Properties properties = new cern.laser.source.alarmsysteminterface.impl.message.Properties();
    Enumeration names = state.getUserProperties().propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Property property = new Property();
        property.setName(name);
        property.setValue(state.getUserProperties().getProperty(name));
        properties.addProperty(property);
    }
    generated.setUserProperties(properties);
    return generated;
}
Also used : Enumeration(java.util.Enumeration) FaultState(cern.laser.source.alarmsysteminterface.FaultState) Properties(java.util.Properties) Date(java.util.Date) Property(cern.laser.source.alarmsysteminterface.impl.message.Property)

Aggregations

FaultState (cern.laser.source.alarmsysteminterface.FaultState)2 Property (cern.laser.source.alarmsysteminterface.impl.message.Property)2 Date (java.util.Date)2 Enumeration (java.util.Enumeration)2 Properties (java.util.Properties)2 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1