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 COM.FutureTense.Util.ftErrors;
21  import COM.FutureTense.Util.ftStatusCode;
22  import tools.gsf.facade.runtag.AbstractTagRunner;
23  import tools.gsf.runtime.CSRuntimeException;
24  
25  /**
26   * {@code <VDM.SETSCALAR ATTRIBUTE="attribute" VALUE="value"/>}
27   *
28   * @author Tony Field
29   * @since Sep 29, 2008
30   */
31  public class SetScalar extends AbstractTagRunner {
32  
33      public SetScalar(String attribute, String value) {
34          this();
35          setAttribute(attribute);
36          setValue(value);
37      }
38  
39      public SetScalar() {
40          super("VDM.SETSCALAR");
41      }
42  
43      public void setAttribute(String attr) {
44          set("ATTRIBUTE", attr);
45      }
46  
47      public void setValue(String val) {
48          set("VALUE", val);
49      }
50  
51      public String execute(ICS ics) {
52          String s = super.execute(ics);
53  
54          // Update from Tony Field September 19, 2009
55          // for some oddball reason, setscalar can fail with a database error
56          // (unique constraint violation)
57          // and the tag does not report errno. However it does return a status
58          // code in a variable called
59          // cshttp. We can look into this variable to get the code, parse it, and
60          // extract errno from it.
61          // Wow this is nasty...
62  
63          String statusCode = ics.GetVar("cshttp");
64          ftStatusCode sc = new ftStatusCode();
65          if (sc.setFromData(statusCode)) {
66              int errno = sc.getErrorID();
67              switch (errno) {
68                  case ftErrors.success:
69                      return s;
70                  case ftErrors.dberror: {
71                      throw new CSRuntimeException(
72                              "SetScalar failed with a database error.  It was returned in a ftStatusCode.  StatusCode:"
73                                      + statusCode, -13704);
74                  }
75                  default: {
76                      throw new CSRuntimeException(
77                              "SetScalar failed with an unexpected error.  It was returned in a ftStatusCode.  StatusCode:"
78                                      + statusCode, -13704);
79                  }
80              }
81          }
82          return s;
83      }
84  }