use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.MaBuilder in project onos by opennetworkinglab.
the class MaintenanceAssociationCodec method decode.
/**
* Decodes the MaintenanceAssociation entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @param mdNameLen the length of the corresponding MD's name
* @return decoded MaintenanceAssociation
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
public MaintenanceAssociation decode(ObjectNode json, CodecContext context, int mdNameLen) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode maNode = json.get(MA);
String maName = nullIsIllegal(maNode.get(MA_NAME), "maName is required").asText();
String maNameType = MaIdShort.MaIdType.CHARACTERSTRING.name();
if (maNode.get(MA_NAME_TYPE) != null) {
maNameType = maNode.get(MA_NAME_TYPE).asText();
}
try {
MaIdShort maId = MdMaNameUtil.parseMaName(maNameType, maName);
MaBuilder builder = DefaultMaintenanceAssociation.builder(maId, mdNameLen);
JsonNode maNumericIdNode = maNode.get(MA_NUMERIC_ID);
if (maNumericIdNode != null) {
short mdNumericId = (short) maNumericIdNode.asInt();
builder = builder.maNumericId(mdNumericId);
}
if (maNode.get(CCM_INTERVAL) != null) {
builder.ccmInterval(CcmInterval.valueOf(maNode.get(CCM_INTERVAL).asText()));
}
List<Component> componentList = (new ComponentCodec()).decode((ArrayNode) nullIsIllegal(maNode.get(COMPONENT_LIST), "component-list is required"), context);
for (Component component : componentList) {
builder = builder.addToComponentList(component);
}
JsonNode rmepListJson = maNode.get(RMEP_LIST);
if (rmepListJson != null) {
List<MepId> remoteMeps = (new RMepCodec()).decode((ArrayNode) rmepListJson, context);
for (MepId remoteMep : remoteMeps) {
builder = builder.addToRemoteMepIdList(remoteMep);
}
}
return builder.build();
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations