KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > plugin > JPluginCapabilities


1 /*
2     =========================================================================
3     Package plugin - Implements the engine package.
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12     
13     This library is free software; you can redistribute it and/or
14     modify it under the terms of the GNU Lesser General Public
15     License as published by the Free Software Foundation; either
16     version 2.1 of the License, or (at your option) any later version.
17
18     This library is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21     Lesser General Public License for more details.
22
23     You should have received a copy of the GNU Lesser General Public
24     License along with this library; if not, write to the Free Software
25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JPluginCapabilities.java,v 1.8 2007/01/28 17:39:21 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.8 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.plugin;
40
41 import java.util.*;
42
43
44 public class JPluginCapabilities extends HashMap<String JavaDoc, String JavaDoc> {
45   
46   private static final String JavaDoc TRUE_VALUE = "true";
47   private static final String JavaDoc FALSE_VALUE = "false";
48   
49   public static final String JavaDoc CAPABILITY_FILE_TRANSFER = "file-transfer";
50   public static final String JavaDoc CAPABILITY_OFFLINE_MESSAGE = "offline-message";
51   public static final String JavaDoc CAPABILITY_FORMATTED_MESSAGE = "formatted-message";
52   public static final String JavaDoc CAPABILITY_EMOTICONS = "emoticons";
53   public static final String JavaDoc CAPABILITY_UPDATE_SCREEN_NAME = "update-screen-name";
54   public static final String JavaDoc CAPABILITY_REGISTER_NEW_USER = "register-new-user";
55   public static final String JavaDoc CAPABILITY_REMOVE_CONTACT_WHEN_DISCONNECTED = "remove-contact-when-disconnected";
56   public static final String JavaDoc CAPABILITY_PRIVACY_CONTROL_ENABLED = "privacy-control-enabled";
57   public static final String JavaDoc CAPABILITY_BLOCK_CONTACT = "block-user";
58   
59           
60   /**
61    * Constructor. Initialize all class data.
62    */

63   public JPluginCapabilities() {
64     
65     super();
66     clear();
67   }
68   
69   /**
70    * Add a boolean property to object.
71    * @param strKey The key to add;
72    * @param bValue The boolean value;
73    */

74   public void putBool( String JavaDoc strKey, boolean bValue ) {
75     
76     if( bValue )
77       put( strKey, TRUE_VALUE );
78     else
79       put( strKey, FALSE_VALUE );
80   }
81   
82   /**
83    * Return a boolean value for required property.
84    * @param strKey The key to retrieve the data;
85    */

86   public boolean getBool( String JavaDoc strKey ) {
87     
88     String JavaDoc strValue = get( strKey );
89     
90     if( strValue != null )
91       if( strValue.compareTo( TRUE_VALUE ) == 0 )
92         return true;
93
94     return false;
95   }
96   
97   /**
98    * Return a string value for required property.
99    * @param objKey The key to retrieve the data;
100    */

101   public String JavaDoc getString( String JavaDoc strKey ) {
102     
103     String JavaDoc strValue = get( strKey );
104     
105     if( strValue != null )
106       return strValue;
107     
108     return null;
109   }
110
111   /**
112    * Static method to provide default capabilities.
113    */

114   public static final JPluginCapabilities getDefault() {
115     
116     JPluginCapabilities capabilities = new JPluginCapabilities();
117     
118     // Default keys/values for capabilities object
119
capabilities.put( JPluginCapabilities.CAPABILITY_FILE_TRANSFER, JPluginCapabilities.FALSE_VALUE );
120     capabilities.put( JPluginCapabilities.CAPABILITY_OFFLINE_MESSAGE, JPluginCapabilities.FALSE_VALUE );
121     capabilities.put( JPluginCapabilities.CAPABILITY_EMOTICONS, JPluginCapabilities.FALSE_VALUE );
122     capabilities.put( JPluginCapabilities.CAPABILITY_FORMATTED_MESSAGE, JPluginCapabilities.FALSE_VALUE );
123     capabilities.put( JPluginCapabilities.CAPABILITY_UPDATE_SCREEN_NAME, JPluginCapabilities.FALSE_VALUE );
124     capabilities.put( JPluginCapabilities.CAPABILITY_REGISTER_NEW_USER, JPluginCapabilities.FALSE_VALUE );
125     capabilities.put( JPluginCapabilities.CAPABILITY_REMOVE_CONTACT_WHEN_DISCONNECTED, JPluginCapabilities.FALSE_VALUE );
126     capabilities.put( JPluginCapabilities.CAPABILITY_PRIVACY_CONTROL_ENABLED, JPluginCapabilities.FALSE_VALUE );
127     capabilities.put( JPluginCapabilities.CAPABILITY_BLOCK_CONTACT, JPluginCapabilities.FALSE_VALUE );
128
129     return capabilities;
130   }
131   
132   /**
133    * Override the default clone method to provide
134    * clone support to a JPluginCapabilities object.
135    */

136   public Object JavaDoc clone() {
137     
138     JPluginCapabilities capabilities = new JPluginCapabilities();
139     Iterator iterator = entrySet().iterator();
140    
141
142     capabilities.clear();
143
144     while( iterator.hasNext() ) {
145       Map.Entry<String JavaDoc, String JavaDoc> entry = ( Map.Entry<String JavaDoc, String JavaDoc> ) iterator.next();
146       capabilities.put( entry.getKey(), entry.getValue() );
147     }
148
149     return capabilities;
150   }
151 }
152
153 // JPluginCapabilities class
154
Popular Tags