incubator-oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r1000710 [35/44] - in /incubator/oodt/site/components/maven: apidocs/org/apache/oodt/grid/ apidocs/org/apache/oodt/grid/class-use/ apidocs/org/apache/oodt/profile/handlers/cas/ apidocs/org/apache/oodt/profile/handlers/cas/class-use/ apidocs...
Date Fri, 24 Sep 2010 05:09:57 GMT
Added: incubator/oodt/site/components/maven/xref/org/apache/oodt/grid/ConfigServlet.html
URL: http://svn.apache.org/viewvc/incubator/oodt/site/components/maven/xref/org/apache/oodt/grid/ConfigServlet.html?rev=1000710&view=auto
==============================================================================
--- incubator/oodt/site/components/maven/xref/org/apache/oodt/grid/ConfigServlet.html (added)
+++ incubator/oodt/site/components/maven/xref/org/apache/oodt/grid/ConfigServlet.html Fri
Sep 24 05:09:48 2010
@@ -0,0 +1,310 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en" xml:lang="en"><head><meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" /><title>ConfigServlet xref</title><link type="text/css"
rel="stylesheet" href="../../../../stylesheet.css" /></head><body>
+<div id="overview"><a href="../../../../../apidocs/org/apache/oodt/grid/ConfigServlet.html">View
Javadoc</a></div><pre>
+
+<a name="1" href="#1" id="1">1</a>   <em class="jxr_javadoccomment">/**</em>
+<a name="2" href="#2" id="2">2</a>   <em class="jxr_javadoccomment"> *
Licensed to the Apache Software Foundation (ASF) under one or more</em>
+<a name="3" href="#3" id="3">3</a>   <em class="jxr_javadoccomment"> *
contributor license agreements.  See the NOTICE file distributed with</em>
+<a name="4" href="#4" id="4">4</a>   <em class="jxr_javadoccomment"> *
this work for additional information regarding copyright ownership.</em>
+<a name="5" href="#5" id="5">5</a>   <em class="jxr_javadoccomment"> *
The ASF licenses this file to You under the Apache License, Version 2.0</em>
+<a name="6" href="#6" id="6">6</a>   <em class="jxr_javadoccomment"> *
(the "License"); you may not use this file except in compliance with</em>
+<a name="7" href="#7" id="7">7</a>   <em class="jxr_javadoccomment"> *
the License.  You may obtain a copy of the License at</em>
+<a name="8" href="#8" id="8">8</a>   <em class="jxr_javadoccomment"> *</em>
+<a name="9" href="#9" id="9">9</a>   <em class="jxr_javadoccomment"> *
    <a href="http://www.apache.org/licenses/LICENSE-2.0" target="alexandria_uri">http://www.apache.org/licenses/LICENSE-2.0</a></em>
+<a name="10" href="#10" id="10">10</a>  <em class="jxr_javadoccomment">
*</em>
+<a name="11" href="#11" id="11">11</a>  <em class="jxr_javadoccomment">
* Unless required by applicable law or agreed to in writing, software</em>
+<a name="12" href="#12" id="12">12</a>  <em class="jxr_javadoccomment">
* distributed under the License is distributed on an "AS IS" BASIS,</em>
+<a name="13" href="#13" id="13">13</a>  <em class="jxr_javadoccomment">
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</em>
+<a name="14" href="#14" id="14">14</a>  <em class="jxr_javadoccomment">
* See the License for the specific language governing permissions and</em>
+<a name="15" href="#15" id="15">15</a>  <em class="jxr_javadoccomment">
* limitations under the License.</em>
+<a name="16" href="#16" id="16">16</a>  <em class="jxr_javadoccomment">
*/</em>
+<a name="17" href="#17" id="17">17</a>  
+<a name="18" href="#18" id="18">18</a>  <strong class="jxr_keyword">package</strong>
org.apache.oodt.grid;
+<a name="19" href="#19" id="19">19</a>  
+<a name="20" href="#20" id="20">20</a>  <strong class="jxr_keyword">import</strong>
java.io.IOException;
+<a name="21" href="#21" id="21">21</a>  <strong class="jxr_keyword">import</strong>
java.net.MalformedURLException;
+<a name="22" href="#22" id="22">22</a>  <strong class="jxr_keyword">import</strong>
java.net.URL;
+<a name="23" href="#23" id="23">23</a>  <strong class="jxr_keyword">import</strong>
java.util.ArrayList;
+<a name="24" href="#24" id="24">24</a>  <strong class="jxr_keyword">import</strong>
java.util.Collections;
+<a name="25" href="#25" id="25">25</a>  <strong class="jxr_keyword">import</strong>
java.util.Iterator;
+<a name="26" href="#26" id="26">26</a>  <strong class="jxr_keyword">import</strong>
java.util.List;
+<a name="27" href="#27" id="27">27</a>  <strong class="jxr_keyword">import</strong>
java.util.Map;
+<a name="28" href="#28" id="28">28</a>  <strong class="jxr_keyword">import</strong>
java.util.Properties;
+<a name="29" href="#29" id="29">29</a>  <strong class="jxr_keyword">import</strong>
javax.servlet.ServletException;
+<a name="30" href="#30" id="30">30</a>  <strong class="jxr_keyword">import</strong>
javax.servlet.http.HttpServletRequest;
+<a name="31" href="#31" id="31">31</a>  <strong class="jxr_keyword">import</strong>
javax.servlet.http.HttpServletResponse;
+<a name="32" href="#32" id="32">32</a>  
+<a name="33" href="#33" id="33">33</a>  <em class="jxr_javadoccomment">/**</em>
+<a name="34" href="#34" id="34">34</a>  <em class="jxr_javadoccomment">
* Controller servlet for making changes to configuration.</em>
+<a name="35" href="#35" id="35">35</a>  <em class="jxr_javadoccomment">
*/</em>
+<a name="36" href="#36" id="36">36</a>  <strong class="jxr_keyword">public</strong>
<strong class="jxr_keyword">class</strong> <a href="../../../../org/apache/oodt/grid/ConfigServlet.html">ConfigServlet</a>
<strong class="jxr_keyword">extends</strong> <a href="../../../../org/apache/oodt/grid/GridServlet.html">GridServlet</a>
{
+<a name="37" href="#37" id="37">37</a>    <em class="jxr_javadoccomment">/**</em>
+<a name="38" href="#38" id="38">38</a>  <em class="jxr_javadoccomment">
  * Handle updates to a configuration by saving them and directing back to the</em>
+<a name="39" href="#39" id="39">39</a>  <em class="jxr_javadoccomment">
  * config page.</em>
+<a name="40" href="#40" id="40">40</a>  <em class="jxr_javadoccomment">
  * </em>
+<a name="41" href="#41" id="41">41</a>  <em class="jxr_javadoccomment">
  * @param req</em>
+<a name="42" href="#42" id="42">42</a>  <em class="jxr_javadoccomment">
  *          a &lt;code&gt;HttpServletRequest&lt;/code&gt; value.</em>
+<a name="43" href="#43" id="43">43</a>  <em class="jxr_javadoccomment">
  * @param res</em>
+<a name="44" href="#44" id="44">44</a>  <em class="jxr_javadoccomment">
  *          a &lt;code&gt;HttpServletResponse&lt;/code&gt; value.</em>
+<a name="45" href="#45" id="45">45</a>  <em class="jxr_javadoccomment">
  * @throws ServletException</em>
+<a name="46" href="#46" id="46">46</a>  <em class="jxr_javadoccomment">
  *           if an error occurs.</em>
+<a name="47" href="#47" id="47">47</a>  <em class="jxr_javadoccomment">
  * @throws IOException</em>
+<a name="48" href="#48" id="48">48</a>  <em class="jxr_javadoccomment">
  *           if an error occurs.</em>
+<a name="49" href="#49" id="49">49</a>  <em class="jxr_javadoccomment">
  */</em>
+<a name="50" href="#50" id="50">50</a>    <strong class="jxr_keyword">public</strong>
<strong class="jxr_keyword">void</strong> doPost(HttpServletRequest req, HttpServletResponse
res)
+<a name="51" href="#51" id="51">51</a>        <strong class="jxr_keyword">throws</strong>
ServletException, IOException {
+<a name="52" href="#52" id="52">52</a>      <a href="../../../../org/apache/oodt/grid/Configuration.html">Configuration</a>
config = getConfiguration(); <em class="jxr_comment">// Get the singleton</em>
+<a name="53" href="#53" id="53">53</a>                                      
          <em class="jxr_comment">// configuration</em>
+<a name="54" href="#54" id="54">54</a>      <strong class="jxr_keyword">if</strong>
(!approveAccess(config, req, res))
+<a name="55" href="#55" id="55">55</a>        <strong class="jxr_keyword">return</strong>;
<em class="jxr_comment">// Check if the user can access this page</em>
+<a name="56" href="#56" id="56">56</a>  
+<a name="57" href="#57" id="57">57</a>      <a href="../../../../org/apache/oodt/grid/ConfigBean.html">ConfigBean</a>
cb = getConfigBean(req); <em class="jxr_comment">// Get the bean</em>
+<a name="58" href="#58" id="58">58</a>      cb.setMessage(<span class="jxr_string">""</span>);
<em class="jxr_comment">// Clear out any message</em>
+<a name="59" href="#59" id="59">59</a>      <strong class="jxr_keyword">if</strong>
(!cb.isAuthentic())
+<a name="60" href="#60" id="60">60</a>        <strong class="jxr_keyword">throw</strong>
<strong class="jxr_keyword">new</strong> ServletException(<strong class="jxr_keyword">new</strong>
<a href="../../../../org/apache/oodt/grid/AuthenticationRequiredException.html">AuthenticationRequiredException</a>());
+<a name="61" href="#61" id="61">61</a>      <strong class="jxr_keyword">boolean</strong>
needSave = false; <em class="jxr_comment">// Assume no changes for now</em>
+<a name="62" href="#62" id="62">62</a>  
+<a name="63" href="#63" id="63">63</a>      String newPass = req.getParameter(<span
class="jxr_string">"password"</span>); <em class="jxr_comment">// See if she
wants to change</em>
+<a name="64" href="#64" id="64">64</a>                                      
              <em class="jxr_comment">// password</em>
+<a name="65" href="#65" id="65">65</a>      <strong class="jxr_keyword">if</strong>
(newPass != <strong class="jxr_keyword">null</strong> &amp;&amp; newPass.length()
&gt; 0) { <em class="jxr_comment">// Got a password, and it's</em>
+<a name="66" href="#66" id="66">66</a>                                      
              <em class="jxr_comment">// not empty?</em>
+<a name="67" href="#67" id="67">67</a>        config.setPassword(newPass.getBytes());
<em class="jxr_comment">// Yes, set its bytes</em>
+<a name="68" href="#68" id="68">68</a>        needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// We need to save</em>
+<a name="69" href="#69" id="69">69</a>      }
+<a name="70" href="#70" id="70">70</a>  
+<a name="71" href="#71" id="71">71</a>      <strong class="jxr_keyword">boolean</strong>
https = config.isHTTPSrequired(); <em class="jxr_comment">// Are we currently using
https?</em>
+<a name="72" href="#72" id="72">72</a>      String httpsParam = req.getParameter(<span
class="jxr_string">"https"</span>); <em class="jxr_comment">// Get her https
param</em>
+<a name="73" href="#73" id="73">73</a>      <strong class="jxr_keyword">boolean</strong>
newHttps = httpsParam != <strong class="jxr_keyword">null</strong> &amp;&amp;
<span class="jxr_string">"on"</span>.equals(httpsParam); <em class="jxr_comment">//
See if</em>
+<a name="74" href="#74" id="74">74</a>                                      
                                 <em class="jxr_comment">// she</em>
+<a name="75" href="#75" id="75">75</a>                                      
                                 <em class="jxr_comment">// wants</em>
+<a name="76" href="#76" id="76">76</a>                                      
                                 <em class="jxr_comment">// to use</em>
+<a name="77" href="#77" id="77">77</a>                                      
                                 <em class="jxr_comment">// https</em>
+<a name="78" href="#78" id="78">78</a>                                      
                                 <em class="jxr_comment">// or not</em>
+<a name="79" href="#79" id="79">79</a>      <strong class="jxr_keyword">if</strong>
(https != newHttps) { <em class="jxr_comment">// Different?</em>
+<a name="80" href="#80" id="80">80</a>        config.setHTTPSrequired(newHttps);
<em class="jxr_comment">// Yes, set the new state</em>
+<a name="81" href="#81" id="81">81</a>        needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// We need to save</em>
+<a name="82" href="#82" id="82">82</a>      }
+<a name="83" href="#83" id="83">83</a>  
+<a name="84" href="#84" id="84">84</a>      <strong class="jxr_keyword">boolean</strong>
local = config.isLocalhostRequired(); <em class="jxr_comment">// Are we requiring localhost?</em>
+<a name="85" href="#85" id="85">85</a>      String localhostParam = req.getParameter(<span
class="jxr_string">"localhost"</span>); <em class="jxr_comment">// Get her
localhost</em>
+<a name="86" href="#86" id="86">86</a>                                      
                      <em class="jxr_comment">// param</em>
+<a name="87" href="#87" id="87">87</a>      <strong class="jxr_keyword">boolean</strong>
newLocal = localhostParam != <strong class="jxr_keyword">null</strong> &amp;&amp;
<span class="jxr_string">"on"</span>.equals(localhostParam); <em class="jxr_comment">//
See</em>
+<a name="88" href="#88" id="88">88</a>                                      
                                         <em class="jxr_comment">// if</em>
+<a name="89" href="#89" id="89">89</a>                                      
                                         <em class="jxr_comment">// she</em>
+<a name="90" href="#90" id="90">90</a>                                      
                                         <em class="jxr_comment">// wants</em>
+<a name="91" href="#91" id="91">91</a>                                      
                                         <em class="jxr_comment">// to</em>
+<a name="92" href="#92" id="92">92</a>                                      
                                         <em class="jxr_comment">// require</em>
+<a name="93" href="#93" id="93">93</a>                                      
                                         <em class="jxr_comment">// localhost</em>
+<a name="94" href="#94" id="94">94</a>      <strong class="jxr_keyword">if</strong>
(local != newLocal) { <em class="jxr_comment">// Different?</em>
+<a name="95" href="#95" id="95">95</a>        config.setLocalhostRequired(newLocal);
<em class="jxr_comment">// Yes, set the new state</em>
+<a name="96" href="#96" id="96">96</a>        needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// We need to save</em>
+<a name="97" href="#97" id="97">97</a>      }
+<a name="98" href="#98" id="98">98</a>  
+<a name="99" href="#99" id="99">99</a>      String newKey = req.getParameter(<span
class="jxr_string">"newkey"</span>); <em class="jxr_comment">// See if she's
got a new</em>
+<a name="100" href="#100" id="100">100</a>                                  
              <em class="jxr_comment">// property</em>
+<a name="101" href="#101" id="101">101</a>     <strong class="jxr_keyword">if</strong>
(newKey != <strong class="jxr_keyword">null</strong> &amp;&amp; newKey.length()
&gt; 0) { <em class="jxr_comment">// And make sure it's nonempty</em>
+<a name="102" href="#102" id="102">102</a>       String newVal = req.getParameter(<span
class="jxr_string">"newval"</span>); <em class="jxr_comment">// Got one, get
its value</em>
+<a name="103" href="#103" id="103">103</a>       <strong class="jxr_keyword">if</strong>
(newVal == <strong class="jxr_keyword">null</strong>)
+<a name="104" href="#104" id="104">104</a>         newVal = <span class="jxr_string">""</span>;
<em class="jxr_comment">// Make sure it's at least an empty string</em>
+<a name="105" href="#105" id="105">105</a>       config.getProperties().setProperty(newKey,
newVal); <em class="jxr_comment">// Set the new</em>
+<a name="106" href="#106" id="106">106</a>                                  
                        <em class="jxr_comment">// property</em>
+<a name="107" href="#107" id="107">107</a>       needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// We need to save</em>
+<a name="108" href="#108" id="108">108</a>     }
+<a name="109" href="#109" id="109">109</a> 
+<a name="110" href="#110" id="110">110</a>     needSave |= updateProperties(config.getProperties(),
<em class="jxr_comment">// Make any updates to</em>
+<a name="111" href="#111" id="111">111</a>                                  
                       <em class="jxr_comment">// existing property</em>
+<a name="112" href="#112" id="112">112</a>         req.getParameterMap()); <em
class="jxr_comment">// values, and see note if we need to save</em>
+<a name="113" href="#113" id="113">113</a>     <strong class="jxr_keyword">try</strong>
{
+<a name="114" href="#114" id="114">114</a>       needSave |= updateServers(config,
req.getParameterMap(), 'd'); <em class="jxr_comment">// Same</em>
+<a name="115" href="#115" id="115">115</a>                                  
                                   <em class="jxr_comment">// goes for</em>
+<a name="116" href="#116" id="116">116</a>                                  
                                   <em class="jxr_comment">// product</em>
+<a name="117" href="#117" id="117">117</a>                                  
                                   <em class="jxr_comment">// servers</em>
+<a name="118" href="#118" id="118">118</a>       needSave |= updateServers(config,
req.getParameterMap(), 'm'); <em class="jxr_comment">// And</em>
+<a name="119" href="#119" id="119">119</a>                                  
                                   <em class="jxr_comment">// profile</em>
+<a name="120" href="#120" id="120">120</a>                                  
                                   <em class="jxr_comment">// servers</em>
+<a name="121" href="#121" id="121">121</a>       needSave |= updateCodeBases(config,
req.getParameterMap()); <em class="jxr_comment">// And for</em>
+<a name="122" href="#122" id="122">122</a>                                  
                                <em class="jxr_comment">// code bases</em>
+<a name="123" href="#123" id="123">123</a>     } <strong class="jxr_keyword">catch</strong>
(MalformedURLException ex) { <em class="jxr_comment">// Make sure code base URLs are
OK</em>
+<a name="124" href="#124" id="124">124</a>       cb.setMessage(<span class="jxr_string">"Code
bases must be valid URLs ("</span> <em class="jxr_comment">// Not OK?</em>
+<a name="125" href="#125" id="125">125</a>           + ex.getMessage() + <span
class="jxr_string">"); no changes made"</span>); <em class="jxr_comment">//
Let user know via a</em>
+<a name="126" href="#126" id="126">126</a>                                  
                   <em class="jxr_comment">// message</em>
+<a name="127" href="#127" id="127">127</a>       req.getRequestDispatcher(<span
class="jxr_string">"config.jsp"</span>).forward(req, res); <em class="jxr_comment">//
And make no</em>
+<a name="128" href="#128" id="128">128</a>                                  
                              <em class="jxr_comment">// changes until</em>
+<a name="129" href="#129" id="129">129</a>                                  
                              <em class="jxr_comment">// she fixes it</em>
+<a name="130" href="#130" id="130">130</a>       <strong class="jxr_keyword">return</strong>;
+<a name="131" href="#131" id="131">131</a>     }
+<a name="132" href="#132" id="132">132</a> 
+<a name="133" href="#133" id="133">133</a>     <strong class="jxr_keyword">if</strong>
(needSave) { <em class="jxr_comment">// Do we need to save?</em>
+<a name="134" href="#134" id="134">134</a>       config.save(); <em class="jxr_comment">//
Then do it already!</em>
+<a name="135" href="#135" id="135">135</a>       cb.setMessage(<span class="jxr_string">"Changes
saved."</span>); <em class="jxr_comment">// And let the user know</em>
+<a name="136" href="#136" id="136">136</a>     } <strong class="jxr_keyword">else</strong>
{
+<a name="137" href="#137" id="137">137</a>       cb.setMessage(<span class="jxr_string">"No
changes made."</span>); <em class="jxr_comment">// Oh, no changes were made, let
user</em>
+<a name="138" href="#138" id="138">138</a>                                  
       <em class="jxr_comment">// know</em>
+<a name="139" href="#139" id="139">139</a>     }
+<a name="140" href="#140" id="140">140</a>     req.getRequestDispatcher(<span
class="jxr_string">"config.jsp"</span>).forward(req, res); <em class="jxr_comment">//
Back to the</em>
+<a name="141" href="#141" id="141">141</a>                                  
                            <em class="jxr_comment">// config page</em>
+<a name="142" href="#142" id="142">142</a>   }
+<a name="143" href="#143" id="143">143</a> 
+<a name="144" href="#144" id="144">144</a>   <em class="jxr_javadoccomment">/**</em>
+<a name="145" href="#145" id="145">145</a> <em class="jxr_javadoccomment">
  * Update changes to the code bases.</em>
+<a name="146" href="#146" id="146">146</a> <em class="jxr_javadoccomment">
  * </em>
+<a name="147" href="#147" id="147">147</a> <em class="jxr_javadoccomment">
  * @param config</em>
+<a name="148" href="#148" id="148">148</a> <em class="jxr_javadoccomment">
  *          a &lt;code&gt;Configuration&lt;/code&gt; value.</em>
+<a name="149" href="#149" id="149">149</a> <em class="jxr_javadoccomment">
  * @param params</em>
+<a name="150" href="#150" id="150">150</a> <em class="jxr_javadoccomment">
  *          a &lt;code&gt;Map&lt;/code&gt; value.</em>
+<a name="151" href="#151" id="151">151</a> <em class="jxr_javadoccomment">
  * @return True if changes need to be saved.</em>
+<a name="152" href="#152" id="152">152</a> <em class="jxr_javadoccomment">
  * @throws MalformedURLException</em>
+<a name="153" href="#153" id="153">153</a> <em class="jxr_javadoccomment">
  *           if an error occurs.</em>
+<a name="154" href="#154" id="154">154</a> <em class="jxr_javadoccomment">
  */</em>
+<a name="155" href="#155" id="155">155</a>   <strong class="jxr_keyword">private</strong>
<strong class="jxr_keyword">boolean</strong> updateCodeBases(<a href="../../../../org/apache/oodt/grid/Configuration.html">Configuration</a>
config, Map params)
+<a name="156" href="#156" id="156">156</a>       <strong class="jxr_keyword">throws</strong>
MalformedURLException {
+<a name="157" href="#157" id="157">157</a>     <strong class="jxr_keyword">boolean</strong>
needSave = false; <em class="jxr_comment">// Assume no change</em>
+<a name="158" href="#158" id="158">158</a>     List codeBases = config.getCodeBases();
<em class="jxr_comment">// Get the current code bases</em>
+<a name="159" href="#159" id="159">159</a> 
+<a name="160" href="#160" id="160">160</a>     List toRemove = <strong class="jxr_keyword">new</strong>
ArrayList(); <em class="jxr_comment">// Hold indexes of code bases to remove</em>
+<a name="161" href="#161" id="161">161</a>     <strong class="jxr_keyword">for</strong>
(Iterator i = params.entrySet().iterator(); i.hasNext();) { <em class="jxr_comment">//
For each</em>
+<a name="162" href="#162" id="162">162</a>                                  
                                  <em class="jxr_comment">// parameter</em>
+<a name="163" href="#163" id="163">163</a>       Map.Entry entry = (Map.Entry)
i.next(); <em class="jxr_comment">// Get its entry</em>
+<a name="164" href="#164" id="164">164</a>       String key = (String) entry.getKey();
<em class="jxr_comment">// And its name</em>
+<a name="165" href="#165" id="165">165</a>       String value = ((String[]) entry.getValue())[0];
<em class="jxr_comment">// And its zeroth value</em>
+<a name="166" href="#166" id="166">166</a>       <strong class="jxr_keyword">if</strong>
(key.startsWith(<span class="jxr_string">"delcb-"</span>) &amp;&amp; <span
class="jxr_string">"on"</span>.equals(value)) { <em class="jxr_comment">//
If it's checked</em>
+<a name="167" href="#167" id="167">167</a>         Integer index = <strong
class="jxr_keyword">new</strong> Integer(key.substring(6)); <em class="jxr_comment">//
Parse out the index</em>
+<a name="168" href="#168" id="168">168</a>         toRemove.add(index); <em
class="jxr_comment">// Add it to the list</em>
+<a name="169" href="#169" id="169">169</a>       }
+<a name="170" href="#170" id="170">170</a>     }
+<a name="171" href="#171" id="171">171</a>     <strong class="jxr_keyword">if</strong>
(!toRemove.isEmpty()) { <em class="jxr_comment">// And if we have any indexes</em>
+<a name="172" href="#172" id="172">172</a>       Collections.sort(toRemove);
<em class="jxr_comment">// Sort 'em and put 'em in reverse ...</em>
+<a name="173" href="#173" id="173">173</a>       Collections.reverse(toRemove);
<em class="jxr_comment">// ... order so we can safely remove them</em>
+<a name="174" href="#174" id="174">174</a>       <strong class="jxr_keyword">for</strong>
(Iterator i = toRemove.iterator(); i.hasNext();) { <em class="jxr_comment">// For each
index</em>
+<a name="175" href="#175" id="175">175</a>                                  
                           <em class="jxr_comment">// to remove</em>
+<a name="176" href="#176" id="176">176</a>         <strong class="jxr_keyword">int</strong>
index = ((Integer) i.next()).intValue(); <em class="jxr_comment">// Get the index value</em>
+<a name="177" href="#177" id="177">177</a>         codeBases.remove(index); <em
class="jxr_comment">// And buh-bye.</em>
+<a name="178" href="#178" id="178">178</a>       }
+<a name="179" href="#179" id="179">179</a>       needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// Definitely need to save changes now</em>
+<a name="180" href="#180" id="180">180</a>     }
+<a name="181" href="#181" id="181">181</a> 
+<a name="182" href="#182" id="182">182</a>     String[] newCBs = (String[]) params.get(<span
class="jxr_string">"newcb"</span>); <em class="jxr_comment">// Was there a
new code</em>
+<a name="183" href="#183" id="183">183</a>                                  
                    <em class="jxr_comment">// base specified?</em>
+<a name="184" href="#184" id="184">184</a>     <strong class="jxr_keyword">if</strong>
(newCBs != <strong class="jxr_keyword">null</strong> &amp;&amp; newCBs.length
== 1) { <em class="jxr_comment">// And was there exactly one</em>
+<a name="185" href="#185" id="185">185</a>                                  
              <em class="jxr_comment">// value?</em>
+<a name="186" href="#186" id="186">186</a>       String newCB = newCBs[0]; <em
class="jxr_comment">// Get that exactly one value</em>
+<a name="187" href="#187" id="187">187</a>       <strong class="jxr_keyword">if</strong>
(newCB != <strong class="jxr_keyword">null</strong> &amp;&amp; newCB.length()
&gt; 0) { <em class="jxr_comment">// Is it nonnull and nonempty?</em>
+<a name="188" href="#188" id="188">188</a>         URL newURL = <strong class="jxr_keyword">new</strong>
URL(newCB); <em class="jxr_comment">// Treat is as an URL</em>
+<a name="189" href="#189" id="189">189</a>         codeBases.add(newURL); <em
class="jxr_comment">// Add it to the list</em>
+<a name="190" href="#190" id="190">190</a>         needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// Ad we gotta save</em>
+<a name="191" href="#191" id="191">191</a>       }
+<a name="192" href="#192" id="192">192</a>     }
+<a name="193" href="#193" id="193">193</a>     <strong class="jxr_keyword">return</strong>
needSave;
+<a name="194" href="#194" id="194">194</a>   }
+<a name="195" href="#195" id="195">195</a> 
+<a name="196" href="#196" id="196">196</a>   <em class="jxr_javadoccomment">/**</em>
+<a name="197" href="#197" id="197">197</a> <em class="jxr_javadoccomment">
  * Update the list of product/profile servers based on request parameters.</em>
+<a name="198" href="#198" id="198">198</a> <em class="jxr_javadoccomment">
  * </em>
+<a name="199" href="#199" id="199">199</a> <em class="jxr_javadoccomment">
  * @param config</em>
+<a name="200" href="#200" id="200">200</a> <em class="jxr_javadoccomment">
  *          System configuration</em>
+<a name="201" href="#201" id="201">201</a> <em class="jxr_javadoccomment">
  * @param params</em>
+<a name="202" href="#202" id="202">202</a> <em class="jxr_javadoccomment">
  *          Request parameters.</em>
+<a name="203" href="#203" id="203">203</a> <em class="jxr_javadoccomment">
  * @param type</em>
+<a name="204" href="#204" id="204">204</a> <em class="jxr_javadoccomment">
  *          &lt;code&gt;d&lt;/code&gt; (data) if product servers, &lt;code&gt;m&lt;/code&gt;</em>
+<a name="205" href="#205" id="205">205</a> <em class="jxr_javadoccomment">
  *          (metadata) if profile servers</em>
+<a name="206" href="#206" id="206">206</a> <em class="jxr_javadoccomment">
  * @return True if any changes were made, false if no changes were made</em>
+<a name="207" href="#207" id="207">207</a> <em class="jxr_javadoccomment">
  */</em>
+<a name="208" href="#208" id="208">208</a>   <strong class="jxr_keyword">private</strong>
<strong class="jxr_keyword">boolean</strong> updateServers(<a href="../../../../org/apache/oodt/grid/Configuration.html">Configuration</a>
config, Map params, <strong class="jxr_keyword">char</strong> type) {
+<a name="209" href="#209" id="209">209</a>     List servers = type == 'd' ? config.getProductServers()
: config
+<a name="210" href="#210" id="210">210</a>         .getProfileServers();
+<a name="211" href="#211" id="211">211</a>     <strong class="jxr_keyword">boolean</strong>
needSave = false; <em class="jxr_comment">// Assume no changes for now</em>
+<a name="212" href="#212" id="212">212</a> 
+<a name="213" href="#213" id="213">213</a>     List toRemove = <strong class="jxr_keyword">new</strong>
ArrayList(); <em class="jxr_comment">// Start with empty list of indexes to</em>
+<a name="214" href="#214" id="214">214</a>                                  
   <em class="jxr_comment">// remove</em>
+<a name="215" href="#215" id="215">215</a>     <strong class="jxr_keyword">for</strong>
(Iterator i = params.entrySet().iterator(); i.hasNext();) { <em class="jxr_comment">//
Go</em>
+<a name="216" href="#216" id="216">216</a>                                  
                                  <em class="jxr_comment">// through</em>
+<a name="217" href="#217" id="217">217</a>                                  
                                  <em class="jxr_comment">// each</em>
+<a name="218" href="#218" id="218">218</a>                                  
                                  <em class="jxr_comment">// parameter</em>
+<a name="219" href="#219" id="219">219</a>       Map.Entry entry = (Map.Entry)
i.next(); <em class="jxr_comment">// Get its key/value</em>
+<a name="220" href="#220" id="220">220</a>       String name = (String) entry.getKey();
<em class="jxr_comment">// The key is a String</em>
+<a name="221" href="#221" id="221">221</a>       <strong class="jxr_keyword">if</strong>
(name.startsWith(type + <span class="jxr_string">"rm-"</span>)) { <em class="jxr_comment">//
Is it an "drm-" or "mrm-"?</em>
+<a name="222" href="#222" id="222">222</a>         Integer index = <strong
class="jxr_keyword">new</strong> Integer(name.substring(4)); <em class="jxr_comment">//
Yes, get it sindex</em>
+<a name="223" href="#223" id="223">223</a>         toRemove.add(index); <em
class="jxr_comment">// Add it to the list</em>
+<a name="224" href="#224" id="224">224</a>       }
+<a name="225" href="#225" id="225">225</a>     }
+<a name="226" href="#226" id="226">226</a> 
+<a name="227" href="#227" id="227">227</a>     <strong class="jxr_keyword">if</strong>
(!toRemove.isEmpty()) { <em class="jxr_comment">// Got any to remove?</em>
+<a name="228" href="#228" id="228">228</a>       Collections.sort(toRemove);
<em class="jxr_comment">// We need to go through them in reverse ord-</em>
+<a name="229" href="#229" id="229">229</a>       Collections.reverse(toRemove);
<em class="jxr_comment">// -er, so that removals don't shift</em>
+<a name="230" href="#230" id="230">230</a>                                  
   <em class="jxr_comment">// indexes</em>
+<a name="231" href="#231" id="231">231</a>       <strong class="jxr_keyword">for</strong>
(Iterator i = toRemove.iterator(); i.hasNext();) { <em class="jxr_comment">// For each
index</em>
+<a name="232" href="#232" id="232">232</a>         <strong class="jxr_keyword">int</strong>
index = ((Integer) i.next()).intValue(); <em class="jxr_comment">// Get its int value</em>
+<a name="233" href="#233" id="233">233</a>         servers.remove(index); <em
class="jxr_comment">// and buh-bye</em>
+<a name="234" href="#234" id="234">234</a>       }
+<a name="235" href="#235" id="235">235</a>       needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// Gotta save after all that, whew.</em>
+<a name="236" href="#236" id="236">236</a>     }
+<a name="237" href="#237" id="237">237</a> 
+<a name="238" href="#238" id="238">238</a>     <strong class="jxr_keyword">if</strong>
(params.containsKey(type + <span class="jxr_string">"-newcn"</span>)) { <em
class="jxr_comment">// Adding a new server?</em>
+<a name="239" href="#239" id="239">239</a>       String[] newClasses = (String[])
params.get(type + <span class="jxr_string">"-newcn"</span>); <em class="jxr_comment">//
And the</em>
+<a name="240" href="#240" id="240">240</a>                                  
                                  <em class="jxr_comment">// new class</em>
+<a name="241" href="#241" id="241">241</a>                                  
                                  <em class="jxr_comment">// name</em>
+<a name="242" href="#242" id="242">242</a>       <strong class="jxr_keyword">if</strong>
(newClasses != <strong class="jxr_keyword">null</strong> &amp;&amp; newClasses.length
== 1) { <em class="jxr_comment">// Are present and</em>
+<a name="243" href="#243" id="243">243</a>                                  
                        <em class="jxr_comment">// there's only one of</em>
+<a name="244" href="#244" id="244">244</a>                                  
                        <em class="jxr_comment">// each</em>
+<a name="245" href="#245" id="245">245</a>         String newClass = newClasses[0];
<em class="jxr_comment">// Get the new class</em>
+<a name="246" href="#246" id="246">246</a>         <strong class="jxr_keyword">if</strong>
(newClass != <strong class="jxr_keyword">null</strong> &amp;&amp; newClass.length()
&gt; 0) { <em class="jxr_comment">// And nonempty</em>
+<a name="247" href="#247" id="247">247</a>           <a href="../../../../org/apache/oodt/grid/Server.html">Server</a>
server;
+<a name="248" href="#248" id="248">248</a>           <strong class="jxr_keyword">if</strong>
(type == 'd') <em class="jxr_comment">// If it's data</em>
+<a name="249" href="#249" id="249">249</a>             server = <strong class="jxr_keyword">new</strong>
<a href="../../../../org/apache/oodt/grid/ProductServer.html">ProductServer</a>(config,
newClass); <em class="jxr_comment">// It's a product</em>
+<a name="250" href="#250" id="250">250</a>                                  
                        <em class="jxr_comment">// server</em>
+<a name="251" href="#251" id="251">251</a>           <strong class="jxr_keyword">else</strong>
+<a name="252" href="#252" id="252">252</a>             <em class="jxr_comment">//
otherwise it's metadata</em>
+<a name="253" href="#253" id="253">253</a>             server = <strong class="jxr_keyword">new</strong>
<a href="../../../../org/apache/oodt/grid/ProfileServer.html">ProfileServer</a>(config,
newClass); <em class="jxr_comment">// Which is a profile</em>
+<a name="254" href="#254" id="254">254</a>                                  
                        <em class="jxr_comment">// server</em>
+<a name="255" href="#255" id="255">255</a>           servers.add(server); <em
class="jxr_comment">// Add it to the set of servers</em>
+<a name="256" href="#256" id="256">256</a>           needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// And after all this, we need to save!</em>
+<a name="257" href="#257" id="257">257</a>         }
+<a name="258" href="#258" id="258">258</a>       }
+<a name="259" href="#259" id="259">259</a>     }
+<a name="260" href="#260" id="260">260</a> 
+<a name="261" href="#261" id="261">261</a>     <strong class="jxr_keyword">return</strong>
needSave;
+<a name="262" href="#262" id="262">262</a>   }
+<a name="263" href="#263" id="263">263</a> 
+<a name="264" href="#264" id="264">264</a>   <em class="jxr_javadoccomment">/**</em>
+<a name="265" href="#265" id="265">265</a> <em class="jxr_javadoccomment">
  * Update properties based on request parameters.</em>
+<a name="266" href="#266" id="266">266</a> <em class="jxr_javadoccomment">
  * </em>
+<a name="267" href="#267" id="267">267</a> <em class="jxr_javadoccomment">
  * @param props</em>
+<a name="268" href="#268" id="268">268</a> <em class="jxr_javadoccomment">
  *          &lt;code&gt;Properties&lt;/code&gt; to update</em>
+<a name="269" href="#269" id="269">269</a> <em class="jxr_javadoccomment">
  * @param params</em>
+<a name="270" href="#270" id="270">270</a> <em class="jxr_javadoccomment">
  *          Request parameters</em>
+<a name="271" href="#271" id="271">271</a> <em class="jxr_javadoccomment">
  * @return True if changes need to be saved, false otherwise</em>
+<a name="272" href="#272" id="272">272</a> <em class="jxr_javadoccomment">
  */</em>
+<a name="273" href="#273" id="273">273</a>   <strong class="jxr_keyword">private</strong>
<strong class="jxr_keyword">boolean</strong> updateProperties(Properties props,
Map params) {
+<a name="274" href="#274" id="274">274</a>     <strong class="jxr_keyword">boolean</strong>
needSave = false; <em class="jxr_comment">// Assume no save for now</em>
+<a name="275" href="#275" id="275">275</a>     <strong class="jxr_keyword">for</strong>
(Iterator i = params.entrySet().iterator(); i.hasNext();) { <em class="jxr_comment">//
Go</em>
+<a name="276" href="#276" id="276">276</a>                                  
                                  <em class="jxr_comment">// through</em>
+<a name="277" href="#277" id="277">277</a>                                  
                                  <em class="jxr_comment">// each</em>
+<a name="278" href="#278" id="278">278</a>                                  
                                  <em class="jxr_comment">// request</em>
+<a name="279" href="#279" id="279">279</a>                                  
                                  <em class="jxr_comment">// parameter</em>
+<a name="280" href="#280" id="280">280</a>       Map.Entry entry = (Map.Entry)
i.next(); <em class="jxr_comment">// Get the key/value</em>
+<a name="281" href="#281" id="281">281</a>       String name = (String) entry.getKey();
<em class="jxr_comment">// Key is always a string</em>
+<a name="282" href="#282" id="282">282</a>       String newValue = ((String[])
entry.getValue())[0]; <em class="jxr_comment">// Value is String[],</em>
+<a name="283" href="#283" id="283">283</a>                                  
                        <em class="jxr_comment">// get the zeroth</em>
+<a name="284" href="#284" id="284">284</a>       <strong class="jxr_keyword">if</strong>
(name.startsWith(<span class="jxr_string">"val-"</span>)) { <em class="jxr_comment">//
If the param is "val-"</em>
+<a name="285" href="#285" id="285">285</a>         String key = name.substring(4);
<em class="jxr_comment">// Then find the key</em>
+<a name="286" href="#286" id="286">286</a>         <strong class="jxr_keyword">if</strong>
(props.containsKey(key)) { <em class="jxr_comment">// If that key exists</em>
+<a name="287" href="#287" id="287">287</a>           String value = props.getProperty(key);
<em class="jxr_comment">// Find its value</em>
+<a name="288" href="#288" id="288">288</a>           <strong class="jxr_keyword">if</strong>
(value == <strong class="jxr_keyword">null</strong> || !value.equals(newValue))
{<em class="jxr_comment">// Are they different?</em>
+<a name="289" href="#289" id="289">289</a>             props.setProperty(key,
newValue); <em class="jxr_comment">// Yes, set the new value</em>
+<a name="290" href="#290" id="290">290</a>             needSave = <strong
class="jxr_keyword">true</strong>; <em class="jxr_comment">// And we need to
save</em>
+<a name="291" href="#291" id="291">291</a>           }
+<a name="292" href="#292" id="292">292</a>         }
+<a name="293" href="#293" id="293">293</a>       } <strong class="jxr_keyword">else</strong>
<strong class="jxr_keyword">if</strong> (name.startsWith(<span class="jxr_string">"del-"</span>))
{ <em class="jxr_comment">// If the param is "del-"</em>
+<a name="294" href="#294" id="294">294</a>         String key = name.substring(4);
<em class="jxr_comment">// Then find the key</em>
+<a name="295" href="#295" id="295">295</a>         <strong class="jxr_keyword">if</strong>
(props.containsKey(key)) { <em class="jxr_comment">// If that key exists</em>
+<a name="296" href="#296" id="296">296</a>           props.remove(key); <em
class="jxr_comment">// Then remove its mapping</em>
+<a name="297" href="#297" id="297">297</a>           needSave = <strong class="jxr_keyword">true</strong>;
<em class="jxr_comment">// And we need to save</em>
+<a name="298" href="#298" id="298">298</a>         }
+<a name="299" href="#299" id="299">299</a>       }
+<a name="300" href="#300" id="300">300</a>     }
+<a name="301" href="#301" id="301">301</a>     <strong class="jxr_keyword">return</strong>
needSave;
+<a name="302" href="#302" id="302">302</a>   }
+<a name="303" href="#303" id="303">303</a> }
+</pre>
+<hr /><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>
\ No newline at end of file



Mime
View raw message