1 <@headerD header=header/>
2 package ${packageName};
4 <@javadocD object=javadoc/>
5 <@annotationsD object=annotations/>
6 <@typeDeclarationD object=typeDeclaration/>
9 <@moduleFieldsD moduleFields=moduleFields/>
12 private static final ${loggerType} logger = ${loggerFactoryType}.getLogger(${typeDeclaration.name}.class);
14 private final ${typeDeclaration.name} oldModule;
15 private final ${instanceType} oldInstance;
16 private ${instanceType} instance;
17 private final ${dependencyResolverType} dependencyResolver;
18 private final ${moduleNameType} identifier;
20 private ${registratorType} rootRuntimeBeanRegistratorWrapper;
23 public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver) {
24 this.identifier = identifier;
25 this.dependencyResolver = dependencyResolver;
26 this.oldInstance = null;
27 this.oldModule = null;
30 public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver, ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
31 this.identifier = identifier;
32 this.dependencyResolver = dependencyResolver;
33 this.oldInstance = oldInstance;
34 this.oldModule = oldModule;
37 // getters and setters exported into MXBean
38 <@methodsD object=methods/>
41 public ${registratorType} getRootRuntimeBeanRegistratorWrapper(){
42 return rootRuntimeBeanRegistratorWrapper;
46 public void setRuntimeBeanRegistrator(${rootRuntimeRegistratorType} rootRuntimeRegistrator){
47 this.rootRuntimeBeanRegistratorWrapper = new ${registratorType}(rootRuntimeRegistrator);
52 public void validate(){
53 <#list moduleFields as field>
54 <#if field.dependent==true && field.dependency.mandatory==true>
55 <#if field.type?starts_with("java.util.List")>
56 for(javax.management.ObjectName dep : ${field.name}) {
57 dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, dep, ${field.name}JmxAttribute);
60 dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);
67 protected void customValidation(){
71 // caches of resolved dependencies
72 <#list moduleFields as field>
73 <#if field.dependent==true>
74 <#if field.type?starts_with("java.util.List")>
75 private java.util.List<${field.dependency.sie.exportedOsgiClassName}> ${field.name}Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
76 protected final java.util.List<${field.dependency.sie.exportedOsgiClassName}> get${field.attributeName}Dependency(){
77 return ${field.name}Dependency;
80 private ${field.dependency.sie.exportedOsgiClassName} ${field.name}Dependency;
81 protected final ${field.dependency.sie.exportedOsgiClassName} get${field.attributeName}Dependency(){
82 return ${field.name}Dependency;
90 public final ${instanceType} getInstance(){
93 <#list moduleFields as field>
94 <#if field.dependent==true>
95 <#if field.dependency.mandatory==false>
96 if(${field.name}!=null) {
99 <#if field.type?starts_with("java.util.List")>
100 ${field.name}Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
101 for(javax.management.ObjectName dep : ${field.name}) {
102 ${field.name}Dependency.add(dependencyResolver.resolveInstance(${field.dependency.sie.exportedOsgiClassName}.class, dep, ${field.name}JmxAttribute));
105 ${field.name}Dependency = dependencyResolver.resolveInstance(${field.dependency.sie.exportedOsgiClassName}.class, ${field.name}, ${field.name}JmxAttribute);
108 <#if field.dependency.mandatory==false>
114 if(oldInstance!=null && canReuseInstance(oldModule)) {
115 instance = reuseInstance(oldInstance);
117 if(oldInstance!=null) {
120 } catch(Exception e) {
121 logger.error("An error occurred while closing old instance " + oldInstance, e);
124 instance = createInstance();
131 public ${moduleNameType} getIdentifier() {
135 public boolean canReuseInstance(${typeDeclaration.name} oldModule){
136 // allow reusing of old instance if no parameters was changed
137 return isSame(oldModule);
140 public ${instanceType} reuseInstance(${instanceType} oldInstance){
141 // implement if instance reuse should be supported. Override canReuseInstance to change the criteria.
145 public abstract ${instanceType} createInstance();
147 public boolean isSame(${typeDeclaration.name} other) {
149 throw new IllegalArgumentException("Parameter 'other' is null");
151 <#list moduleFields as field>
152 <#if field.dependent==true>
153 if (${field.name}Dependency == null) {
154 if (other.${field.name}Dependency != null)
156 } else if (!${field.name}Dependency.equals(other.${field.name}Dependency)) {
160 if (${field.name} == null) {
161 if (other.${field.name} != null) {
165 <#if field.array == false>
166 (${field.name}.equals(other.${field.name}) == false)
168 (java.util.Arrays.equals(${field.name},other.${field.name}) == false)
180 public boolean equals(Object o) {
181 if (this == o) return true;
182 if (o == null || getClass() != o.getClass()) return false;
184 ${typeDeclaration.name} that = (${typeDeclaration.name}) o;
186 return identifier.equals(that.identifier);
190 public int hashCode() {
191 return identifier.hashCode();