📄 simpleentry.java
字号:
* @return a JposEntry.Prop object created with the <name, value, type> tripplet
* passed as arguments
* @param propName the property name
* @param propValue the property value
* @param propType the property type (valid for this value)
* @throws jpos.config.JposConfigException if any of the argument is null or the
* property value and type mismatch or this is not a valid property type
* @see jpos.config.JposEntryConst#PROP_TYPES
* @since 2.0.0
*/
public JposEntry.Prop createProp( String propName, Object propValue, Class propType ) throws JposConfigException
{
if( propName == null || propValue == null || propType == null )
throw new JposConfigException( "Cannot create JposEntry.Prop with null argument" );
if( JposEntryUtility.validatePropValue( propValue, propType ) == false )
throw new JposConfigException( "Cannot create JposEntry.Prop with invalid value or type" );
return new Prop( propName, propValue );
}
//--------------------------------------------------------------------------
// Public overidden methods
//
/**
* @return true if the two JposEntries have the same properties
* @since 1.3 (SF 2K meeting)
*/
public boolean equals( Object object )
{
if( object instanceof JposEntry )
return equals( (JposEntry)object );
return false;
}
/**
* @return 0 if two entries are the same -1 if this is less or 1 of more than other
* the comparison for > and < uses the logicalName of the entry to decide
* @param otherEntry the other JposEntry
*/
public int compareTo( Object other )
{
if( other == null || ( (other instanceof JposEntry ) == false ) )
throw new RuntimeException( "Cannot compare: " + other + " with JposEntry: " + this );
JposEntry otherEntry = (JposEntry)other;
if( equals( otherEntry ) ) return 0;
return getLogicalName().compareTo( otherEntry.getLogicalName() );
}
/**
* @return a String representation of this entry
* @since 1.3 (SF 2K meeting)
*/
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append( "<JposEntry logicalName=\"" + getPropertyValue( JposEntry.LOGICAL_NAME_PROP_NAME ) + "\">\n" );
sb.append( "\t<creation factoryClass=\"" + getPropertyValue( JposEntry.SI_FACTORY_CLASS_PROP_NAME ) + "\" serviceClass=\"" + getPropertyValue( JposEntry.SERVICE_CLASS_PROP_NAME ) + "\"/>\n" );
sb.append( "\t<vendor name=\"" + getPropertyValue( JposEntry.VENDOR_NAME_PROP_NAME ) + "\" url=" + getPropertyValue( JposEntry.VENDOR_URL_PROP_NAME ) + "\"/>\n" );
sb.append( "\t<jpos category=\"" + getPropertyValue( JposEntry.DEVICE_CATEGORY_PROP_NAME ) + "\" version=\"" + getPropertyValue( JposEntry.JPOS_VERSION_PROP_NAME ) + "\"/>\n" );
sb.append( "\t<product description=\"" + getPropertyValue( JposEntry.PRODUCT_DESCRIPTION_PROP_NAME ) + "\" name=\"" + getPropertyValue( JposEntry.PRODUCT_NAME_PROP_NAME ) + "\" url=\"" + getPropertyValue( JposEntry.PRODUCT_URL_PROP_NAME ) + "\"/>\n" );
sb.append( "\n" );
Enumeration otherPropNames = JposEntryUtility.getNonRequiredPropNames( this );
while( otherPropNames.hasMoreElements() )
{
String name = (String)otherPropNames.nextElement();
String value = getPropertyValue( name ).toString();
String typeClassName = JposEntryUtility.shortClassName( value.getClass() );
sb.append( "\t<prop name=\"" + name + "\" value=\"" + value +
"\" type=\"" + typeClassName +"\"/>\n" );
}
sb.append( "</JposEntry>\n" );
return sb.toString();
}
//--------------------------------------------------------------------------
// Package methods
//
/**
* Sets the JposRegPopulator that loads/saves this entry. If null the default
* populator is used
* @since 1.3 (Washington DC 2001 meeting)
*/
void setRegPopulator( JposRegPopulator populator ) { regPopulator = populator; }
//---------------------------------------------------------------------
// Class methods
//
/**
* Checks that the Object argument is not null and if it is throw a IllegalArgumentException
* @param object the Object argument
* @throws java.lang.IllegalArgumentException if the object is null
*/
protected static void checkNull( Object object ) throws IllegalArgumentException
{
if( object == null )
throw new IllegalArgumentException( "Invalid null argument passed for a JposEntry property value or name" );
}
//--------------------------------------------------------------------------
// Instance variables
//
private Hashtable properties = new Hashtable();
private transient JposRegPopulator regPopulator = null;
//-------------------------------------------------------------------------
// Inner classes
//
/**
* Inner class to represent a property of a JposEntry
* @author E. Michael Maximilien
* @since 1.3 (Washington DC 2001)
*/
public static class Prop implements JposEntry.Prop, Comparable
{
//---------------------------------------------------------------------
// Ctor(s)
//
/**
* Creates a JposEntry.Prop object
* @param name the name of this property
* @param value the value of this property
* @throws java.lang.IllegalArgumentException if any of the arguments are null
*/
public Prop( String name, Object value ) throws IllegalArgumentException
{
checkNull( name );
checkNull( value );
this.name = name;
this.value = value;
this.typeClass = value.getClass();
}
//---------------------------------------------------------------------
// Public methods
//
/** @return the name of this property */
public String getName() { return name; }
/** @return the value of this property (the value is returned as an Object) */
public Object getValue() { return value; }
/** @return the value of this property as a String */
public String getValueAsString() { return String.valueOf( value ); }
/**
* Returns the Class object that is the type of this property value
* possible values returned are the java.lang wrapper classes for the
* primitive types e.g. Integer, Byte, Boolean, ...
* @return the type of this property as a java.lang.Class object
*/
public Class getType() { return typeClass; }
/**
* Sets the name of this property
* @param s the String object
* @throws java.lang.IllegalArgumentException if the argument is null
*/
public void setName( String s ) throws IllegalArgumentException
{
checkNull( s );
name = s;
}
/**
* Sets the value of this property (String). Also sets its Type.
* <p><b>This is the default type of any property</b></p>
* @param objValue the object's value
* @throws java.lang.IllegalArgumentException if the value is null or
* that this is not a valid typed property value
*/
public void setValue( Object objValue ) throws IllegalArgumentException
{
checkNull( objValue );
if( JposEntryUtility.validatePropValue( objValue, objValue.getClass() ) == false )
throw new IllegalArgumentException( "Cannot set property named = " + getName() +
" with value = " + objValue +
" invalid value or type" );
setValue( objValue, objValue.getClass() );
}
/**
* @return true if the property is of the type specified by the Class
* object passed
* @param type the Class object
*/
public boolean isOfType( Class type )
{
if( type == null || typeClass == null ) return false;
return typeClass.equals( type );
}
/** @return a new copy of this JposEntry.Prop object */
public JposEntry.Prop copy() { return new SimpleEntry.Prop( getName(), getValue() ); }
//---------------------------------------------------------------------
// Public overridden
//
/**
* @return true if this and otherProp have same name and value
* @param otherProp the other JposEntry.Prop
*/
public boolean equals( Object otherProp )
{
if( otherProp == null ) return false;
if( !( otherProp instanceof JposEntry.Prop ) ) return false;
JposEntry.Prop prop = (JposEntry.Prop)otherProp;
return ( getName().equals( prop.getName() ) ) &&
( getValue().equals( prop.getValue() ) );
}
/**
* @return 0 if two entries are the same -1 if this is less or 1 of more than other
* the comparison for > and < uses the logicalName of the entry to decide
* @param otherEntry the other JposEntry
*/
public int compareTo( Object other )
{
if( other == null || ( (other instanceof JposEntry.Prop ) == false ) )
throw new RuntimeException( "Cannot compare: " + other + " with JposEntry.Prop: " + this );
JposEntry.Prop otherEntryProp = (JposEntry.Prop)other;
if( equals( otherEntryProp ) ) return 0;
return getName().compareTo( otherEntryProp.getName() );
}
/** @return a unique key for this object */
public int hashCode() { return getName().hashCode(); }
//---------------------------------------------------------------------
// Private methods
//
/**
* Sets the value of this property as an Object that must match the
* the type specified. Also sets its Type.
* @param object the Object value (must be one of wrapper for primitive types
* or java.lang.String)
* @param type the java.lang.Class object matching the object type
* @throws java.lang.IllegalArgumentException if the object value type does not
* match the Class type
*/
private void setValue( Object object, Class type ) throws IllegalArgumentException
{
checkNull( object );
checkNull( type );
if( !object.getClass().equals( type ) )
throw new IllegalArgumentException( "Value and value type not in agreement for property named = " + name );
value = object;
typeClass = type;
}
//---------------------------------------------------------------------
// Instance variables
//
private String name = "";
private Object value = null;
private Class typeClass = null;
}
//--------------------------------------------------------------------------
// Public constants
//
/**
* serialVersionUID constant to maintain serialization compatibility between releases
* @since 1.3 (SF 2K meeting)
*/
public static final long serialVersionUID = 6937048853319310114L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -