All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.wsf.spi.deployment.AbstractExtensible Maven / Gradle / Ivy

There is a newer version: 5.0.0.Final
Show newest version
/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2013, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.wsf.spi.deployment;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * A general extendible artifact; please note the 'attachments' and 'properties' fields are not meant to be modified concurrently,
 * as they are initialied to plain HashMap instances. Extensions of this class should override the methods accessing those fields
 * and add synchronized keyword.  
 * Most of the time, though, there will only be a single thread writing/deleting stuff in this class at the same time, for example
 * because that only happens during deployment processing (which executes in the same thread for deployment processors / aspects
 * and only the last aspect installs a service for each endpoint that run very limited stuff in different threads).
 * Visibility is ensured by the fields being final.
 * 
 * @author [email protected]
 * @author [email protected]
 * @since 20-Apr-2007 
 */
public abstract class AbstractExtensible implements Extensible
{
   private final Map, Object> attachments;
   private final Map properties;
   
   public AbstractExtensible()
   {
      this.attachments  = new HashMap, Object>();
      this.properties = new HashMap();
   }
   
   public AbstractExtensible(int initialAttachmentsSize, int initialPropertiesSize)
   {
      this.attachments  = new HashMap, Object>(initialAttachmentsSize);
      this.properties = new HashMap(initialPropertiesSize);
   }
   
   public Collection getAttachments()
   {
      return attachments.values();
   }
   
   @SuppressWarnings("unchecked")
   public  T getAttachment(Class clazz)
   {
      return (T)attachments.get(clazz);
   }
   
   @SuppressWarnings("unchecked")
   public  T addAttachment(Class clazz, Object obj)
   {
      return (T)attachments.put(clazz, obj);
   }

   @SuppressWarnings("unchecked")
   public  T removeAttachment(Class key)
   {
      return (T)attachments.remove(key);
   }
   
   public Set getProperties()
   {
      return properties.keySet();
   }

   public Object getProperty(String key)
   {
      return properties.get(key);
   }

   public void removeProperty(String key)
   {
      properties.remove(key);
   }

   public void setProperty(String key, Object value)
   {
      properties.put(key, value);
   }

   public void setProperties(Map props)
   {
      properties.putAll(props);
   }

}