Derek Hulley db95d287ee Merged V2.9 to HEAD
9241: Merged V2.2 to V2.9
      9119: Merged V2.1 to V2.2
         8671: Fix for AR-2221 - JavaScript scriptable Map objects recursively converted to Freemarker accessable maps
   9256: Merged V2.2 to V2.9 
      9100: Merged V2.1 to V2.2 
         8728 <Not required>: Latest AMP changes for AR-2212 
         8731: Faster content store cleaner 
         8738: Fix for AWC 1930 - support simple bind when building DNs that contain a comma 
         8835: Fix regression issue as discussed in ACT 2019 
         8861: Fix WCM-1158 
         8866: Fixed AR-2272: Module Management Tool distribution is broken 
         8872: Fixed distribution of benchmark executable jar after EHCache upgrade 
         8933: Fix for ACT-2469


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9260 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2008-05-23 21:41:53 +00:00

200 lines
5.2 KiB
Java

/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.service.namespace;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.util.ApplicationContextHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A Map that holds as it's key a QName stored in it's internal String representation.
* Calls to get and put automatically map the key to and from the QName representation.
*
* @author gavinc
*/
public class QNameMap<K,V> implements Map, Cloneable, Serializable
{
private static final long serialVersionUID = -6578946123712939601L;
protected static Log logger = LogFactory.getLog(QNameMap.class);
protected Map<String, Object> contents = new HashMap<String, Object>(16, 1.0f);
protected NamespacePrefixResolver resolver = null;
/**
* Constructor
*
* @param resolver Mandatory NamespacePrefixResolver helper
*/
public QNameMap(NamespacePrefixResolver resolver)
{
if (resolver == null)
{
throw new IllegalArgumentException("NamespacePrefixResolver is mandatory.");
}
this.resolver = resolver;
}
/**
* Constructor for Serialization mechanism
*
*/
protected QNameMap()
{
super();
}
/**
* @see java.util.Map#size()
*/
public final int size()
{
return this.contents.size();
}
/**
* @see java.util.Map#isEmpty()
*/
public boolean isEmpty()
{
return this.contents.isEmpty();
}
/**
* @see java.util.Map#containsKey(java.lang.Object)
*/
public boolean containsKey(Object key)
{
return (this.contents.containsKey(QName.resolveToQNameString(resolver, key.toString())));
}
/**
* @see java.util.Map#containsValue(java.lang.Object)
*/
public boolean containsValue(Object value)
{
return this.contents.containsValue(value);
}
/**
* @see java.util.Map#get(java.lang.Object)
*/
public Object get(Object key)
{
String qnameKey = QName.resolveToQNameString(resolver, key.toString());
Object obj = this.contents.get(qnameKey);
return obj;
}
/**
* @see java.util.Map#put(K, V)
*/
public Object put(Object key, Object value)
{
return this.contents.put(QName.resolveToQNameString(resolver, key.toString()), value);
}
/**
* @see java.util.Map#remove(java.lang.Object)
*/
public Object remove(Object key)
{
return this.contents.remove(QName.resolveToQNameString(resolver, key.toString()));
}
/**
* @see java.util.Map#putAll(java.util.Map)
*/
public void putAll(Map t)
{
for (Object key : t.keySet())
{
this.put(key, t.get(key));
}
}
/**
* @see java.util.Map#clear()
*/
public void clear()
{
this.contents.clear();
}
/**
* @see java.util.Map#keySet()
*/
public Set<String> keySet()
{
return this.contents.keySet();
}
/**
* @see java.util.Map#values()
*/
public Collection values()
{
return this.contents.values();
}
/**
* @see java.util.Map#entrySet()
*/
public Set entrySet()
{
return this.contents.entrySet();
}
/**
* Override Object.toString() to provide useful debug output
*/
public String toString()
{
return this.contents.toString();
}
/**
* Shallow copy the map by copying keys and values into a new QNameMap
*/
public Object clone()
{
QNameMap map = new QNameMap(resolver);
map.putAll(this);
return map;
}
}