| 1 |
/* |
| 2 |
* @(#) AbstractContext.java |
| 3 |
* |
| 4 |
* Copyright 2002 - 2003 JIDE Software. All rights reserved. |
| 5 |
*/ |
| 6 |
package com.jidesoft.converter; |
| 7 |
|
| 8 |
import java.io.Serializable; |
| 9 |
|
| 10 |
/** |
| 11 |
* <code>AbstractContext</code> is a generic context class. It has two fields: name and userObject. The name is just the |
| 12 |
* name of the context. You can use a meaningful string to name it. The userObject is customizable portion of Context. |
| 13 |
* You can set whatever you want as userObject. It's just a convention between whoever set it and whoever use it. For |
| 14 |
* example, in <code>ConverterContext</code>, we sometimes used it to pass in a <code>Format</code>. |
| 15 |
*/ |
| 16 |
abstract public class AbstractContext implements Serializable { |
| 17 |
private static final long serialVersionUID = -8924789128314897783L; |
| 18 |
|
| 19 |
private String _name; |
| 20 |
|
| 21 |
private Object _userObject; |
| 22 |
|
| 23 |
/** |
| 24 |
* Creates a named <code>AbstractContext</code>. |
| 25 |
* |
| 26 |
* @param name the name of the <code>AbstractContext</code>. |
| 27 |
*/ |
| 28 |
public AbstractContext(String name) { |
| 29 |
_name = name; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Creates an abstract context with a name and an object. |
| 34 |
* |
| 35 |
* @param name the name of the <code>AbstractContext</code>. |
| 36 |
* @param object the user object. It can be used any object to pass information along. |
| 37 |
*/ |
| 38 |
public AbstractContext(String name, Object object) { |
| 39 |
_name = name; |
| 40 |
_userObject = object; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Gets the name of the abstract context. |
| 45 |
* |
| 46 |
* @return the name of the abstract context |
| 47 |
*/ |
| 48 |
public String getName() { |
| 49 |
return _name; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Sets the name of the abstract context. |
| 54 |
* |
| 55 |
* @param name the name of the abstract context |
| 56 |
*/ |
| 57 |
public void setName(String name) { |
| 58 |
_name = name; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Gets the user object. |
| 63 |
* |
| 64 |
* @return the user object |
| 65 |
*/ |
| 66 |
public Object getUserObject() { |
| 67 |
return _userObject; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Sets the user object. |
| 72 |
* |
| 73 |
* @param userObject the user object. |
| 74 |
*/ |
| 75 |
public void setUserObject(Object userObject) { |
| 76 |
_userObject = userObject; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Override equals. Two abstract context equals as long as the name is the same. |
| 81 |
* |
| 82 |
* @param o object to compare. |
| 83 |
* @return if two objects equal. |
| 84 |
*/ |
| 85 |
@Override |
| 86 |
public boolean equals(Object o) { |
| 87 |
if (this == o) return true; |
| 88 |
if (!(o instanceof AbstractContext)) return false; |
| 89 |
|
| 90 |
final AbstractContext abstractContext = (AbstractContext) o; |
| 91 |
|
| 92 |
return !(_name != null ? !_name.equals(abstractContext._name) : abstractContext._name != null); |
| 93 |
} |
| 94 |
|
| 95 |
@Override |
| 96 |
public int hashCode() { |
| 97 |
return (_name != null ? _name.hashCode() : 0); |
| 98 |
} |
| 99 |
|
| 100 |
@Override |
| 101 |
public String toString() { |
| 102 |
return getName(); |
| 103 |
} |
| 104 |
} |