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("Impossible to clear the project properties."); 083 } 084 085 public synchronized boolean isEmpty() { 086 return project.getProperties().isEmpty(); 087 } 088 089 public synchronized Object clone() { 090 return project.getProperties().clone(); 091 } 092 093 public synchronized boolean contains(Object value) { 094 return project.getProperties().contains(value); 095 } 096 097 public synchronized boolean containsKey(Object key) { 098 return project.getProperties().containsKey(key); 099 } 100 101 public boolean containsValue(Object value) { 102 return project.getProperties().containsValue(value); 103 } 104 105 public synchronized boolean equals(Object o) { 106 return project.getProperties().equals(o); 107 } 108 109 public synchronized String toString() { 110 return project.getProperties().toString(); 111 } 112 113 public Collection values() { 114 return project.getProperties().values(); 115 } 116 117 public synchronized Enumeration elements() { 118 return project.getProperties().elements(); 119 } 120 121 public synchronized Enumeration keys() { 122 return project.getProperties().keys(); 123 } 124 125 public AntProjectPropertiesDelegate(Map t) { 126 super(t); 127 } 128 129 public synchronized void putAll(Map t) { 130 Set keySet = t.keySet(); 131 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { 132 Object key = iterator.next(); 133 Object value = t.get(key); 134 put(key, value); 135 } 136 } 137 138 public Set entrySet() { 139 return project.getProperties().entrySet(); 140 } 141 142 public Set keySet() { 143 return project.getProperties().keySet(); 144 } 145 146 public synchronized Object get(Object key) { 147 return project.getProperties().get(key); 148 } 149 150 /** 151 * @throws UnsupportedOperationException is always thrown when this method is invoked. The Project properties are immutable. 152 */ 153 public synchronized Object remove(Object key) { 154 throw new UnsupportedOperationException("Impossible to remove a property from the project properties."); 155 } 156 157 public synchronized Object put(Object key, Object value) { 158 Object oldValue = null; 159 if (containsKey(key)) { 160 oldValue = get(key); 161 } 162 project.setProperty(key.toString(), value.toString()); 163 return oldValue; 164 } 165 }