| 1 | 0 | |
| 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 | 0 | public class ParametersImpl implements IParameters { |
| 21 | |
|
| 22 | |
|
| 23 | 0 | private ParameterList applicationParameters = null; |
| 24 | |
|
| 25 | |
|
| 26 | |
@Inject |
| 27 | |
IParameterManager manager; |
| 28 | |
|
| 29 | |
|
| 30 | 0 | private ParameterList providerParameters = null; |
| 31 | |
|
| 32 | |
|
| 33 | 0 | private ParameterList serviceParameters = null; |
| 34 | |
|
| 35 | |
|
| 36 | |
private IStageInstance stage; |
| 37 | |
|
| 38 | |
|
| 39 | 0 | 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 | 0 | parameter = parameterClass.newInstance(); |
| 53 | |
} |
| 54 | 0 | catch (InstantiationException e) |
| 55 | |
{ |
| 56 | 0 | throw new ParameterException("Cannot create the parameter instance", e, null); |
| 57 | |
} |
| 58 | 0 | catch (IllegalAccessException e) |
| 59 | |
{ |
| 60 | 0 | throw new ParameterException("Cannot create the parameter instance", e, null); |
| 61 | |
} |
| 62 | |
|
| 63 | 0 | parameter.initialize(parameterID, Entity.STAGE, stage.getID(), false, false, false, parameterScope, |
| 64 | 0 | defaultValue, constraintDefinition, null, null); |
| 65 | |
|
| 66 | 0 | this.getStageParameters().addParameter(parameter); |
| 67 | |
|
| 68 | 0 | return parameter; |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public ParameterList getAllAvailableParameters() throws ParameterException |
| 75 | |
{ |
| 76 | 0 | ParameterList allParameters = new ParameterList(); |
| 77 | 0 | allParameters.addParameters(getProviderParameters()); |
| 78 | 0 | allParameters.addParameters(getApplicationParameters()); |
| 79 | 0 | allParameters.addParameters(getServiceParameters()); |
| 80 | 0 | allParameters.addParameters(getStageParameters()); |
| 81 | |
|
| 82 | 0 | return allParameters; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public ParameterList getApplicationParameters() throws ParameterException |
| 89 | |
{ |
| 90 | |
|
| 91 | 0 | if (this.applicationParameters == null) |
| 92 | |
{ |
| 93 | 0 | ParameterList parameterList = this.manager.getParameters(this.stage.getService().getApplication()); |
| 94 | |
|
| 95 | |
try |
| 96 | |
{ |
| 97 | 0 | this.applicationParameters = parameterList.cloneMe(); |
| 98 | |
} |
| 99 | 0 | catch (CloneNotSupportedException e) |
| 100 | |
{ |
| 101 | 0 | e.printStackTrace(); |
| 102 | |
} |
| 103 | |
} |
| 104 | 0 | return this.applicationParameters; |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public ParameterList getProviderParameters() throws ParameterException |
| 111 | |
{ |
| 112 | 0 | if (this.providerParameters == null) |
| 113 | |
{ |
| 114 | 0 | ParameterList parameterList = this.manager.getParameters(this.stage.getService().getApplication() |
| 115 | 0 | .getProvider()); |
| 116 | |
try |
| 117 | |
{ |
| 118 | 0 | this.providerParameters = parameterList.cloneMe(); |
| 119 | |
} |
| 120 | 0 | catch (CloneNotSupportedException e) |
| 121 | |
{ |
| 122 | 0 | e.printStackTrace(); |
| 123 | |
} |
| 124 | |
} |
| 125 | 0 | return this.providerParameters; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
public ParameterList getServiceParameters() throws ParameterException |
| 132 | |
{ |
| 133 | 0 | if (this.serviceParameters == null) |
| 134 | |
{ |
| 135 | 0 | ParameterList parameterList = this.manager.getParameters(this.stage.getService()); |
| 136 | |
try |
| 137 | |
{ |
| 138 | 0 | this.serviceParameters = parameterList.cloneMe(); |
| 139 | |
} |
| 140 | 0 | catch (CloneNotSupportedException e) |
| 141 | |
{ |
| 142 | 0 | e.printStackTrace(); |
| 143 | |
} |
| 144 | |
} |
| 145 | 0 | return this.serviceParameters; |
| 146 | |
} |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
public ParameterList getStageParameters() throws ParameterException |
| 152 | |
{ |
| 153 | |
|
| 154 | 0 | if (this.stageParameters == null) |
| 155 | |
{ |
| 156 | 0 | ParameterList parameterList = this.manager.getParameters(this.stage); |
| 157 | |
try |
| 158 | |
{ |
| 159 | 0 | this.stageParameters = parameterList.cloneMe(); |
| 160 | |
} |
| 161 | 0 | catch (CloneNotSupportedException e) |
| 162 | |
{ |
| 163 | 0 | e.printStackTrace(); |
| 164 | |
} |
| 165 | |
} |
| 166 | |
|
| 167 | 0 | return this.stageParameters; |
| 168 | |
} |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public void initialize(IStageInstance stage) |
| 174 | |
{ |
| 175 | 0 | this.stage = stage; |
| 176 | 0 | } |
| 177 | |
} |