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 dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);
61 protected void customValidation(){
65 // caches of resolved dependencies
66 <#list moduleFields as field>
67 <#if field.dependent==true>
68 private ${field.dependency.sie.exportedOsgiClassName} ${field.name}Dependency;
69 protected final ${field.dependency.sie.exportedOsgiClassName} get${field.attributeName}Dependency(){
70 return ${field.name}Dependency;
77 public final ${instanceType} getInstance(){
80 <#list moduleFields as field>
81 <#if field.dependent==true>
83 <#if field.dependency.mandatory==false>
84 if(${field.name}!=null) {
87 ${field.name}Dependency = dependencyResolver.resolveInstance(${field.dependency.sie.exportedOsgiClassName}.class, ${field.name}, ${field.name}JmxAttribute);
89 <#if field.dependency.mandatory==false>
95 if(oldInstance!=null && canReuseInstance(oldModule)) {
96 instance = reuseInstance(oldInstance);
98 if(oldInstance!=null) {
101 } catch(Exception e) {
102 logger.error("An error occurred while closing old instance " + oldInstance, e);
105 instance = createInstance();
112 public ${moduleNameType} getIdentifier() {
116 public boolean canReuseInstance(${typeDeclaration.name} oldModule){
117 // allow reusing of old instance if no parameters was changed
118 return isSame(oldModule);
121 public ${instanceType} reuseInstance(${instanceType} oldInstance){
122 // implement if instance reuse should be supported. Override canReuseInstance to change the criteria.
126 public abstract ${instanceType} createInstance();
128 public boolean isSame(${typeDeclaration.name} other) {
130 throw new IllegalArgumentException("Parameter 'other' is null");
132 <#list moduleFields as field>
133 <#if field.dependent==true>
134 if (${field.name}Dependency == null) {
135 if (other.${field.name}Dependency != null)
137 } else if (!${field.name}Dependency.equals(other.${field.name}Dependency)) {
141 if (${field.name} == null) {
142 if (other.${field.name} != null) {
146 <#if field.array == false>
147 (${field.name}.equals(other.${field.name}) == false)
149 (java.util.Arrays.equals(${field.name},other.${field.name}) == false)
161 public boolean equals(Object o) {
162 if (this == o) return true;
163 if (o == null || getClass() != o.getClass()) return false;
165 ${typeDeclaration.name} that = (${typeDeclaration.name}) o;
167 return identifier.equals(that.identifier);
171 public int hashCode() {
172 return identifier.hashCode();