2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.core
.execution
.tasks
;
19 import org
.argeo
.slc
.SlcException
;
20 import org
.argeo
.slc
.core
.test
.context
.SimpleContextAware
;
21 import org
.argeo
.slc
.test
.context
.ContextAware
;
24 * Overrides Values and Expected values of a target
25 * <code>SimpleContextAware</code> with the corresponding
26 * values and expected values of a source <code>ContextAware</code>
29 public class OverrideContextAware
implements Runnable
{
31 private ContextAware source
;
33 private SimpleContextAware target
;
36 * Whether an exception shall be thrown if a value
37 * or expected value of the source is not defined
40 private Boolean failIfUndefinedInSource
= true;
44 if(source
.getValues() != null)
45 for(String key
: source
.getValues().keySet()) {
46 if(failIfUndefinedInSource
&& !target
.getValues().containsKey(key
)) {
47 throw new SlcException("No entry in target values for key '" + key
+ "'");
49 target
.getValues().put(key
, source
.getValues().get(key
));
52 // override expected values
53 if(source
.getExpectedValues() != null)
54 for(String key
: source
.getExpectedValues().keySet()) {
55 if(failIfUndefinedInSource
&& !target
.getExpectedValues().containsKey(key
)) {
56 throw new SlcException("No entry in target expected values for key '" + key
+ "'");
58 target
.getExpectedValues().put(key
, source
.getExpectedValues().get(key
));
62 public void setSource(ContextAware source
) {
66 public void setTarget(SimpleContextAware target
) {
70 public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource
) {
71 this.failIfUndefinedInSource
= failIfUndefinedInSource
;