View Javadoc

1   //========================================================================
2   //$Id: SystemProperty.java 661 2006-07-06 10:38:27Z 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  	/**
36  	 * @return Returns the name.
37  	 */
38  	public String getName()
39  	{
40  		return this.name;
41  	}
42  	/**
43  	 * @param name The name to set.
44  	 */
45  	public void setName(String name)
46  	{
47  		this.name = name;
48  	}
49      
50      public String getKey()
51      {
52          return this.name;
53      }
54      
55      public void setKey (String name)
56      {
57          this.name = name;
58      }
59  	/**
60  	 * @return Returns the value.
61  	 */
62  	public String getValue()
63  	{
64  		return this.value;
65  	}
66  	/**
67  	 * @param value The value to set.
68  	 */
69  	public void setValue(String value)
70  	{
71  		this.value = value;
72  	}
73  	
74  	/** Set a System.property with this value
75  	 * if it is not already set.
76  	 * @return
77  	 */
78  	public boolean setIfNotSetAlready()
79  	{
80      	if (System.getProperty(getName()) == null)
81      	{
82      		System.setProperty(getName(), (getValue()==null?"":getValue()));
83      		return true;
84      	}
85      	
86      	return false;
87  	}
88  	
89  }