2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.slc
.core
.execution
.tasks
;
18 import org
.argeo
.slc
.SlcException
;
19 import org
.argeo
.slc
.core
.test
.context
.SimpleContextAware
;
20 import org
.argeo
.slc
.test
.context
.ContextAware
;
23 * Overrides Values and Expected values of a target
24 * <code>SimpleContextAware</code> with the corresponding
25 * values and expected values of a source <code>ContextAware</code>
28 public class OverrideContextAware
implements Runnable
{
30 private ContextAware source
;
32 private SimpleContextAware target
;
35 * Whether an exception shall be thrown if a value
36 * or expected value of the source is not defined
39 private Boolean failIfUndefinedInSource
= true;
43 if(source
.getValues() != null)
44 for(String key
: source
.getValues().keySet()) {
45 if(failIfUndefinedInSource
&& !target
.getValues().containsKey(key
)) {
46 throw new SlcException("No entry in target values for key '" + key
+ "'");
48 target
.getValues().put(key
, source
.getValues().get(key
));
51 // override expected values
52 if(source
.getExpectedValues() != null)
53 for(String key
: source
.getExpectedValues().keySet()) {
54 if(failIfUndefinedInSource
&& !target
.getExpectedValues().containsKey(key
)) {
55 throw new SlcException("No entry in target expected values for key '" + key
+ "'");
57 target
.getExpectedValues().put(key
, source
.getExpectedValues().get(key
));
61 public void setSource(ContextAware source
) {
65 public void setTarget(SimpleContextAware target
) {
69 public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource
) {
70 this.failIfUndefinedInSource
= failIfUndefinedInSource
;