Changeset 2173

Show
Ignore:
Timestamp:
05/22/08 08:29:18 (6 months ago)
Author:
npatrick
Message:

Allow users to change the NetworkType? property for NetworkResource? on the property sheet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/NetworkResource.java

    r2143 r2173  
    1212 
    1313import java.util.List; 
     14import java.util.Map; 
    1415 
    1516import com.tresys.framework.compiler.AbstractToken; 
     17import com.tresys.framework.compiler.dictionary.Dictionary; 
    1618import com.tresys.framework.compiler.dictionary.IDictionaryObject; 
    1719import com.tresys.framework.compiler.dictionary.Rdef; 
    1820import com.tresys.framework.compiler.linkage.net.NetResource; 
     21import com.tresys.framework.compiler.systemResources.LabeledNetworkResource; 
     22import com.tresys.framework.compiler.systemResources.NetworkInfo; 
    1923import com.tresys.framework.compiler.systemResources.SystemResource; 
    2024 
     
    2832                super (n, null, policy); 
    2933                m_netInfo = i_netRes; 
     34                 
     35                Dictionary dictionary = policy.getDictionary (); 
     36                Map rdefs = dictionary.GetRdefs (); 
     37                Rdef rdef = (Rdef)rdefs.get ("ipsec"); 
     38                 
     39                this.Add (rdef, new Token(rdef.GetName (), n.getErrorHandler ())); 
     40                 
     41                NetworkInfo info = new NetworkInfo (null, null, null, null); 
     42                LabeledNetworkResource ip_lab = new LabeledNetworkResource (info, rdef); 
     43                this.AddSystemResource (rdef, ip_lab); 
    3044        } 
    3145 
     
    5165                { 
    5266                        if (!GetRdefs ().isEmpty ()) 
    53                                 return false
     67                                this.ClearAllRdef ()
    5468                } 
    5569                return super.Add (rdef, i_token); 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/NetworkResourceShape.java

    r2172 r2173  
    1111 
    1212import java.util.ArrayList; 
     13import java.util.Arrays; 
    1314import java.util.List; 
    1415import java.util.HashSet; 
     
    9899        private IPropertyDescriptor[] m_descriptors = null; 
    99100        private Vector m_rdefs = null; 
     101        private String[] rdefsArray = null; 
    100102 
    101103        private Rdef m_rdef; 
     
    151153                } 
    152154                return m_rdefs; 
     155        } 
     156         
     157        public String[] getRDefsArray() 
     158        { 
     159                if (rdefsArray == null) 
     160                { 
     161                        ArrayList rdefsList = new ArrayList(); 
     162                 
     163                        Dictionary dictionary = getSystem ().getDictionary (); 
     164                        Map rdefs = dictionary.GetRdefs (); 
     165                        Iterator itr = rdefs.values ().iterator (); 
     166 
     167                        while (itr.hasNext ()) 
     168                        { 
     169                                Rdef item = (Rdef) itr.next (); 
     170                                if (item.isNetworkRdef ()) 
     171                                        rdefsList.add (item.GetName ()); 
     172                        } 
     173 
     174                        rdefsArray = new String[rdefsList.size ()]; 
     175                 
     176                        for (int i = 0; i < rdefsList.size (); i++) 
     177                                rdefsArray[i] = (String)rdefsList.get (i); 
     178                } 
     179                 
     180                return rdefsArray; 
     181        } 
     182         
     183        public Integer getRDefsArrayIndex(Rdef rdef) 
     184        { 
     185                return new Integer(Arrays.binarySearch (getRDefsArray (), rdef.GetName ())); 
    153186        } 
    154187         
     
    257290 
    258291                        { 
    259                                 PropertyDescriptor prop_desc = new PropertyDescriptor (NETWORK_TYPE_PROP, DISPLAY_NAME_NETWORK_TYPE); 
    260                                 prop_desc.setCategory (PROP_NETWORK_RESOURCE); 
     292                                ComboBoxPropertyDescriptor prop_desc = new ComboBoxPropertyDescriptor (NETWORK_TYPE_PROP, DISPLAY_NAME_NETWORK_TYPE, getRDefsArray ()); 
     293                                prop_desc.setCategory (PROP_SECTION_BASE); 
    261294                                myDescriptors.add (prop_desc); 
    262295                        } 
     
    340373                                        PropertyDescriptor desc = new ComboBoxPropertyDescriptor (NETWORK_PROTOCOL_INDEX, DISPLAY_NAME_NETWORK_PROTOCOL, 
    341374                                                (String[]) GetNetworkProtcols ().toArray (new String[2])); 
    342                                         desc.setCategory (PROP_NETWORK_RESOURCE); 
     375                                        desc.setCategory (PROP_SECTION_BASE); 
    343376                                        myDescriptors.add (desc); 
    344377                                } 
     
    373406 
    374407                if (NETWORK_TYPE_PROP.equals (propertyId)) 
    375                         return this.m_rdef
     408                        return getRDefsArrayIndex (this.m_rdef)
    376409 
    377410                NetworkResource resource = (NetworkResource) getComponent (); 
     
    398431 
    399432                if (NETWORK_LOCAL_DEVICE.equals (propertyId)) 
    400                         return localInfo.getDevice (); 
    401  
     433                { 
     434                        String retValue = localInfo.getDevice (); 
     435                        if (retValue == null) 
     436                                return ""; 
     437                         
     438                        return retValue; 
     439                } 
     440                 
    402441                if (NETWORK_LOCAL_IP_ADDRESS.equals (propertyId)) 
    403                         return localInfo.getIPAddr (); 
    404  
     442                { 
     443                        String retValue = localInfo.getIPAddr (); 
     444                        if (retValue == null) 
     445                                return ""; 
     446                         
     447                        return retValue; 
     448                } 
     449                 
    405450                if (NETWORK_LOCAL_MASK.equals (propertyId)) 
    406                         return localInfo.getMask (); 
     451                { 
     452                        String retValue = localInfo.getMask (); 
     453                        if (retValue == null) 
     454                                return ""; 
     455                         
     456                        return retValue; 
     457                } 
    407458 
    408459                if (NETWORK_LOCAL_IP_PORTS.equals (propertyId)) 
     
    425476                 
    426477                if (NETWORK_REMOTE_DEVICE.equals (propertyId)) 
    427                         return remoteInfo.getDevice (); 
     478                { 
     479                        String retValue = remoteInfo.getDevice (); 
     480                        if (retValue == null) 
     481                                return ""; 
     482                         
     483                        return retValue; 
     484                } 
    428485 
    429486                if (NETWORK_REMOTE_IP_ADDRESS.equals (propertyId)) 
    430                         return remoteInfo.getIPAddr (); 
     487                { 
     488                        String retValue = remoteInfo.getIPAddr (); 
     489                        if (retValue == null) 
     490                                return ""; 
     491                         
     492                        return retValue; 
     493                } 
    431494 
    432495                if (NETWORK_REMOTE_MASK.equals (propertyId)) 
    433                         return remoteInfo.getMask (); 
     496                { 
     497                        String retValue = remoteInfo.getMask (); 
     498                        if (retValue == null) 
     499                                return ""; 
     500                         
     501                        return retValue; 
     502                } 
    434503 
    435504                if (NETWORK_REMOTE_IP_PORTS.equals (propertyId)) 
     
    455524                if (NETWORK_TYPE_PROP.equals (propertyId)) 
    456525                { 
    457                         this.m_rdef = (Rdef) value; 
     526                        NetworkResource resource = (NetworkResource)getComponent (); 
     527                        List systemResources = resource.GetSystemResources(m_rdef); 
     528                        SystemResource sysResource = (SystemResource) systemResources.get (0); 
     529 
     530                        NetworkInfo localInfo = null; 
     531 
     532                        if (sysResource instanceof LabeledNetworkResource) 
     533                        { 
     534                                localInfo = ((LabeledNetworkResource) sysResource).getNetworkInfo (); 
     535                                resource.ClearSystemResources (m_rdef); 
     536 
     537                                this.m_rdef = (Rdef)getRDefs ().get (((Integer)value).intValue ()); 
     538                                resource.Add(m_rdef, new Token(m_rdef.GetName (), getErrorHandler ())); 
     539                                 
     540                                sysResource = new IPTablesNetworkResource(localInfo, new NetworkInfo(null, null, null, null), "tcp", m_rdef); 
     541                                resource.AddSystemResource (m_rdef, sysResource); 
     542                        } 
     543 
     544                        else if (sysResource instanceof IPTablesNetworkResource) 
     545                        { 
     546                                localInfo = ((IPTablesNetworkResource) sysResource).getLocalInfo (); 
     547                                resource.ClearSystemResources (m_rdef); 
     548 
     549                                this.m_rdef = (Rdef)getRDefs ().get (((Integer)value).intValue ()); 
     550                                resource.Add(m_rdef, new Token(m_rdef.GetName (), getErrorHandler ())); 
     551 
     552                                sysResource = new LabeledNetworkResource(localInfo, m_rdef); 
     553                                resource.AddSystemResource (m_rdef, sysResource); 
     554                        }                        
    458555                } 
    459556