package mit.roles ;

public class QualifierType
implements roles.QualifierType
{
	private static String QUALIFIER_TYPE_DESC = "QUALIFIER_TYPE_DESC" ;

	private static mit.roles.RolesFactory rolesFactory = null ;
	public static mit.roles.RolesFactory getRolesFactory() { return rolesFactory ; }
	protected static void setRolesFactory( mit.roles.RolesFactory rFactory )
		{ rolesFactory = rFactory ; }

	private String type = null ;
	public String getType() { return this.type ; }
	public void setType( String type )
		{ this.type = type ; }

	private String description = null ;
	public String getDescription() { return this.description ; }
	private void setDescription( String description )
		{ this.description = description ; }

	private Boolean foundInRoles = new Boolean( false ) ;
	public Boolean isFoundInRoles()
	throws Exception
	{
		if( ! this.foundInRoles.booleanValue() )
		{
			refresh() ;
		}
		return this.foundInRoles ;
	}

	public void refresh()
	throws Exception
	{
		if( ( null != getType() )
		&&  ( null != getRolesFactory() )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select qualifier_type_desc "
						+ "from qualifier_type "
						+ "where qualifier_type = "
						+ getType()
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					setDescription( ( String ) row[ rows.getColumn( QUALIFIER_TYPE_DESC ) ] ) ;
					this.foundInRoles = new Boolean( true ) ;
				}
			}
		}
	}

	public QualifierType
	( mit.roles.RolesFactory rolesFactory
	, String type
	, String description
	)
	{
		setRolesFactory( rolesFactory ) ;
		setType( type ) ;
		setDescription( description ) ;
	}

}