1
2
3
4
5 package pt.digitalis.dif.dem.objects.parameters;
6
7 import pt.digitalis.dif.dem.Entity;
8 import pt.digitalis.dif.dem.interfaces.IStageInstance;
9 import pt.digitalis.dif.dem.managers.IParameterManager;
10 import pt.digitalis.dif.exception.objects.ParameterException;
11
12 import com.google.inject.Inject;
13
14
15
16
17
18
19
20 public class ParametersImpl implements IParameters {
21
22
23 private ParameterList applicationParameters = null;
24
25
26 @Inject
27 IParameterManager manager;
28
29
30 private ParameterList providerParameters = null;
31
32
33 private ParameterList serviceParameters = null;
34
35
36 private IStageInstance stage;
37
38
39 private ParameterList stageParameters = null;
40
41
42
43
44
45 public <T extends IParameter<?>> T addStageParameter(Class<T> parameterClass, String parameterID,
46 ParameterScope parameterScope, String defaultValue, String constraintDefinition) throws ParameterException
47 {
48 T parameter;
49
50 try
51 {
52 parameter = parameterClass.newInstance();
53 }
54 catch (InstantiationException e)
55 {
56 throw new ParameterException("Cannot create the parameter instance", e, null);
57 }
58 catch (IllegalAccessException e)
59 {
60 throw new ParameterException("Cannot create the parameter instance", e, null);
61 }
62
63 parameter.initialize(parameterID, Entity.STAGE, stage.getID(), false, false, false, parameterScope,
64 defaultValue, constraintDefinition, null, null);
65
66 this.getStageParameters().addParameter(parameter);
67
68 return parameter;
69 }
70
71
72
73
74 public ParameterList getAllAvailableParameters() throws ParameterException
75 {
76 ParameterList allParameters = new ParameterList();
77 allParameters.addParameters(getProviderParameters());
78 allParameters.addParameters(getApplicationParameters());
79 allParameters.addParameters(getServiceParameters());
80 allParameters.addParameters(getStageParameters());
81
82 return allParameters;
83 }
84
85
86
87
88 public ParameterList getApplicationParameters() throws ParameterException
89 {
90
91 if (this.applicationParameters == null)
92 {
93 ParameterList parameterList = this.manager.getParameters(this.stage.getService().getApplication());
94
95 try
96 {
97 this.applicationParameters = parameterList.cloneMe();
98 }
99 catch (CloneNotSupportedException e)
100 {
101 e.printStackTrace();
102 }
103 }
104 return this.applicationParameters;
105 }
106
107
108
109
110 public ParameterList getProviderParameters() throws ParameterException
111 {
112 if (this.providerParameters == null)
113 {
114 ParameterList parameterList = this.manager.getParameters(this.stage.getService().getApplication()
115 .getProvider());
116 try
117 {
118 this.providerParameters = parameterList.cloneMe();
119 }
120 catch (CloneNotSupportedException e)
121 {
122 e.printStackTrace();
123 }
124 }
125 return this.providerParameters;
126 }
127
128
129
130
131 public ParameterList getServiceParameters() throws ParameterException
132 {
133 if (this.serviceParameters == null)
134 {
135 ParameterList parameterList = this.manager.getParameters(this.stage.getService());
136 try
137 {
138 this.serviceParameters = parameterList.cloneMe();
139 }
140 catch (CloneNotSupportedException e)
141 {
142 e.printStackTrace();
143 }
144 }
145 return this.serviceParameters;
146 }
147
148
149
150
151 public ParameterList getStageParameters() throws ParameterException
152 {
153
154 if (this.stageParameters == null)
155 {
156 ParameterList parameterList = this.manager.getParameters(this.stage);
157 try
158 {
159 this.stageParameters = parameterList.cloneMe();
160 }
161 catch (CloneNotSupportedException e)
162 {
163 e.printStackTrace();
164 }
165 }
166
167 return this.stageParameters;
168 }
169
170
171
172
173 public void initialize(IStageInstance stage)
174 {
175 this.stage = stage;
176 }
177 }