001: /*
002: $Id: AntProjectPropertiesDelegate.java 2566 2005-07-18 22:11:48Z glaforge $
003:
004: Copyright 2005 (C) Guillaume Laforge. All Rights Reserved.
005:
006: Redistribution and use of this software and associated documentation
007: ("Software"), with or without modification, are permitted provided
008: that the following conditions are met:
009:
010: 1. Redistributions of source code must retain copyright
011: statements and notices. Redistributions must also contain a
012: copy of this document.
013:
014: 2. Redistributions in binary form must reproduce the
015: above copyright notice, this list of conditions and the
016: following disclaimer in the documentation and/or other
017: materials provided with the distribution.
018:
019: 3. The name "groovy" must not be used to endorse or promote
020: products derived from this Software without prior written
021: permission of The Codehaus. For written permission,
022: please contact info@codehaus.org.
023:
024: 4. Products derived from this Software may not be called "groovy"
025: nor may "groovy" appear in their names without prior written
026: permission of The Codehaus. "groovy" is a registered
027: trademark of The Codehaus.
028:
029: 5. Due credit should be given to The Codehaus -
030: http://groovy.codehaus.org/
031:
032: THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
033: ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
034: NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
035: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
036: THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
037: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
038: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
039: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
040: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
041: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
042: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
043: OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: */
046:
047: package org.codehaus.groovy.ant;
048:
049: import org.apache.tools.ant.Project;
050:
051: import java.util.Hashtable;
052: import java.util.Collection;
053: import java.util.Enumeration;
054: import java.util.Map;
055: import java.util.Set;
056: import java.util.Iterator;
057:
058: /**
059: * @author Guillaume Laforge
060: */
061: public class AntProjectPropertiesDelegate extends Hashtable {
062:
063: private Project project;
064:
065: public AntProjectPropertiesDelegate(Project project) {
066: super ();
067: this .project = project;
068: }
069:
070: public synchronized int hashCode() {
071: return project.getProperties().hashCode();
072: }
073:
074: public synchronized int size() {
075: return project.getProperties().size();
076: }
077:
078: /**
079: * @throws UnsupportedOperationException is always thrown when this method is invoked. The Project properties are immutable.
080: */
081: public synchronized void clear() {
082: throw new UnsupportedOperationException(
083: "Impossible to clear the project properties.");
084: }
085:
086: public synchronized boolean isEmpty() {
087: return project.getProperties().isEmpty();
088: }
089:
090: public synchronized Object clone() {
091: return project.getProperties().clone();
092: }
093:
094: public synchronized boolean contains(Object value) {
095: return project.getProperties().contains(value);
096: }
097:
098: public synchronized boolean containsKey(Object key) {
099: return project.getProperties().containsKey(key);
100: }
101:
102: public boolean containsValue(Object value) {
103: return project.getProperties().containsValue(value);
104: }
105:
106: public synchronized boolean equals(Object o) {
107: return project.getProperties().equals(o);
108: }
109:
110: public synchronized String toString() {
111: return project.getProperties().toString();
112: }
113:
114: public Collection values() {
115: return project.getProperties().values();
116: }
117:
118: public synchronized Enumeration elements() {
119: return project.getProperties().elements();
120: }
121:
122: public synchronized Enumeration keys() {
123: return project.getProperties().keys();
124: }
125:
126: public AntProjectPropertiesDelegate(Map t) {
127: super (t);
128: }
129:
130: public synchronized void putAll(Map t) {
131: Set keySet = t.keySet();
132: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
133: Object key = iterator.next();
134: Object value = t.get(key);
135: put(key, value);
136: }
137: }
138:
139: public Set entrySet() {
140: return project.getProperties().entrySet();
141: }
142:
143: public Set keySet() {
144: return project.getProperties().keySet();
145: }
146:
147: public synchronized Object get(Object key) {
148: return project.getProperties().get(key);
149: }
150:
151: /**
152: * @throws UnsupportedOperationException is always thrown when this method is invoked. The Project properties are immutable.
153: */
154: public synchronized Object remove(Object key) {
155: throw new UnsupportedOperationException(
156: "Impossible to remove a property from the project properties.");
157: }
158:
159: public synchronized Object put(Object key, Object value) {
160: Object oldValue = null;
161: if (containsKey(key)) {
162: oldValue = get(key);
163: }
164: project.setProperty(key.toString(), value.toString());
165: return oldValue;
166: }
167: }
|