Changeset 2174

Show
Ignore:
Timestamp:
05/22/08 09:42:11 (6 months ago)
Author:
apatel
Message:

updated add and remove methods of the network configuration object. We need to put the system and network resources in the separate maps to overcome name collisions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/compiler/linkage/net/NetworkConfig.java

    r2172 r2174  
    88|*| $Rev:2113 $ 
    99\*/ 
    10  
    1110 
    1211package com.tresys.framework.compiler.linkage.net; 
     
    2019/** 
    2120 * @author dsugar 
    22  * 
     21 *  
    2322 */ 
    2423public class NetworkConfig 
    2524{ 
    26         private final Map m_items = new HashMap (); 
    27 //     private final Map m_resources = new HashMap (); 
     25        private final Map m_netresources = new HashMap (); 
     26       private final Map m_systems = new HashMap (); 
    2827        private final Map m_connections = new HashMap (); 
    29          
     28 
    3029        public NetworkConfig () 
    3130        {} 
    32          
     31 
    3332        public void Add (NetItem i_item) 
    3433        { 
    3534                if (i_item == null) 
    3635                        throw new IllegalArgumentException (); 
    37                  
     36 
    3837                String sName = i_item.getName (); 
    39                 m_items.put (sName, i_item); 
     38                if (i_item instanceof NetSystem) 
     39                        m_systems.put (sName, i_item); 
     40                else if (i_item instanceof NetResource) 
     41                        m_systems.put (sName, i_item); 
    4042        } 
    41          
     43 
    4244        public void Remove (NetItem i_item) 
    4345        { 
    44                 if (i_item != null) 
    45                 { 
    46                         String sName = i_item.getName (); 
    47                         Remove (sName); 
    48                 } 
    49         } 
    50          
    51         public void Remove (String i_sName) 
    52         { 
    53                 if (i_sName == null) 
    54                         throw new IllegalArgumentException (); 
    55                  
    56                 m_items.remove (i_sName); 
     46                if (i_item == null) 
     47                        return; 
     48                String sName = i_item.getName (); 
     49                if (i_item instanceof NetSystem) 
     50                        RemoveSystem (sName); 
     51                else if (i_item instanceof NetResource) 
     52                        RemoveNetResource (sName); 
    5753        } 
    5854 
    59         public void Accept(INetVisitor i_visitor) 
     55        public void RemoveSystem (String i_sSystemName) 
     56        { 
     57                m_systems.remove (i_sSystemName); 
     58        } 
     59 
     60        public void RemoveNetResource (String i_sNetResourceName) 
     61        { 
     62                m_netresources.remove (i_sNetResourceName); 
     63        } 
     64 
     65        public void Accept (INetVisitor i_visitor) 
    6066        { 
    6167                i_visitor.Visit (this); 
    62                  
    63                 for( Iterator itr= m_items.values ().iterator (); itr.hasNext ();
     68 
     69                for (Iterator itr = m_systems.values ().iterator (); itr.hasNext ();
    6470                { 
    65                         Object item = itr.next (); 
    66                         if( item instanceof NetResource) 
    67                                 i_visitor.Visit ((NetResource)item); 
    68                         else if( item instanceof NetSystem) 
    69                                 i_visitor.Visit ((NetSystem)item); 
     71                        i_visitor.Visit ((NetSystem) itr.next ()); 
    7072                } 
    71                 for( Iterator itr= m_connections.values ().iterator (); itr.hasNext ();
     73                for (Iterator itr = m_netresources.values ().iterator (); itr.hasNext ();
    7274                { 
    73                         i_visitor.Visit ((NetConnection)itr.next ()); 
     75                        i_visitor.Visit ((NetResource) itr.next ()); 
     76                } 
     77                for (Iterator itr = m_connections.values ().iterator (); itr.hasNext ();) 
     78                { 
     79                        i_visitor.Visit ((NetConnection) itr.next ()); 
    7480                } 
    7581        } 
     
    7783        public NetSystem getSystem (String i_sName) 
    7884        { 
    79                 NetItem item = (NetItem) m_items.get (i_sName); 
     85                return (NetSystem) m_systems.get (i_sName); 
     86        } 
    8087 
    81                 if (item instanceof NetSystem) 
    82                         return (NetSystem) item; 
    83                 return null; 
    84         } 
    85          
    8688        public NetResource getResource (String i_sName) 
    8789        { 
    88                 NetItem item = (NetItem) m_items.get (i_sName); 
    89  
    90                 if (item instanceof NetResource) 
    91                         return (NetResource) item; 
    92                 return null; 
     90                return (NetResource) m_netresources.get (i_sName); 
    9391        } 
    9492 
    9593        public Collection getNetworkItems () 
    9694        { 
    97                 return m_items.values (); 
     95                Collection coll = m_systems.values (); 
     96                coll.addAll (m_netresources.values ()); 
     97                return coll; 
    9898        } 
    99          
     99 
    100100        public void Add (NetConnection i_connection) 
    101101        { 
    102102                if (i_connection == null) 
    103103                        throw new IllegalArgumentException (); 
    104                  
     104 
    105105                String sName = i_connection.toString (); 
    106106                m_connections.put (sName, i_connection); 
    107107        } 
    108          
     108 
    109109        public void Remove (NetConnection i_connection) 
    110110        { 
     
    115115                } 
    116116        } 
    117          
     117 
    118118        public Collection getConnections (NetResource i_res) 
    119119        { 
     
    121121                if (i_res == null) 
    122122                        return list; 
    123                  
    124                 for (Iterator itr = m_connections.values ().iterator (); itr.hasNext ();
     123 
     124                for (Iterator itr = m_connections.values ().iterator (); itr.hasNext ();
    125125                { 
    126126                        NetConnection connection = (NetConnection) itr.next (); 
     
    128128                                list.add (connection); 
    129129                } 
    130                  
     130 
    131131                return list; 
    132132        } 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/builder/FrameworkNature.java

    r2171 r2174  
    638638                        systems.remove(i_system); 
    639639                        // remove the system from the netconfig 
    640                         getNetworkConfiguration ().Remove(i_system.getName ()); 
     640                        getNetworkConfiguration ().RemoveSystem (i_system.getName ()); 
    641641                } 
    642642        }