View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
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 tools.gsf.facade.runtag.vdm;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  import tools.gsf.facade.runtag.TagRunner;
21  
22  /**
23   * Sets a scalar attribute value without resetting it if it has already been set
24   * to the same value.
25   *
26   * @author Tony Field
27   * @since Sep 29, 2008
28   */
29  public class SetScalarWithoutReset implements TagRunner {
30  
31      private final String attribute;
32  
33      private final String value;
34  
35      public SetScalarWithoutReset(final String attribute, final String value) {
36          super();
37          this.attribute = attribute;
38          this.value = value;
39      }
40  
41      public String execute(final ICS ics) {
42          final String varname = "get_scalar_output_value" + ics.genID(true);
43          try {
44              ics.RemoveVar(varname);
45              GetScalar getScalar = new GetScalar(attribute, varname);
46              String getResult = getScalar.execute(ics);
47              String attrVal = ics.GetVar(varname);
48              if (attrVal != null && attrVal.equals(value) || attrVal == null && value == null) {
49                  // nothing to do. this saves a lot of processing
50                  return getResult;
51              }
52  
53              SetScalar setScalar = new SetScalar(attribute, value);
54              return setScalar.execute(ics);
55          } finally {
56              // cleaning up
57              ics.RemoveVar(varname);
58          }
59      }
60  
61      public String getValue() {
62          return value;
63      }
64  
65      public String getAttribute() {
66          return attribute;
67      }
68  }