Main Page | Packages | Class Hierarchy | Class List | File List | Class Members

Environment.java

Go to the documentation of this file.
00001 //$Id: Environment_8java-source.html 336 2010-01-12 20:03:17Z linus $
00002 //Copyright (c) 2003, Mikael Albertsson, Mattias Danielsson, Per Engström, 
00003 //Fredrik Gröndahl, Martin Gyllensten, Anna Kent, Anders Olsson, 
00004 //Mattias Sidebäck.
00005 //All rights reserved.
00006 //
00007 //Redistribution and use in source and binary forms, with or without 
00008 //modification, are permitted provided that the following conditions are met:
00009 //
00010 //* Redistributions of source code must retain the above copyright notice, 
00011 //  this list of conditions and the following disclaimer.
00012 // 
00013 //* Redistributions in binary form must reproduce the above copyright 
00014 //  notice, this list of conditions and the following disclaimer in the 
00015 //  documentation and/or other materials provided with the distribution.
00016 //
00017 //* Neither the name of the University of Linköping nor the names of its 
00018 //  contributors may be used to endorse or promote products derived from 
00019 //  this software without specific prior written permission. 
00020 //
00021 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022 //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00023 //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00024 //ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00025 //LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00026 //CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00027 //SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00028 //INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00029 //CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00030 //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
00031 //THE POSSIBILITY OF SUCH DAMAGE.
00032 
00033 package org.argoprint.engine;
00034 
00035 import java.util.*;
00036 
00037 /**
00038  * The environment or scope for argoprint. Used for storing iterators.
00039  * @author matda701, Mattias Danielsson
00040  */
00041 public class Environment{
00042 
00043     /**
00044      * Reference to self
00045      */
00046     private Environment _instance;
00047     
00048     /**
00049      * Hashtable containing ArgoPrintIterator's hashed with
00050      * name spcifyed by the user/template.
00051      */
00052     private Hashtable _iteratorTable;
00053 
00054     /**
00055      * Constructor for Environment
00056      */ 
00057     public Environment(){
00058         _instance = this;
00059     _iteratorTable = new Hashtable();
00060     }
00061 
00062     /**
00063      * Checks if iterator name exists in the table
00064      */    
00065     public boolean existsIterator(String name){
00066     return _iteratorTable.containsKey(name);
00067     }
00068   
00069     
00070     /**
00071      * Adds an Iterator to the hashtable, hashed with name. Returns
00072      * true if succesful.
00073      */
00074     public boolean addIterator(String name, Iterator iterator){
00075     if(_iteratorTable.containsKey(name)){
00076         //Key collision occured. Perhaps solve this by calling rehash() ?
00077         //and calling addIterator recursively, Or perhaps totally 
00078         //unneccesary since add and get solves this automagically
00079         return false;
00080     }
00081     
00082     try{
00083         _iteratorTable.put(name, iterator);
00084     }
00085     catch(Exception e){
00086         //this means name or iterator is null
00087         return false;
00088     }
00089     
00090     return true;
00091     }
00092     
00093     /**
00094      * Removes the Iterator name from the hashtable. Returns
00095      * true if succesful.
00096      */
00097     public boolean removeIterator(String name){ 
00098     try{
00099         Iterator iter = (Iterator)_iteratorTable.remove(name);
00100         if(iter == null) { return false; }
00101     } 
00102     catch(Exception e){
00103     }
00104     return true;
00105     }
00106 
00107     /**
00108      * Gets the Iterator called name from the hashtable. Returns
00109      * the iterator if succesful, othervise null 
00110      */
00111     public ArgoPrintIterator getIterator(String name){  
00112     try{
00113         return (ArgoPrintIterator)_iteratorTable.get(name);
00114     }
00115     catch(Exception e){
00116         return null;
00117     }
00118     }
00119 
00120     /**
00121      * Returns referenc to self
00122      */
00123     public Environment instance(){
00124     return _instance;
00125     }
00126 }

Generated on Tue Dec 2 22:50:56 2003 for ArgoPrint by doxygen 1.3.4