View Javadoc

    1   //========================================================================
    2   //$Id: SystemProperty.java 3907 2008-10-28 00:39:40Z janb $
    3   //Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
    4   //------------------------------------------------------------------------
    5   //Licensed under the Apache License, Version 2.0 (the "License");
    6   //you may not use this file except in compliance with the License.
    7   //You may obtain a copy of the License at
    8   //http://www.apache.org/licenses/LICENSE-2.0
    9   //Unless required by applicable law or agreed to in writing, software
    10  //distributed under the License is distributed on an "AS IS" BASIS,
    11  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //See the License for the specific language governing permissions and
    13  //limitations under the License.
    14  //========================================================================
    15
    16  package org.mortbay.jetty.plugin.util;
    17
    18  /**
    19   * SystemProperty
    20   *
    21   * Provides the ability to set System properties
    22   * for the mojo execution. A value will only
    23   * be set if it is not set already. That is, if
    24   * it was set on the command line or by the system,
    25   * it won't be overridden by settings in the
    26   * plugin's configuration.
    27   *
    28   */
    29  public class SystemProperty
    30  {
    31
    32
    33      private String name;
    34      private String value;
    35      private boolean isSet;
    36
    37      /**
    38       * @return Returns the name.
    39       */
    40      public String getName()
    41      {
    42          return this.name;
    43      }
    44      /**
    45       * @param name The name to set.
    46       */
    47      public void setName(String name)
    48      {
    49          this.name = name;
    50      }
    51
    52      public String getKey()
    53      {
    54          return this.name;
    55      }
    56
    57      public void setKey (String name)
    58      {
    59          this.name = name;
    60      }
    61      /**
    62       * @return Returns the value.
    63       */
    64      public String getValue()
    65      {
    66          return this.value;
    67      }
    68      /**
    69       * @param value The value to set.
    70       */
    71      public void setValue(String value)
    72      {
    73          this.value = value;
    74      }
    75
    76
    77      public boolean isSet ()
    78      {
    79          return isSet;
    80      }
    81
    82      /** Set a System.property with this value
    83       * if it is not already set.
    84       */
    85      void setIfNotSetAlready()
    86      {
    87          if (System.getProperty(getName()) == null)
    88          {
    89              System.setProperty(getName(), (getValue()==null?"":getValue()));
    90              isSet=true;
    91          }
    92      }
    93
    94  }