Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.configuration.serialization.ConfigurationSerialization Class Reference

Public Member Functions

ConfigurationSerializable deserialize (Map< String,?> args)
 

Static Public Member Functions

static ConfigurationSerializable deserializeObject (Map< String,?> args, Class<?extends ConfigurationSerializable > clazz)
 
static ConfigurationSerializable deserializeObject (Map< String,?> args)
 
static void registerClass (Class<?extends ConfigurationSerializable > clazz)
 
static void registerClass (Class<?extends ConfigurationSerializable > clazz, String alias)
 
static void unregisterClass (String alias)
 
static void unregisterClass (Class<?extends ConfigurationSerializable > clazz)
 
static Class<?extends ConfigurationSerializablegetClassByAlias (String alias)
 
static String getAlias (Class<?extends ConfigurationSerializable > clazz)
 

Static Public Attributes

static final String SERIALIZED_TYPE_KEY = "=="
 

Protected Member Functions

 ConfigurationSerialization (Class<?extends ConfigurationSerializable > clazz)
 
Method getMethod (String name, boolean isStatic)
 
Constructor<?extends ConfigurationSerializablegetConstructor ()
 
ConfigurationSerializable deserializeViaMethod (Method method, Map< String,?> args)
 
ConfigurationSerializable deserializeViaCtor (Constructor<?extends ConfigurationSerializable > ctor, Map< String,?> args)
 

Detailed Description

Utility class for storing and retrieving classes for Configuration.

Definition at line 24 of file ConfigurationSerialization.java.

Member Function Documentation

static ConfigurationSerializable org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject ( Map< String,?>  args,
Class<?extends ConfigurationSerializable clazz 
)
static

Attempts to deserialize the given arguments into a new instance of the given class.

The class must implement ConfigurationSerializable, including the extra methods as specified in the javadoc of ConfigurationSerializable.

If a new instance could not be made, an example being the class not fully implementing the interface, null will be returned.

Parameters
argsArguments for deserialization
clazzClass to deserialize into
Returns
New instance of the specified class

Definition at line 151 of file ConfigurationSerialization.java.

151  {
152  return new ConfigurationSerialization(clazz).deserialize(args);
153  }
static ConfigurationSerializable org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject ( Map< String,?>  args)
static

Attempts to deserialize the given arguments into a new instance of the given class.

The class must implement ConfigurationSerializable, including the extra methods as specified in the javadoc of ConfigurationSerializable.

If a new instance could not be made, an example being the class not fully implementing the interface, null will be returned.

Parameters
argsArguments for deserialization
Returns
New instance of the specified class

Definition at line 169 of file ConfigurationSerialization.java.

References org.bukkit.configuration.serialization.ConfigurationSerialization.getClassByAlias().

169  {
170  Class<? extends ConfigurationSerializable> clazz = null;
171 
172  if (args.containsKey(SERIALIZED_TYPE_KEY)) {
173  try {
174  String alias = (String) args.get(SERIALIZED_TYPE_KEY);
175 
176  if (alias == null) {
177  throw new IllegalArgumentException("Cannot have null alias");
178  }
179  clazz = getClassByAlias(alias);
180  if (clazz == null) {
181  throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')");
182  }
183  } catch (ClassCastException ex) {
184  ex.fillInStackTrace();
185  throw ex;
186  }
187  } else {
188  throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
189  }
190 
191  return new ConfigurationSerialization(clazz).deserialize(args);
192  }
static Class<?extends ConfigurationSerializable > getClassByAlias(String alias)
static String org.bukkit.configuration.serialization.ConfigurationSerialization.getAlias ( Class<?extends ConfigurationSerializable clazz)
static

Gets the correct alias for the given ConfigurationSerializable class

Parameters
clazzClass to get alias for
Returns
Alias to use for the class

Definition at line 260 of file ConfigurationSerialization.java.

References org.bukkit.configuration.serialization.DelegateDeserialization.value(), and org.bukkit.configuration.serialization.SerializableAs.value().

Referenced by org.bukkit.configuration.serialization.ConfigurationSerialization.registerClass().

260  {
261  DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
262 
263  if (delegate != null) {
264  if ((delegate.value() == null) || (delegate.value() == clazz)) {
265  delegate = null;
266  } else {
267  return getAlias(delegate.value());
268  }
269  }
270 
271  if (delegate == null) {
272  SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
273 
274  if ((alias != null) && (alias.value() != null)) {
275  return alias.value();
276  }
277  }
278 
279  return clazz.getName();
280  }
static String getAlias(Class<?extends ConfigurationSerializable > clazz)
static Class<? extends ConfigurationSerializable> org.bukkit.configuration.serialization.ConfigurationSerialization.getClassByAlias ( String  alias)
static

Attempts to get a registered ConfigurationSerializable class by its alias

Parameters
aliasAlias of the serializable
Returns
Registered class, or null if not found

Definition at line 249 of file ConfigurationSerialization.java.

Referenced by org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject().

249  {
250  return aliases.get(alias);
251  }
static void org.bukkit.configuration.serialization.ConfigurationSerialization.registerClass ( Class<?extends ConfigurationSerializable clazz)
static

Registers the given ConfigurationSerializable class by its alias

Parameters
clazzClass to register

Definition at line 200 of file ConfigurationSerialization.java.

References org.bukkit.configuration.serialization.ConfigurationSerialization.getAlias().

200  {
201  DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
202 
203  if (delegate == null) {
204  registerClass(clazz, getAlias(clazz));
205  registerClass(clazz, clazz.getName());
206  }
207  }
static String getAlias(Class<?extends ConfigurationSerializable > clazz)
static void registerClass(Class<?extends ConfigurationSerializable > clazz)
static void org.bukkit.configuration.serialization.ConfigurationSerialization.registerClass ( Class<?extends ConfigurationSerializable clazz,
String  alias 
)
static

Registers the given alias to the specified ConfigurationSerializable class

Parameters
clazzClass to register
aliasAlias to register as
See also
SerializableAs

Definition at line 217 of file ConfigurationSerialization.java.

217  {
218  aliases.put(alias, clazz);
219  }
static void org.bukkit.configuration.serialization.ConfigurationSerialization.unregisterClass ( String  alias)
static

Unregisters the specified alias to a ConfigurationSerializable

Parameters
aliasAlias to unregister

Definition at line 226 of file ConfigurationSerialization.java.

226  {
227  aliases.remove(alias);
228  }
static void org.bukkit.configuration.serialization.ConfigurationSerialization.unregisterClass ( Class<?extends ConfigurationSerializable clazz)
static

Unregisters any aliases for the specified ConfigurationSerializable class

Parameters
clazzClass to unregister

Definition at line 236 of file ConfigurationSerialization.java.

236  {
237  while (aliases.values().remove(clazz)) {
238  ;
239  }
240  }

The documentation for this class was generated from the following file: