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 an alias ONLY if it has not been set before. Avoids unnecessary DB
24 * thrash.
25 *
26 * @author Tony Field
27 * @since Sep 29, 2008
28 */
29 public class SetAliasWithoutReset implements TagRunner {
30
31 private final String key;
32
33 private final String value;
34
35 public SetAliasWithoutReset(final String key, final String value) {
36 super();
37 this.key = key;
38 this.value = value;
39 }
40
41 public String execute(final ICS ics) {
42 final String varname = "alias" + ics.genID(true);
43 try {
44 GetAlias getAlias = new GetAlias(key, varname);
45 String getResult = getAlias.execute(ics);
46 String alias = ics.GetVar(varname);
47 if (alias != null && alias.equals(value) || alias == null && value == null) {
48 // nothing to do. this saves a lot of processing
49 return getResult;
50 }
51
52 SetAlias setAlias = new SetAlias(key, value);
53 return setAlias.execute(ics);
54
55 } finally {
56 // cleaning up
57 ics.RemoveVar(varname);
58 }
59 }
60
61 public String getValue() {
62 return value;
63 }
64
65 public String getKey() {
66 return key;
67 }
68
69 }