001: /*
002: * @(#) AbstractContext.java
003: *
004: * Copyright 2002 - 2003 JIDE Software. All rights reserved.
005: */
006: package com.jidesoft.converter;
007:
008: import java.io.Serializable;
009:
010: /**
011: * <code>AbstractContext</code> is a generic context class. It has two fields: name and userObject.
012: * The name is just the name of the context. You can use a meanful string to name it.
013: * The userObject is customizable portion of Context. You can set whatever you want as userObject.
014: * It's just a convention between whoever set it and whoever use it. For example, in <code>ConverterContext</code>,
015: * we sometimes used it to pass in a <code>Format</code>.
016: */
017: abstract public class AbstractContext implements Serializable {
018:
019: private String _name;
020:
021: private Object _userObject;
022:
023: /**
024: * Creates a named <code>AbstractContext</code>.
025: *
026: * @param name the name of the <code>AbstractContext</code>.
027: */
028: public AbstractContext(String name) {
029: _name = name;
030: }
031:
032: /**
033: * Creates an abstract contex with a name and an object.
034: *
035: * @param name the name of the <code>AbstractContext</code>.
036: * @param object the user object. It can be used any object to pass informaton along.
037: */
038: public AbstractContext(String name, Object object) {
039: _name = name;
040: _userObject = object;
041: }
042:
043: /**
044: * Gets the name of the abstract context.
045: *
046: * @return the name of the abstract context
047: */
048: public String getName() {
049: return _name;
050: }
051:
052: /**
053: * Sets the name of the abstract context.
054: *
055: * @param name the name of the abstract context
056: */
057: public void setName(String name) {
058: _name = name;
059: }
060:
061: /**
062: * Gets the user object.
063: *
064: * @return the user object
065: */
066: public Object getUserObject() {
067: return _userObject;
068: }
069:
070: /**
071: * Sets the user object.
072: *
073: * @param userObject the user object.
074: */
075: public void setUserObject(Object userObject) {
076: _userObject = userObject;
077: }
078:
079: /**
080: * Override equals. Two abstract context equals as long as the name is the same.
081: *
082: * @param o object to compare.
083: * @return if two objects euqnals.
084: */
085: @Override
086: public boolean equals(Object o) {
087: if (this == o)
088: return true;
089: if (!(o instanceof AbstractContext))
090: return false;
091:
092: final AbstractContext abstractContext = (AbstractContext) o;
093:
094: return !(_name != null ? !_name.equals(abstractContext._name)
095: : abstractContext._name != null);
096: }
097:
098: @Override
099: public int hashCode() {
100: return (_name != null ? _name.hashCode() : 0);
101: }
102:
103: @Override
104: public String toString() {
105: return getName();
106: }
107: }
|