⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleentry.java

📁 JavaPOS的最新版本!这是源代码!零售业的请看!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package jpos.config.simple;

///////////////////////////////////////////////////////////////////////////////
//
// This software is provided "AS IS".  The JavaPOS working group (including
// each of the Corporate members, contributors and individuals)  MAKES NO
// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for
// any damages suffered as a result of using, modifying or distributing this
// software or its derivatives. Permission to use, copy, modify, and distribute
// the software and its documentation for any purpose is hereby granted. 
//
// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which 
// is an OSS Apache-like license.  The complete license is located at:
//    http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
//
///////////////////////////////////////////////////////////////////////////////

import jpos.config.JposEntry;

import java.util.*;
import java.io.Serializable;

import jpos.config.*;
import jpos.util.JposEntryUtility;

/**
 * This is a simple implementation of the JposEntry interface using a Hashtable 
 * to collect the properties
 * @since 0.1 (Philly 99 meeting)
 * @author E. Michael Maximilien (maxim@us.ibm.com)
 */
public class SimpleEntry implements JposEntry, Serializable, Comparable
{
    //--------------------------------------------------------------------------
    // Ctor(s)
    //

	/**
	 * Default ctor (sets the JposRegPopulator to null)
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public SimpleEntry() { regPopulator = null; }

	/**
	 * One argument ctor taking the JposRegPopulator for this entry
	 * @param populator the JposRegPopulator for this entry
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public SimpleEntry( JposRegPopulator populator ) { regPopulator = populator; }

	/**
	 * One argument ctor taking the JposRegPopulator for this entry
	 * @param logicalName the logical name for this entry
	 * @param populator the JposRegPopulator for this entry
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public SimpleEntry( String logicalName, JposRegPopulator populator ) 
	{
		this( populator );

		addProperty( LOGICAL_NAME_PROP_NAME, logicalName );
	}

	/**
	 * One argument ctor taking the LogicalName this entry
	 * @param logicalName the logical name string for this entry
	 * @since 2.0.0
	 */
	SimpleEntry( String logicalName ) { addProperty( LOGICAL_NAME_PROP_NAME, logicalName ); }

    //--------------------------------------------------------------------------
    // Public instance methods
    //

    /**
     * @return count of number of properties 
     * @since 0.1 (Philly 99 meeting)
     */
    public int getPropertyCount() { return properties.size(); }

    /**
     * @return an enumerator for the properties names 
     * @since 0.1 (Philly 99 meeting)
     */
    public Enumeration getPropertyNames() { return properties.keys(); }

    /**
     * @return true if there is a property by the name specified
     * @param propName the property name String
     * @since 0.1 (Philly 99 meeting)
     */
    public boolean hasPropertyWithName( String propName ) { return properties.containsKey( propName ); }

    /**
     * @return true if there is a property by the value specified
     * NOTE: Object.equals method will be used to compare
     * @param propValue the property's value Object
     * @since 0.1 (Philly 99 meeting)
     */
    public boolean hasPropertyWithValue( Object propValue ) { return properties.contains( propValue ); }

    /** 
     * @return the property's value Object
     * @param propName the property's propName String
     * @since 0.1 (Philly 99 meeting)
     */
    public Object getPropertyValue( String propName ) { return properties.get( propName ); }

    /** 
     * @return the property's type
     * @param propName the property's name String
     * @since 2.0.0
     */
    public Class getPropertyType( String propName ) { return getPropertyValue( propName ).getClass(); }

    /**
     * Modifies the property value of the property passed
	 * @return the oldPropValue or null if this property does not exist
     * @param propName the property name
	 * @param propValue the new property value
	 * @since 1.3 (Tokyo 2001 meeting)
     * @throws java.lang.IllegalArgumentException if the propName or propValue is null
     */
    public Object modifyPropertyValue( String propName, Object propValue ) throws IllegalArgumentException
	{
		checkNull( propName );
		checkNull( propValue );

		if( hasPropertyWithName( propName ) == false )
			return null;

		Object oldValue = removeProperty( propName );

		addProperty( propName, propValue );

		return oldValue;
	}

    /**
     * Adds a property to the JposEntry object.
     * NOTE: any property with the same name gets overlaid
     * @param propName the name of this property (should be unique per property)
     * @param propValue the properties value Object
     * @since 0.1 (Philly 99 meeting)
     * @throws java.lang.IllegalArgumentException if the propName or propValue is null
     */
    public Object addProperty( String propName, Object propValue ) throws IllegalArgumentException
	{
		checkNull( propName );
		checkNull( propValue );

		return properties.put( propName, propValue ); 
	}

    /**
     * Looks for a property with name specified and removes it.  If none exist then 
	 * does nothing and return null
	 * @return the value for the name passed
     * @param propName the name String of the property to remove
     * @since 0.1 (Philly 99 meeting)
     */
    public Object removeProperty( String propName ) { return properties.remove( propName ); }

    /** 
     * @return true if the two JposEntries have the same properties 
     * @since 0.1 (Philly 99 meeting)
     */
    public boolean equals( JposEntry otherEntry )
    {
        if( otherEntry == null ) return false;

        if( getPropertyCount() != otherEntry.getPropertyCount() ) return false;

        Enumeration otherPropNames = otherEntry.getPropertyNames();

        while( otherPropNames.hasMoreElements() )
        {
            String name = (String)otherPropNames.nextElement();
            Object value = otherEntry.getPropertyValue( name );

            if( !hasPropertyWithName( name ) ) return false;

            if( !getPropertyValue( name ).equals( value ) ) return false;
        }

        return true;
    }

	/**
	 * @return a copy of this JposEntry object
	 * @since 1.3 (Tokyo 2001 meeting)
	 */
	public JposEntry copy() 
	{
		JposEntry entryCopy = new SimpleEntry();

		Enumeration entryNames = getPropertyNames();

		while( entryNames.hasMoreElements() )
		{
			String propName = (String)entryNames.nextElement();
			entryCopy.addProperty( propName,getPropertyValue( propName ) );
		}

		return entryCopy; 
	}

	/**
	 * @return the JposRegPopulator that loads/saves this entry.  If null the default
	 * populator is used
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public JposRegPopulator getRegPopulator() { return regPopulator; }

	/**
	 * @return the logical name for this JposEntry.  This is a shortcut for easily getting
	 * the logical name vs getting a property and passing the logical name constant
	 * @see jpos.config.JposEntry#getPropertyValue
	 * @see jpos.config.JposEntry#LOGICAL_NAME_PROP_NAME
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public String getLogicalName() { return (String)getPropertyValue( JposEntry.LOGICAL_NAME_PROP_NAME ); }

	/**
	 * @return the JposEntry.Prop with name specified or null if no such property exist
	 * @param propName the property name
	 * @since 2.0.0
	 */
	public JposEntry.Prop getProp( String propName )
	{
		Object propValue = getPropertyValue( propName );

		if( propValue == null ) return null;

		return new Prop( propName, propValue );
	}

	/**
	 * @return an Iterator over the properties in this JposEntry as JposEntry.Prop objects
	 * @since 1.3 (Washington DC 2001)
	 */
	public Iterator getProps()
	{
		List list = new ArrayList();

		Enumeration names = getPropertyNames();

		while( names.hasMoreElements() )
		{
			String name = (String)names.nextElement();

			list.add( new Prop( name, getPropertyValue( name ) ) );
		}

		return list.iterator();
	}

	/**
	 * Adds a new property
	 * @param prop the JposEntry.Prop to add
	 * @since 1.3 (Washington DC 2001 meeting)
	 * @throws java.lang.IllegalArgumentException if the argument is null
	 */
	public void add( JposEntry.Prop prop ) throws IllegalArgumentException
	{
		checkNull( prop );

		addProperty( prop.getName(), prop.getValue() ); 
	}

	/**
	 * Removes the property
	 * @param prop the JposEntry.Prop to remove
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public void remove( JposEntry.Prop prop ) { removeProperty( prop.getName() ); }

	/**
	 * Modifies the property with name of property passed with the new value if
	 * that property currently exist in the entry otherwise does nothing
	 * @param prop the JposEntry.Prop to modify
	 * @since 2.0.0
	 * @throws java.lang.IllegalArgumentException if the prop is null
	 */
	public void modify( JposEntry.Prop prop ) throws IllegalArgumentException
	{
		checkNull( prop );

		if( hasPropertyWithName( prop.getName() ) == false ) return;

		modifyPropertyValue( prop.getName(), prop.getValue() );
	}

	/** 
	 * @return true if this entry has the property passed
	 * @param prop the JposEntry.Prop to check for
	 * @since 1.3 (Washington DC 2001 meeting)
	 */
	public boolean hasProp( JposEntry.Prop prop ) { return hasPropertyWithName( prop.getName() ); }

	/** 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -