Changeset 1992

Show
Ignore:
Timestamp:
03/11/08 11:20:56 (9 months ago)
Author:
apatel
Message:

some cleanup.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java

    r1991 r1992  
    531531                        IFile metadataFile = getProject ().getFile(mLayer.getProjectRelativePath().append("metadata.xml")); //$NON-NLS-1$ 
    532532                         
    533                         String summary = "<summary> </summary>"; 
     533                        String summary = "<summary>CDSFramework Policy Layer</summary>\n"; 
    534534                        InputStream stream = new ByteArrayInputStream (summary.getBytes()); //$NON-NLS-1$ 
    535535                        metadataFile.create(stream, true, null); 
     
    762762                private IFile[] mModule; 
    763763 
    764                 public CPolicyContainer(String mod_postfix) 
    765                 { 
    766                         CUSTOM_MODULE_NAME = "cds-custom" + mod_postfix; 
     764                public CPolicyContainer(String module_postfix) 
     765                { 
     766                        CUSTOM_MODULE_NAME = "cds-custom-" + module_postfix; 
    767767                        mModified = new HashMap (10); 
    768768                } 
     
    794794                                        InputStream stream = new ByteArrayInputStream (((String)array[i][1]).getBytes()); 
    795795                                        mModule[i] = file; 
    796                                         mModule[i].create (stream, true, null); 
    797                                         mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 
     796                                        if( mModule[i].exists() ) 
     797                                        { 
     798                                                mModule[i].appendContents (stream, IResource.KEEP_HISTORY, null); 
     799                                                mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 
     800                                        } 
     801                                        else 
     802                                        { 
     803                                                mModule[i].create (stream, true, null); 
     804                                                mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 
     805                                        } 
    798806                                } 
    799807                        } 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/custom/AddCustomPolicy.java

    r1991 r1992  
    1313import java.io.OutputStream; 
    1414 
    15 import org.eclipse.core.internal.resources.WorkspaceRoot; 
    1615import org.eclipse.core.resources.IFile; 
    17 import org.eclipse.core.resources.IFolder; 
    1816import org.eclipse.core.resources.IResource; 
    1917import org.eclipse.core.runtime.CoreException; 
    20 import org.eclipse.core.runtime.IPath; 
    21 import org.eclipse.core.runtime.Platform; 
    2218import org.eclipse.gef.ui.actions.SelectionAction; 
    2319import org.eclipse.jface.dialogs.ErrorDialog; 
     
    2723import org.eclipse.swt.widgets.Shell; 
    2824import org.eclipse.ui.PartInitException; 
    29 import org.eclipse.ui.PlatformUI; 
    3025import org.eclipse.ui.ide.IDE; 
    3126 
     
    4338import com.tresys.framework.plugin.editor.policy.graphic.parts.AccessEditPart; 
    4439import com.tresys.framework.plugin.editor.policy.graphic.parts.DomainEditPart; 
     40import com.tresys.framework.plugin.editor.policy.graphic.parts.PolicyEditPart; 
    4541import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 
    4642import com.tresys.slide.plugin.editors.module.ModuleEditor; 
    47 //import com.tresys.slide.plugin.editors.module.ModuleEditorInput; 
    48 //import com.tresys.slide.plugin.views.policyexplorer.PLayer; 
    49 //import com.tresys.slide.plugin.views.policyexplorer.PModule; 
    5043 
    5144public class AddCustomPolicy 
     
    10598                        return; 
    10699                 
    107                 /** 
    108                  * Get the selection, get policy of the selection  
    109                  * and get the file system resource for editor input. 
    110                  */ 
    111                 OutputStream stream = getPolicy (); 
    112                 if( stream == null ) 
    113                 { 
    114                         System.out.println ("AddCustomPolicy.run() --> No Policy Found"); 
    115                         return; 
    116                 } 
    117                  
    118                  
    119100                try 
    120101                { 
     
    130111                        if( files[CPolicyContainer.TE_FILE].exists () ) 
    131112                        { 
     113                                /** 
     114                                 * Get the selection, get policy of the selection  
     115                                 * and get the file system resource for editor input. 
     116                                 */ 
     117                                OutputStream stream = getPolicy (); 
     118                                if( stream == null ) 
     119                                { 
     120                                        System.out.println ("AddCustomPolicy.run() --> No Policy Found"); 
     121                                        return; 
     122                                } 
     123                                 
    132124                                ByteArrayInputStream input = new ByteArrayInputStream(stream.toString ().getBytes ()); 
    133                                 files[0].appendContents (input, IResource.KEEP_HISTORY, null); 
     125                                files[CPolicyContainer.TE_FILE].appendContents (input, IResource.KEEP_HISTORY, null); 
    134126                        } 
    135127                        /** 
     
    150142        private final boolean customizationAllowed(Object selected_item) 
    151143        { 
    152                 Linkage linkage = mEditor.getSystem ().getLinkage (); 
    153                 SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 
    154                  
    155144                boolean supports_customization = false; 
    156145                 
    157                 if( selected_item instanceof ShapeEditPart) 
    158                 { 
    159                         ShapeEditPart shape_part = (ShapeEditPart)selected_item; 
    160                         Object model = shape_part.getModel (); 
     146                if( selected_item instanceof PolicyEditPart) 
     147                { 
     148                        PolicyEditPart policy_part = (PolicyEditPart)selected_item; 
     149                        Object model = policy_part.getModel (); 
    161150                        if( model instanceof Shape ) 
    162151                        { 
     
    164153                                Component comp = shape.getComponent ();  
    165154                                if( comp instanceof ICustomPolicy ) 
    166                                         supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 
    167                         } 
    168                 } 
    169                 else if( selected_item instanceof DomainEditPart) 
    170                 { 
    171                         DomainEditPart part = (DomainEditPart)selected_item; 
    172                         Object model = part.getModel (); 
    173                         if( model instanceof Shape ) 
    174                         { 
    175                                 Shape shape = (Shape)model; 
    176                                 Component comp = shape.getComponent (); 
    177                                 if( comp instanceof ICustomPolicy ) 
    178                                         supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 
    179                         } 
    180                 } 
    181                 else if( selected_item instanceof AbstractConnectionEditPart ) 
    182                 { 
    183                         AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 
    184                          
    185                         Object ab  =  ((AccessEditPart)selected_item).getModel (); 
    186                         Object model = part.getModel (); 
    187                         if( model instanceof Connection) 
    188                         { 
    189                                 Connection con = (Connection)model; 
    190                                 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
    191                                 if( con instanceof ICustomPolicy ) 
    192                                         supports_customization = ((ICustomPolicy)con).supportsCustomPolicy (); 
    193                                 con.Accept (meta_visitor); 
    194                                 OutputStream p = policy.GetPolicy (); 
    195                                 print_debug (p); 
    196                         } 
    197                 } 
    198                 return supports_customization; 
    199         } 
    200          
    201          
    202         private final Object getModel() 
    203         { 
    204                 IStructuredSelection selection = (StructuredSelection)getSelection (); 
    205                 Object selected_item = selection.getFirstElement (); 
    206                  
    207                 Linkage linkage = mEditor.getSystem ().getLinkage (); 
    208                 SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 
    209                  
    210                 if( selected_item instanceof ShapeEditPart) 
    211                 { 
    212                         ShapeEditPart shape_part = (ShapeEditPart)selected_item; 
    213                         Object model = shape_part.getModel (); 
     155                                { 
     156                                        ICustomPolicy customization = (ICustomPolicy)comp; 
     157                                        boolean can_be_customized = customization.supportsCustomPolicy (); 
     158                                        boolean modified = !customization.hasCustomization (); 
     159                                        supports_customization = (can_be_customized & modified); 
     160                                } 
     161                        } 
    214162                } 
    215163                else if( selected_item instanceof AbstractConnectionEditPart ) 
     
    220168                        { 
    221169                                Connection con = (Connection)model; 
    222                                 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
    223                         } 
    224                 } 
    225                 return null; 
    226         } 
    227          
    228         void getPolicy(Object model) 
    229         { 
     170                                if( con instanceof ICustomPolicy ) 
     171                                { 
     172                                        ICustomPolicy customization = (ICustomPolicy)con; 
     173                                        boolean can_be_customized = customization.supportsCustomPolicy (); 
     174                                        boolean modified = !customization.hasCustomization (); 
     175                                        supports_customization = (can_be_customized & modified); 
     176                                } 
     177                        } 
     178                } 
     179                return supports_customization; 
    230180        } 
    231181         
     
    238188                SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 
    239189                 
    240                 if( selected_item instanceof ShapeEditPart) 
    241                 { 
    242                         ShapeEditPart shape_part = (ShapeEditPart)selected_item; 
    243                         Object model = shape_part.getModel (); 
     190                if( selected_item instanceof PolicyEditPart) 
     191                { 
     192                        PolicyEditPart policy_part = (PolicyEditPart)selected_item; 
     193                        Object model = policy_part.getModel (); 
    244194                        if( model instanceof Shape ) 
    245195                        { 
    246196                                Shape shape = (Shape)model; 
    247                                 shape.getComponent ().Accept (policy); 
    248                                 // generated policy 
    249                                 OutputStream p = policy.GetPolicy (); 
    250                                 System.out.println (p); 
    251                                 return p; 
    252                         } 
    253                 } 
    254                 if( selected_item instanceof DomainEditPart) 
    255                 { 
    256                         DomainEditPart part = (DomainEditPart)selected_item; 
    257                          
    258                         Object model = part.getModel (); 
    259                         if( model instanceof Shape ) 
    260                         { 
    261                                 Shape shape = (Shape)model; 
    262                                 shape.getComponent ().Accept (policy); 
    263                                 // generated policy 
    264                                 OutputStream p = policy.GetPolicy (); 
    265                                 System.out.println (p); 
    266                                 return p; 
    267                         } 
    268                 } 
    269  
    270                 if( selected_item instanceof AbstractConnectionEditPart ) 
     197                                Component comp = shape.getComponent (); 
     198                                if( comp instanceof ICustomPolicy) 
     199                                { 
     200                                        ICustomPolicy customization = (ICustomPolicy)comp; 
     201                                        customization.markCustomized (); 
     202                                        comp.Accept (policy); 
     203                                        // generated policy 
     204                                        OutputStream p = policy.GetPolicy (); 
     205                                        return p; 
     206                                } 
     207                        } 
     208                } 
     209                else if( selected_item instanceof AbstractConnectionEditPart ) 
    271210                { 
    272211                        AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 
     
    275214                        { 
    276215                                Connection con = (Connection)model; 
    277                                 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
    278                                 con.Accept (meta_visitor); 
    279                                  
    280                                 // text policy 
    281                                 OutputStream p = policy.GetPolicy (); 
    282                                 System.out.println (p); 
    283                                 return p; 
     216                                if( con instanceof ICustomPolicy) 
     217                                { 
     218                                        ICustomPolicy customization = (ICustomPolicy)con; 
     219                                        customization.markCustomized (); 
     220                                        GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
     221                                        con.Accept (meta_visitor); 
     222                                        // text policy 
     223                                        OutputStream p = policy.GetPolicy (); 
     224                                        return p; 
     225                                } 
    284226                        } 
    285227                }