src/core/net/sf/basedb/util/extensions/AboutBean.java

Code
Comments
Other
Rev Date Author Line
4163 28 Feb 08 nicklas 1 /**
4479 05 Sep 08 jari 2   $Id$
4163 28 Feb 08 nicklas 3
4163 28 Feb 08 nicklas 4   Copyright (C) Authors contributing to this file.
4163 28 Feb 08 nicklas 5
4163 28 Feb 08 nicklas 6   This file is part of BASE - BioArray Software Environment.
4163 28 Feb 08 nicklas 7   Available at http://base.thep.lu.se/
4163 28 Feb 08 nicklas 8
4163 28 Feb 08 nicklas 9   BASE is free software; you can redistribute it and/or
4163 28 Feb 08 nicklas 10   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 11   as published by the Free Software Foundation; either version 3
4163 28 Feb 08 nicklas 12   of the License, or (at your option) any later version.
4163 28 Feb 08 nicklas 13
4163 28 Feb 08 nicklas 14   BASE is distributed in the hope that it will be useful,
4163 28 Feb 08 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4163 28 Feb 08 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4163 28 Feb 08 nicklas 17   GNU General Public License for more details.
4163 28 Feb 08 nicklas 18
4163 28 Feb 08 nicklas 19   You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4163 28 Feb 08 nicklas 21 */
4163 28 Feb 08 nicklas 22 package net.sf.basedb.util.extensions;
4163 28 Feb 08 nicklas 23
6408 31 Jan 14 nicklas 24 import java.util.Collection;
6408 31 Jan 14 nicklas 25 import java.util.HashMap;
6408 31 Jan 14 nicklas 26 import java.util.Map;
6408 31 Jan 14 nicklas 27
4163 28 Feb 08 nicklas 28 import net.sf.basedb.core.plugin.About;
4163 28 Feb 08 nicklas 29
4163 28 Feb 08 nicklas 30 /**
4163 28 Feb 08 nicklas 31   An implementation of the {@link About} interface, which
4170 07 Mar 08 nicklas 32   complements all getter methods with setter methods.
4163 28 Feb 08 nicklas 33   
4163 28 Feb 08 nicklas 34   @author nicklas
4163 28 Feb 08 nicklas 35   @version 2.7
4198 28 Mar 08 nicklas 36   @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
4163 28 Feb 08 nicklas 37 */
4163 28 Feb 08 nicklas 38 public class AboutBean 
6408 31 Jan 14 nicklas 39   implements About, ExtendedAbout
4163 28 Feb 08 nicklas 40 {
4163 28 Feb 08 nicklas 41
4163 28 Feb 08 nicklas 42   private String name;
4163 28 Feb 08 nicklas 43   private String description;
4163 28 Feb 08 nicklas 44   private String version;
5607 15 Apr 11 nicklas 45   private String minBaseVersion;
5607 15 Apr 11 nicklas 46   private String maxBaseVersion;
4163 28 Feb 08 nicklas 47   private String copyright;
4163 28 Feb 08 nicklas 48   private String contact;
4163 28 Feb 08 nicklas 49   private String email;
4163 28 Feb 08 nicklas 50   private String url;
6408 31 Jan 14 nicklas 51   private Map<String, String> attributes;
4163 28 Feb 08 nicklas 52   
4163 28 Feb 08 nicklas 53   /**
4163 28 Feb 08 nicklas 54     Create a new empty about instance.
4163 28 Feb 08 nicklas 55   */
4163 28 Feb 08 nicklas 56   public AboutBean()
4163 28 Feb 08 nicklas 57   {}
4163 28 Feb 08 nicklas 58   
4163 28 Feb 08 nicklas 59   @Override
4163 28 Feb 08 nicklas 60   public String getContact()
4163 28 Feb 08 nicklas 61   {
4163 28 Feb 08 nicklas 62     return contact;
4163 28 Feb 08 nicklas 63   }
4163 28 Feb 08 nicklas 64   public void setContact(String contact)
4163 28 Feb 08 nicklas 65   {
4163 28 Feb 08 nicklas 66     this.contact = contact;
4163 28 Feb 08 nicklas 67   }
4163 28 Feb 08 nicklas 68   
4163 28 Feb 08 nicklas 69   @Override
4163 28 Feb 08 nicklas 70   public String getCopyright() 
4163 28 Feb 08 nicklas 71   {
4163 28 Feb 08 nicklas 72     return copyright;
4163 28 Feb 08 nicklas 73   }
4163 28 Feb 08 nicklas 74   public void setCopyright(String copyright)
4163 28 Feb 08 nicklas 75   {
4163 28 Feb 08 nicklas 76     this.copyright = copyright;
4163 28 Feb 08 nicklas 77   }
4163 28 Feb 08 nicklas 78   @Override
4163 28 Feb 08 nicklas 79   public String getDescription() 
4163 28 Feb 08 nicklas 80   {
4163 28 Feb 08 nicklas 81     return description;
4163 28 Feb 08 nicklas 82   }
4163 28 Feb 08 nicklas 83   public void setDescription(String description)
4163 28 Feb 08 nicklas 84   {
4163 28 Feb 08 nicklas 85     this.description = description;
4163 28 Feb 08 nicklas 86   }
4163 28 Feb 08 nicklas 87   
4163 28 Feb 08 nicklas 88   @Override
4163 28 Feb 08 nicklas 89   public String getEmail() 
4163 28 Feb 08 nicklas 90   {
4163 28 Feb 08 nicklas 91     return email;
4163 28 Feb 08 nicklas 92   }
4163 28 Feb 08 nicklas 93   public void setEmail(String email)
4163 28 Feb 08 nicklas 94   {
4163 28 Feb 08 nicklas 95     this.email = email;
4163 28 Feb 08 nicklas 96   }
4163 28 Feb 08 nicklas 97
4163 28 Feb 08 nicklas 98   @Override
4163 28 Feb 08 nicklas 99   public String getName() 
4163 28 Feb 08 nicklas 100   {
4163 28 Feb 08 nicklas 101     return name;
4163 28 Feb 08 nicklas 102   }
4163 28 Feb 08 nicklas 103   public void setName(String name)
4163 28 Feb 08 nicklas 104   {
4163 28 Feb 08 nicklas 105     this.name = name;
4163 28 Feb 08 nicklas 106   }
4163 28 Feb 08 nicklas 107
4163 28 Feb 08 nicklas 108   @Override
4163 28 Feb 08 nicklas 109   public String getUrl() 
4163 28 Feb 08 nicklas 110   {
4163 28 Feb 08 nicklas 111     return url;
4163 28 Feb 08 nicklas 112   }
4163 28 Feb 08 nicklas 113   public void setUrl(String url)
4163 28 Feb 08 nicklas 114   {
4163 28 Feb 08 nicklas 115     this.url = url;
4163 28 Feb 08 nicklas 116   }
4163 28 Feb 08 nicklas 117
4163 28 Feb 08 nicklas 118   @Override
4163 28 Feb 08 nicklas 119   public String getVersion() 
4163 28 Feb 08 nicklas 120   {
4163 28 Feb 08 nicklas 121     return version;
4163 28 Feb 08 nicklas 122   }
4163 28 Feb 08 nicklas 123   public void setVersion(String version)
4163 28 Feb 08 nicklas 124   {
4163 28 Feb 08 nicklas 125     this.version = version;
4163 28 Feb 08 nicklas 126   }
4163 28 Feb 08 nicklas 127
5607 15 Apr 11 nicklas 128   @Override
5607 15 Apr 11 nicklas 129   public String getMinBaseVersion() 
5607 15 Apr 11 nicklas 130   {
5607 15 Apr 11 nicklas 131     return minBaseVersion;
5607 15 Apr 11 nicklas 132   }
5607 15 Apr 11 nicklas 133   public void setMinBaseVersion(String version)
5607 15 Apr 11 nicklas 134   {
5607 15 Apr 11 nicklas 135     this.minBaseVersion = version;
5607 15 Apr 11 nicklas 136   }
5607 15 Apr 11 nicklas 137
5607 15 Apr 11 nicklas 138   @Override
5607 15 Apr 11 nicklas 139   public String getMaxBaseVersion() 
5607 15 Apr 11 nicklas 140   {
5607 15 Apr 11 nicklas 141     return maxBaseVersion;
5607 15 Apr 11 nicklas 142   }
5607 15 Apr 11 nicklas 143   public void setMaxBaseVersion(String version)
5607 15 Apr 11 nicklas 144   {
5607 15 Apr 11 nicklas 145     this.maxBaseVersion = version;
5607 15 Apr 11 nicklas 146   }
5607 15 Apr 11 nicklas 147
6408 31 Jan 14 nicklas 148
6408 31 Jan 14 nicklas 149   @Override
6408 31 Jan 14 nicklas 150   public String getAttribute(String name)
6408 31 Jan 14 nicklas 151   {
6408 31 Jan 14 nicklas 152     return attributes == null ? null : attributes.get(name);
6408 31 Jan 14 nicklas 153   }
5607 15 Apr 11 nicklas 154   
6408 31 Jan 14 nicklas 155   @Override
6408 31 Jan 14 nicklas 156   public Collection<String> getAttributeNames() 
6408 31 Jan 14 nicklas 157   {
6408 31 Jan 14 nicklas 158     return attributes == null ? null : attributes.keySet();
6408 31 Jan 14 nicklas 159   }
6408 31 Jan 14 nicklas 160
4198 28 Mar 08 nicklas 161   /**
6408 31 Jan 14 nicklas 162     Set an attribute for the given name.
6408 31 Jan 14 nicklas 163     @since 3.3
6408 31 Jan 14 nicklas 164   */
6408 31 Jan 14 nicklas 165   public void setAttribute(String name, String value)
6408 31 Jan 14 nicklas 166   {
6408 31 Jan 14 nicklas 167     if (attributes == null) attributes = new HashMap<String, String>();
6408 31 Jan 14 nicklas 168     attributes.put(name, value);
6408 31 Jan 14 nicklas 169   }
6408 31 Jan 14 nicklas 170
6408 31 Jan 14 nicklas 171   
6408 31 Jan 14 nicklas 172   /**
4198 28 Mar 08 nicklas 173     Copy information from antoher <code>About</code> object
4198 28 Mar 08 nicklas 174     to this one.
4198 28 Mar 08 nicklas 175     @param from The object to copy from
4198 28 Mar 08 nicklas 176     @param overwrite TRUE copy all values, FALSE
4198 28 Mar 08 nicklas 177       to only copy if the existing value is null
4198 28 Mar 08 nicklas 178   */
4198 28 Mar 08 nicklas 179   public void copy(About from, boolean overwrite)
4198 28 Mar 08 nicklas 180   {
4198 28 Mar 08 nicklas 181     if (from == null) return;
4198 28 Mar 08 nicklas 182     name = overwrite || name == null ? from.getName() : name;
4198 28 Mar 08 nicklas 183     description = overwrite || description == null ? from.getDescription() : description;
4198 28 Mar 08 nicklas 184     version = overwrite || version == null ? from.getVersion() : version;
5607 15 Apr 11 nicklas 185     minBaseVersion = overwrite || minBaseVersion == null ? from.getMinBaseVersion() : minBaseVersion;
5607 15 Apr 11 nicklas 186     maxBaseVersion = overwrite || maxBaseVersion == null ? from.getMaxBaseVersion() : maxBaseVersion;
4198 28 Mar 08 nicklas 187     copyright = overwrite || copyright == null ? from.getCopyright() : copyright;
4198 28 Mar 08 nicklas 188     contact = overwrite || contact == null ? from.getContact() : contact;
4198 28 Mar 08 nicklas 189     email = overwrite || email == null ? from.getEmail() : email;
4198 28 Mar 08 nicklas 190     url = overwrite || url == null ? from.getUrl() : url;
6408 31 Jan 14 nicklas 191     
6408 31 Jan 14 nicklas 192     if (from instanceof ExtendedAbout)
6408 31 Jan 14 nicklas 193     {
6408 31 Jan 14 nicklas 194       ExtendedAbout xtFrom = ((ExtendedAbout)from);
6408 31 Jan 14 nicklas 195       Collection<String> otherAttributes = xtFrom.getAttributeNames();
6408 31 Jan 14 nicklas 196       if (otherAttributes != null && otherAttributes.size() > 0)
6408 31 Jan 14 nicklas 197       {
6408 31 Jan 14 nicklas 198         if (attributes == null) attributes = new HashMap<String, String>();
6408 31 Jan 14 nicklas 199         for (String name : otherAttributes)
6408 31 Jan 14 nicklas 200         {
6408 31 Jan 14 nicklas 201           if (overwrite || !attributes.containsKey(name))
6408 31 Jan 14 nicklas 202           {
6408 31 Jan 14 nicklas 203             attributes.put(name, xtFrom.getAttribute(name));
6408 31 Jan 14 nicklas 204           }
6408 31 Jan 14 nicklas 205         }
6408 31 Jan 14 nicklas 206       }
6408 31 Jan 14 nicklas 207     }
6408 31 Jan 14 nicklas 208     
4198 28 Mar 08 nicklas 209   }
4198 28 Mar 08 nicklas 210
4163 28 Feb 08 nicklas 211 }