private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class);
private static Properties yangMappingProperties = new Properties();
- protected static boolean useLegacyEnumerationMapping = false;
-
- public static void useLegacyEnumerationMapping(Boolean bool) {
- useLegacyEnumerationMapping = bool;
- }
@Deprecated
public static void setProperties(Properties input) {
}
public static Properties toProperties(Properties props, Object fromObj) {
+ return toProperties(props, fromObj, false);
+ }
+
+ public static Properties toProperties(Properties props, Object fromObj, Boolean useLegacyEnumerationMapping) {
Class fromClass = null;
if (fromObj != null) {
fromClass = fromObj.getClass();
}
- return toProperties(props, "", fromObj, fromClass);
+ return toProperties(props, "", fromObj, fromClass,useLegacyEnumerationMapping );
}
public static Properties toProperties(Properties props, String pfx, Object fromObj) {
+ return toProperties(props, pfx, fromObj, false);
+ }
+
+ public static Properties toProperties(Properties props, String pfx, Object fromObj, Boolean useLegacyEnumerationMapping) {
Class fromClass = null;
if (fromObj != null) {
fromClass = fromObj.getClass();
}
- return toProperties(props, pfx, fromObj, fromClass);
+ return toProperties(props, pfx, fromObj, fromClass, useLegacyEnumerationMapping);
}
public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) {
+ return toProperties(props, pfx, fromObj, fromClass, false);
+ }
+
+ public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass, Boolean useLegacyEnumerationMapping) {
if (fromObj == null) {
return props;
List fromList = (List) fromObj;
for (int i = 0; i < fromList.size(); i++) {
- toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
+ toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass, useLegacyEnumerationMapping);
}
props.setProperty(pfx + "_length", Integer.toString(fromList.size()));
m.setAccessible(isAccessible);
}
if (retValue != null) {
- toProperties(props, propNamePfx + "." + fieldName, retValue, returnType);
+ toProperties(props, propNamePfx + "." + fieldName, retValue, returnType, useLegacyEnumerationMapping);
}
} catch (Exception e) {
// this array.
Type paramType = m.getGenericReturnType();
Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0];
- toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType);
+ toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType, useLegacyEnumerationMapping);
} catch (Exception e) {
LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "."
+ m.getName() + "() to Properties entry", e);
// During the default enumeration mapping no properties file is needed, the yang value is returned
// by the java object
public void testDefaultEnumerationMapping() throws Exception {
- MdsalHelper.useLegacyEnumerationMapping(false);
Properties props = new Properties();
MdsalHelper.toProperties(props, new WrapperObj());
assertEquals("4COS", props.getProperty("wrapper-obj.cos-model-type"));
// When no properties file exists the default java value will be returned if legacy enumeration
// mapping is enabled
public void testLegacyEnumerationMappingNoProperties() throws Exception {
- MdsalHelper.useLegacyEnumerationMapping(true);
Properties props = new Properties();
- MdsalHelper.toProperties(props, new WrapperObj());
+ MdsalHelper.toProperties(props, new WrapperObj(), true);
assertEquals("_4COS", props.getProperty("wrapper-obj.cos-model-type"));
}
// properties file should be returned
public void testLegacyEnumerationMappingWithProperties() throws Exception {
MdsalHelper.loadProperties("src/test/resources/EnumerationMapping.properties");
- MdsalHelper.useLegacyEnumerationMapping(true);
Properties props = new Properties();
- MdsalHelper.toProperties(props, new WrapperObj());
+ MdsalHelper.toProperties(props, new WrapperObj(), true);
assertEquals("HelloWorld", props.getProperty("wrapper-obj.cos-model-type"));
}
}