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