View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.uddipub;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  import javax.xml.datatype.DatatypeFactory;
27  import javax.xml.datatype.Duration;
28  import org.apache.log4j.Level;
29  import org.miloss.fgsms.common.Utility;
30  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
31  import org.miloss.fgsms.services.interfaces.policyconfiguration.FederationPolicy;
32  
33  /**
34   * For UDDI Publisher, utility helper methods for publication
35   *
36   * @author AO
37   */
38  public class FederationPolicyExt {
39  
40      public FederationPolicyExt(FederationPolicy parent) {
41          ref = parent;
42      }
43  
44      public FederationPolicy getParentObject() {
45          return ref;
46      }
47      private FederationPolicy ref = null;
48  
49      public List<Duration> getPublishTimeRange() {
50          List<Duration> ret = new ArrayList<Duration>();
51          NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_TIME_RANGE);
52          if (target != null) {
53              String val = target.getValue();
54              if (target.isEncrypted()) {
55                  val = Utility.DE(val);
56              }
57              String[] durs = val.split(",");
58              try {
59                  DatatypeFactory fac = DatatypeFactory.newInstance();
60                  for (int i = 0; i < durs.length; i++) {
61                      long x = Long.parseLong(durs[i]);
62                      ret.add(fac.newDuration(x));
63                  }
64              } catch (Exception ex) {
65                  UddiPublisher.log.log(Level.ERROR, "unable to retrieve durations for federation publication", ex);
66              }
67  
68          }
69          return ret;
70      }
71  
72      public boolean isPublishAverageResponseTime() {
73          NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_AVG_RES_TIME);
74          if (target != null) {
75              String val = target.getValue();
76              if (target.isEncrypted()) {
77                  val = Utility.DE(val);
78              }
79              if (val.equalsIgnoreCase("true")) {
80                  return true;
81              }
82          }
83          return false;
84      }
85  
86      public boolean isPublishSuccessCount() {
87          NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_SUCCESS);
88          if (target != null) {
89              String val = target.getValue();
90              if (target.isEncrypted()) {
91                  val = Utility.DE(val);
92              }
93              if (val.equalsIgnoreCase("true")) {
94                  return true;
95              }
96          }
97          return false;
98      }
99  
100     public boolean isPublishFailureCount() {
101         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_FAULTS);
102         if (target != null) {
103             String val = target.getValue();
104             if (target.isEncrypted()) {
105                 val = Utility.DE(val);
106             }
107             if (val.equalsIgnoreCase("true")) {
108                 return true;
109             }
110         }
111         return false;
112     }
113 
114     public boolean isPublishUpTimePercent() {
115         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_UPTIME);
116         if (target != null) {
117             String val = target.getValue();
118             if (target.isEncrypted()) {
119                 val = Utility.DE(val);
120             }
121             if (val.equalsIgnoreCase("true")) {
122                 return true;
123             }
124         }
125         return false;
126     }
127 
128     public boolean isPublishMaximums() {
129         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_MAX);
130         if (target != null) {
131             String val = target.getValue();
132             if (target.isEncrypted()) {
133                 val = Utility.DE(val);
134             }
135             if (val.equalsIgnoreCase("true")) {
136                 return true;
137             }
138         }
139         return false;
140     }
141 
142     public boolean isPublishSLAFaults() {
143         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_SLA);
144         if (target != null) {
145             String val = target.getValue();
146             if (target.isEncrypted()) {
147                 val = Utility.DE(val);
148             }
149             if (val.equalsIgnoreCase("true")) {
150                 return true;
151             }
152         }
153         return false;
154     }
155 
156     public boolean isPublishLastKnownStatus() {
157         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_STATUS);
158         if (target != null) {
159             String val = target.getValue();
160             if (target.isEncrypted()) {
161                 val = Utility.DE(val);
162             }
163             if (val.equalsIgnoreCase("true")) {
164                 return true;
165             }
166         }
167         return false;
168     }
169 
170     public void setFederationTarget(String target) {
171         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.FederationTarget_UDDI_Publisher) == null) {
172             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.FederationTarget_UDDI_Publisher, target, false, false));
173         }
174     }
175 
176     public void setPublishAverageResponseTime(boolean b) {
177         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_AVG_RES_TIME) == null) {
178             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_AVG_RES_TIME, Boolean.toString(b), false, false));
179         }
180     }
181 
182     public void setPublishFailureCount(boolean b) {
183         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_FAULTS) == null) {
184             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_FAULTS, Boolean.toString(b), false, false));
185         }
186     }
187 
188     public void setPublishLastKnownStatus(boolean b) {
189         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_STATUS) == null) {
190             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_STATUS, Boolean.toString(b), false, false));
191         }
192     }
193 
194     public void setPublishMaximums(boolean b) {
195         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_MAX) == null) {
196             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_MAX, Boolean.toString(b), false, false));
197         }
198     }
199 
200     public void setPublishSuccessCount(boolean b) {
201         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_SUCCESS) == null) {
202             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_SUCCESS, Boolean.toString(b), false, false));
203         }
204     }
205 
206     public void setPublishTimeSinceLastStatusChange(boolean b) {
207         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_UPTIME) == null) {
208             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_UPTIME, Boolean.toString(b), false, false));
209         }
210     }
211 
212     public void setPublishUpTimePercent(boolean b) {
213         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_UPTIME) == null) {
214             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_UPTIME, Boolean.toString(b), false, false));
215         }
216     }
217 
218     public void setPublishSLAFaults(boolean b) {
219         if (Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_SLA) == null) {
220             ref.getParameterNameValue().add(Utility.newNameValuePair(UddiPublisher.OPTION_PUBLISH_SLA, Boolean.toString(b), false, false));
221         }
222     }
223 
224     public String getBindingKey() {
225         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_BINDING_KEY);
226         if (target != null) {
227             String val = target.getValue();
228             if (target.isEncrypted()) {
229                 val = Utility.DE(val);
230             }
231 
232             return val;
233         }
234         return null;
235     }
236 
237     boolean isPublishTimeSinceLastStatusChange() {
238         NameValuePair target = Utility.getNameValuePairByName(ref.getParameterNameValue(), UddiPublisher.OPTION_PUBLISH_UPTIME);
239         if (target != null) {
240             String val = target.getValue();
241             if (target.isEncrypted()) {
242                 val = Utility.DE(val);
243             }
244             if (val.equalsIgnoreCase("true")) {
245                 return true;
246             }
247         }
248         return false;
249     }
250 
251 
252     
253 }