]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java
Execution attribute of type ref now supported (break data model)
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / OverrideContextAware.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.core.execution.tasks;
18
19 import org.argeo.slc.SlcException;
20 import org.argeo.slc.core.test.context.SimpleContextAware;
21 import org.argeo.slc.test.context.ContextAware;
22
23 /**
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>
27 *
28 */
29 public class OverrideContextAware implements Runnable {
30
31 private ContextAware source;
32
33 private SimpleContextAware target;
34
35 /**
36 * Whether an exception shall be thrown if a value
37 * or expected value of the source is not defined
38 * in the target
39 */
40 private Boolean failIfUndefinedInSource = true;
41
42 public void run() {
43 // override values
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 + "'");
48 }
49 target.getValues().put(key, source.getValues().get(key));
50 }
51
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 + "'");
57 }
58 target.getExpectedValues().put(key, source.getExpectedValues().get(key));
59 }
60 }
61
62 public void setSource(ContextAware source) {
63 this.source = source;
64 }
65
66 public void setTarget(SimpleContextAware target) {
67 this.target = target;
68 }
69
70 public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource) {
71 this.failIfUndefinedInSource = failIfUndefinedInSource;
72 }
73 }