From: Alessandro Boch Date: Wed, 18 Dec 2013 20:13:50 +0000 (+0000) Subject: Merge "Lazily initialize jaxb context in NB application" X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~167 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=0563e3f9bbfc5c8fdcb910046738534126901e9a;hp=7f2e6aa488a5b99a331421684886b9afe47259d2 Merge "Lazily initialize jaxb context in NB application" --- diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java index b0588a0903..fa9e0f169e 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java @@ -115,10 +115,10 @@ public abstract class AbstractConfigTest extends protected void assertStatus(CommitStatus status, int expectedNewInstances, int expectedRecreatedInstances, int expectedReusedInstances) { - assertEquals(expectedNewInstances, status.getNewInstances().size()); - assertEquals(expectedRecreatedInstances, status.getRecreatedInstances() + assertEquals("New instances mismatch in " + status, expectedNewInstances, status.getNewInstances().size()); + assertEquals("Recreated instances mismatch in " + status, expectedRecreatedInstances, status.getRecreatedInstances() .size()); - assertEquals(expectedReusedInstances, status.getReusedInstances() + assertEquals("Reused instances mismatch in " + status, expectedReusedInstances, status.getReusedInstances() .size()); } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java index 28e0256c05..49a20bd462 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java @@ -26,6 +26,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIf import org.opendaylight.controller.config.yangjmxgenerator.attribute.Dependency; import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.VoidAttribute; @@ -623,6 +624,7 @@ public class TemplateFactory { } boolean isDependency = false; + boolean isListOfDependencies = false; Dependency dependency = null; Annotation overrideAnnotation = new Annotation("Override", Collections. emptyList()); @@ -635,12 +637,15 @@ public class TemplateFactory { .getDependency(); annotations.add(Annotation .createRequireIfcAnnotation(dependency.getSie())); + if (attributeIfc instanceof ListDependenciesAttribute) { + isListOfDependencies = true; + } } String varName = BindingGeneratorUtil .parseToValidParamName(attrEntry.getKey()); moduleFields.add(new ModuleField(type, varName, attributeIfc - .getUpperCaseCammelCase(), nullableDefaultWrapped, isDependency, dependency)); + .getUpperCaseCammelCase(), nullableDefaultWrapped, isDependency, dependency, isListOfDependencies)); String getterName = "get" + attributeIfc.getUpperCaseCammelCase(); @@ -657,10 +662,16 @@ public class TemplateFactory { .createDescriptionAnnotation(attributeIfc.getNullableDescription())); } + String setterBody = "this." + varName + " = " + varName + ";"; + if (isListOfDependencies) { + String nullCheck = String.format("if (%s == null) throw new IllegalArgumentException(\"Null not supported\");%n", + varName); + setterBody = nullCheck + setterBody; + } MethodDefinition setter = new MethodDefinition("void", setterName, Lists.newArrayList(new Field(type, varName)), - annotations, "this." + varName + " = " + varName + ";"); + annotations, setterBody); setter.setJavadoc(attributeIfc.getNullableDescription()); methods.add(getter); diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleField.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleField.java index 5624e169da..aff7af2811 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleField.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleField.java @@ -17,12 +17,12 @@ import java.util.List; public class ModuleField extends Field { private final String nullableDefault, attributeName; - private final boolean dependent; + private final boolean dependent, isListOfDependencies; private final Dependency dependency; - public ModuleField(List modifiers, String type, String name, + private ModuleField(List modifiers, String type, String name, String attributeName, String nullableDefault, boolean isDependency, - Dependency dependency) { + Dependency dependency, boolean isListOfDependencies) { super(modifiers, type, name); this.dependent = isDependency; this.dependency = dependency; @@ -32,12 +32,13 @@ public class ModuleField extends Field { nullableDefault = "new " + ArrayList.class.getName() + generics + "()"; } this.nullableDefault = nullableDefault; + this.isListOfDependencies = isListOfDependencies; } public ModuleField(String type, String name, String attributeName, - String nullableDefault, boolean isDependency, Dependency dependency) { + String nullableDefault, boolean isDependency, Dependency dependency, boolean isListOfDependencies) { this(Collections. emptyList(), type, name, attributeName, - nullableDefault, isDependency, dependency); + nullableDefault, isDependency, dependency, isListOfDependencies); } public Dependency getDependency() { @@ -52,6 +53,10 @@ public class ModuleField extends Field { return dependent; } + public boolean isListOfDependencies() { + return isListOfDependencies; + } + public String getAttributeName() { return attributeName; } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl index b32e8bc130..7192ac661f 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl @@ -149,10 +149,19 @@ package ${packageName}; throw new IllegalArgumentException("Parameter 'other' is null"); } <#list moduleFields as field> - <#if field.dependent==true> + <#if field.dependent==true && field.listOfDependencies == false> if (${field.name}Dependency != other.${field.name}Dependency) { // reference to dependency must be same return false; } + <#elseif field.listOfDependencies> + if (${field.name}Dependency.equals(other.${field.name}Dependency) == false) { + return false; + } + for (int idx = 0; idx < ${field.name}Dependency.size(); idx++) { + if (${field.name}Dependency.get(idx) != other.${field.name}Dependency.get(idx)) { + return false; + } + } <#else> if (${field.name} == null) { if (other.${field.name} != null) { diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorFileNamesValidationTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorFileNamesValidationTest.java index b49b17e3a0..e33f1cddc4 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorFileNamesValidationTest.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorFileNamesValidationTest.java @@ -42,7 +42,7 @@ public class JMXGeneratorFileNamesValidationTest extends JMXGeneratorTest { } catch (RuntimeException e) { final Throwable cause = e.getCause(); assertNotNull(cause); - assertTrue(cause instanceof IllegalStateException); + assertTrue(cause.toString() + " is unexpected", cause instanceof IllegalStateException); assertThat(cause.getMessage(), containsString("Name conflict in generated files")); assertThat(cause.getMessage(), containsString("DtoA.java"));