Changeset 2232

Show
Ignore:
Timestamp:
06/12/08 10:29:19 (4 months ago)
Author:
apatel
Message:

performance improvement and code formatting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/commands/ShapeDeleteCommand.java

    r2229 r2232  
    7070        private Collection m_controlResources = null; 
    7171         
    72         private StringBuffer mCustomization = new StringBuffer()
     72        private StringBuffer mCustomization
    7373         
    7474        /** 
     
    269269        private void loadCustomPolicy() 
    270270        { 
    271                 if( mCustomization.length () <= 0) 
     271                if( mCustomization == null || mCustomization.length () <= 0) 
    272272                        return; 
    273273                 
     
    310310        private void saveCustomPolicy() 
    311311        { 
    312                         final SELinuxSystem system = m_child.getSystem (); 
    313                         final IFile []files = system.getCustomModuleFiles (); 
    314                         final List lines_to_remove = new ArrayList(); 
    315                         final List lines = new ArrayList(); 
    316  
     312                final SELinuxSystem system = m_child.getSystem (); 
     313                final IFile []files = system.getCustomModuleFiles (); 
     314                final List lines_to_remove = new ArrayList(); 
     315                final List lines = new ArrayList(); 
     316 
     317                 
     318//                      Shell shell = Display.getCurrent ().getActiveShell (); 
     319                if( files == null ) 
     320                        return; 
     321                 
     322                SLIDEProjectNature nat = SLIDEProjectNature.getNature(system.getProject ()); 
     323                 
     324                PolicyXMLContainer policyXML = nat.getPolicyXML (system.getFolder ()); 
     325                if ( policyXML == null ) 
     326                        return; 
     327                 
     328                IPolicyPartCreator part_creator = policyXML.getCreator (); 
     329                if( part_creator == null ) 
     330                        return; 
     331 
     332                final File interfacefile = files[0].getLocation ().toFile (); 
     333                 
     334                Map modified_templates = null; 
     335                 
     336                try 
     337                { 
     338                        modified_templates = MacroParser.parseM4File (interfacefile, MacroParser.TEMPLATE, part_creator ); 
     339                } 
     340                catch(MacroParseException me) 
     341                { 
     342                        return; 
     343                } 
     344                catch(FileNotFoundException fe) 
     345                { 
     346                        return; 
     347                } 
     348                 
     349                Collection custom_interfafces = null; 
     350 
     351                if (modified_templates != null && modified_templates.size () > 0 ) 
     352                { 
     353                        custom_interfafces = CustomUtil.computePossibleNames (m_child.getComponent (), system.getName()); 
     354                } 
     355                 
     356                List interface_info = new ArrayList(); 
     357                if( custom_interfafces != null && custom_interfafces.size () > 0 ) 
     358                { 
     359                        for( Iterator name_itr = custom_interfafces.iterator (); name_itr.hasNext (); ) 
     360                        { 
     361                                String name = name_itr.next ().toString (); 
     362                                if( modified_templates.containsKey (name.toString ()) ) 
     363                                { 
     364                                        interface_info.add(modified_templates.get (name.toString ())); 
     365                                } 
     366                        } 
     367                } 
     368                 
     369                if( interface_info.size () > 0 ) 
     370                { 
     371                        try 
     372                        { 
     373                                BufferedReader reader = new BufferedReader(new FileReader(interfacefile)); 
     374                                String line; 
     375                                 
     376                                while ( (line = reader.readLine ()) != null ) 
     377                                { 
     378                                        lines.add (line); 
     379                                } 
     380                                reader.close (); 
     381                        } 
     382                        catch(FileNotFoundException fne) 
     383                        { 
     384                                return; 
     385                        } 
     386                        catch(IOException ie) 
     387                        { 
     388                                return; 
     389                        } 
    317390                         
    318 //                      Shell shell = Display.getCurrent ().getActiveShell (); 
    319                         if( files == null ) 
     391                        mCustomization = new StringBuffer(); 
     392                         
     393                        for( Iterator node_itr = interface_info.iterator (); node_itr.hasNext (); ) 
     394                        { 
     395                                MacroNode n = (MacroNode)node_itr.next (); 
     396                                int comment_end_line = -1; 
     397                                int comment_start_line = -1; 
     398                                 
     399                                for (int index = 0; index < lines.size () && comment_end_line < 0; index++ ) 
     400                                { 
     401                                        String st = (String)lines.get(index); 
     402                                        if( st.startsWith ("template")  && st.contains (n.getName ()) ) 
     403                                        { 
     404                                                comment_end_line = index; 
     405                                        } 
     406                                } 
     407                                if( comment_end_line > 1 ) 
     408                                { 
     409                                        for (int index=comment_end_line-1; index >= 0 && comment_start_line <= 0; index--) 
     410                                        { 
     411                                                String st = (String)lines.get(index);  
     412                                                if( ! st.startsWith ("#") ) 
     413                                                        comment_start_line = index; 
     414                                        } 
     415                                } 
     416                                 
     417                                if( comment_start_line >= 0 ) 
     418                                { 
     419                                        for (int index=comment_start_line; index < n.getEndLine (); index++) 
     420                                        { 
     421                                                lines_to_remove.add (new Integer(index)); 
     422                                                mCustomization.append (lines.get(index)); 
     423                                                mCustomization.append ("\n"); 
     424                                        } 
     425                                } 
     426                        } 
     427                } 
     428                 
     429                if( lines_to_remove.size () > 0) 
     430                { 
     431                        try 
     432                        { 
     433                                FileWriter writer = new FileWriter(interfacefile, false); 
     434                                for(int index = 0; index < lines.size (); index++) 
     435                                { 
     436                                        if( lines_to_remove.contains (new Integer(index)) ) 
     437                                                continue; 
     438                                        writer.write ((String)lines.get(index)); 
     439                                        writer.write("\n"); 
     440                                } 
     441                                writer.flush (); 
     442                                writer.close (); 
     443                        } 
     444                        catch(IOException ie) 
     445                        { 
    320446                                return; 
    321                          
    322                         SLIDEProjectNature nat = SLIDEProjectNature.getNature(system.getProject ()); 
    323                          
    324                         PolicyXMLContainer policyXML = nat.getPolicyXML (system.getFolder ()); 
    325                         if ( policyXML == null ) 
    326                                 return; 
    327                          
    328                         IPolicyPartCreator part_creator = policyXML.getCreator (); 
    329                         if( part_creator == null ) 
    330                                 return; 
    331  
    332                         final File interfacefile = files[0].getLocation ().toFile (); 
    333                          
    334                         Map modified_templates = null; 
    335                          
    336                         try 
    337                         { 
    338                                 modified_templates = MacroParser.parseM4File (interfacefile, MacroParser.TEMPLATE, part_creator ); 
    339                         } 
    340                         catch(MacroParseException me) 
    341                         { 
    342                                 return; 
    343                         } 
    344                         catch(FileNotFoundException fe) 
    345                         { 
    346                                 return; 
    347                         } 
    348                          
    349                         Collection custom_interfafces = null; 
    350  
    351                         if (modified_templates != null && modified_templates.size () > 0 ) 
    352                         { 
    353                                 custom_interfafces = CustomUtil.computePossibleNames (m_child.getComponent (), system.getName()); 
    354                         } 
    355                          
    356                         List interface_info = new ArrayList(); 
    357                         if( custom_interfafces != null && custom_interfafces.size () > 0 ) 
    358                         { 
    359                                 for( Iterator name_itr = custom_interfafces.iterator (); name_itr.hasNext (); ) 
    360                                 { 
    361                                         String name = name_itr.next ().toString (); 
    362                                         if( modified_templates.containsKey (name.toString ()) ) 
    363                                         { 
    364                                                 interface_info.add(modified_templates.get (name.toString ())); 
    365                                         } 
    366                                 } 
    367                         } 
    368                          
    369                         if( interface_info.size () > 0 ) 
    370                         { 
    371                                 try 
    372                                 { 
    373                                         BufferedReader reader = new BufferedReader(new FileReader(interfacefile)); 
    374                                         String line; 
    375                                          
    376                                         while ( (line = reader.readLine ()) != null ) 
    377                                         { 
    378                                                 lines.add (line); 
    379                                         } 
    380                                         reader.close (); 
    381                                 } 
    382                                 catch(FileNotFoundException fne) 
    383                                 { 
    384                                         return; 
    385                                 } 
    386                                 catch(IOException ie) 
    387                                 { 
    388                                         return; 
    389                                 } 
    390                                  
    391                                 for( Iterator node_itr = interface_info.iterator (); node_itr.hasNext (); ) 
    392                                 { 
    393                                         MacroNode n = (MacroNode)node_itr.next (); 
    394                                         int comment_end_line = -1; 
    395                                         int comment_start_line = -1; 
    396                                          
    397                                         for (int index = 0; index < lines.size () && comment_end_line < 0; index++ ) 
    398                                         { 
    399                                                 String st = (String)lines.get(index); 
    400                                                 if( st.startsWith ("template")  && st.contains (n.getName ()) ) 
    401                                                 { 
    402                                                         comment_end_line = index; 
    403                                                 } 
    404                                         } 
    405                                         if( comment_end_line > 1 ) 
    406                                         { 
    407                                                 for (int index=comment_end_line-1; index >= 0 && comment_start_line <= 0; index--) 
    408                                                 { 
    409                                                         String st = (String)lines.get(index);  
    410                                                         if( ! st.startsWith ("#") ) 
    411                                                                 comment_start_line = index; 
    412                                                 } 
    413                                         } 
    414                                          
    415                                         if( comment_start_line >= 0 ) 
    416                                         { 
    417                                                 for (int index=comment_start_line; index < n.getEndLine (); index++) 
    418                                                 { 
    419                                                         lines_to_remove.add (new Integer(index)); 
    420                                                         mCustomization.append (lines.get(index)); 
    421                                                         mCustomization.append ("\n"); 
    422                                                 } 
    423                                         } 
    424                                 } 
    425                         } 
    426                          
    427                         if( lines_to_remove.size () > 0) 
    428                         { 
    429                                 try 
    430                                 { 
    431                                         FileWriter writer = new FileWriter(interfacefile, false); 
    432                                         for(int index = 0; index < lines.size (); index++) 
    433                                         { 
    434                                                 if( lines_to_remove.contains (new Integer(index)) ) 
    435                                                         continue; 
    436                                                 writer.write ((String)lines.get(index)); 
    437                                                 writer.write("\n"); 
    438                                         } 
    439                                         writer.flush (); 
    440                                         writer.close (); 
    441                                 } 
    442                                 catch(IOException ie) 
    443                                 { 
    444                                         return; 
    445                                 } 
    446                         } 
     447                        } 
     448                } 
    447449        } 
    448450