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