Package de.netsysit.model

Source Code of de.netsysit.model.DataBaseModel

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.netsysit.model;

import de.netsysit.policymanager.Enums;
import de.netsysit.policymanager.Enums.Algorithms;
import de.netsysit.policymanager.Enums.ItemTypes;
import de.netsysit.policymanager.Enums.Modes;
import de.netsysit.policymanager.Enums.PolicyLevel;
import de.netsysit.policymanager.PolicyUtilities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.swing.DefaultComboBoxModel;

/**
*
* @author ducksoul
*/
public class DataBaseModel extends PropertyChangeModel {

    private List<ApplicationModel> applications;
    private List<ReceiverListModel> receiverLists;
    private List<PolicyModel> aPolicies;
    private List<PolicyModel> cPolicies;
    private List<PolicyModel> iPolicies;
    private LevelModel baseLow;
    private LevelModel baseNormal;
    private LevelModel baseHigh;
   
    private ApplicationModel currentApplication;
    private ReceiverListModel currentReceiverList;
    private PolicyModel currentPolicy;
   
    private PolicyLevel activeLevel = PolicyLevel.NONE;
    private ItemTypes activeItem = ItemTypes.NONE; 
    private Map<ActionTupel, String> aActions;
    private Map<ActionTupel, String> cActions;
    private Map<ActionTupel, String> iActions;
   
    private Set<Integer> appKeys = new TreeSet();
    private Set<Integer> receiverListKeys = new TreeSet();
    private Set<Integer> policyAKeys = new TreeSet();
    private Set<Integer> policyCKeys = new TreeSet();
    private Set<Integer> policyIKeys = new TreeSet();
   
    private String filePath = null;

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public Set<Integer> getAppKeys() {
        return appKeys;
    }

    public void setAppKeys(Set<Integer> appKeys) {
        this.appKeys = appKeys;
    }

    public Set<Integer> getPolicyAKeys() {
        return policyAKeys;
    }

    public void setPolicyAKeys(Set<Integer> policyAKeys) {
        this.policyAKeys = policyAKeys;
    }

    public Set<Integer> getPolicyCKeys() {
        return policyCKeys;
    }

    public void setPolicyCKeys(Set<Integer> policyCKeys) {
        this.policyCKeys = policyCKeys;
    }

    public Set<Integer> getPolicyIKeys() {
        return policyIKeys;
    }

    public void setPolicyIKeys(Set<Integer> policyIKeys) {
        this.policyIKeys = policyIKeys;
    }

    public Set<Integer> getReceiverListKeys() {
        return receiverListKeys;
    }

    public void setReceiverListKeys(Set<Integer> receiverListKeys) {
        this.receiverListKeys = receiverListKeys;
    }
   
    public DataBaseModel() {
        activeLevel = PolicyLevel.NONE;
        activeItem = ItemTypes.NONE;
       
        applications = new ArrayList();
        receiverLists = new ArrayList();
        aPolicies = new ArrayList();
        cPolicies = new ArrayList();
        iPolicies = new ArrayList();
        createHashMaps();      
    }
    
    private void createHashMaps() {
        aActions = new HashMap();
       
        aActions.put(new ActionTupel(Algorithms.NOTDEFINEDA, Modes.NONE), "-1");
       
        cActions = new HashMap();
       
        cActions.put(new ActionTupel(Algorithms.NOTDEFINEDC, Modes.NONE), "-1");
        cActions.put(new ActionTupel(Algorithms.AES128, Modes.CBC), "2.16.840.1.101.3.4.1.2");
        cActions.put(new ActionTupel(Algorithms.AES128, Modes.CFB), "2.16.840.1.101.3.4.1.4");
        cActions.put(new ActionTupel(Algorithms.AES192, Modes.CBC), "2.16.840.1.101.3.4.1.22");
        cActions.put(new ActionTupel(Algorithms.AES192, Modes.CFB), "2.16.840.1.101.3.4.1.24");
        cActions.put(new ActionTupel(Algorithms.AES256, Modes.CBC), "2.16.840.1.101.3.4.1.42");
        cActions.put(new ActionTupel(Algorithms.AES256, Modes.CFB), "2.16.840.1.101.3.4.1.44");
        cActions.put(new ActionTupel(Algorithms.DES, Modes.NONE), "1.3.6.1.4.1.4929.1.6")
       
        iActions = new HashMap();
       
        iActions.put(new ActionTupel(Algorithms.NOTDEFINEDI, Modes.NONE), "-1");
        iActions.put(new ActionTupel(Algorithms.SHA1, Modes.NONE), "1.3.14.3.2.26");
        iActions.put(new ActionTupel(Algorithms.SHA256, Modes.NONE), "2.16.840.1.101.3.4.2.1");
        iActions.put(new ActionTupel(Algorithms.SHA384, Modes.NONE), "2.16.840.1.101.3.4.2.2");
        iActions.put(new ActionTupel(Algorithms.SHA512, Modes.NONE), "2.16.840.1.101.3.4.2.3");
    }

    public LevelModel getBaseLow() {
        return baseLow;
    }

    public void setBaseLow(LevelModel baseLow) {
        LevelModel oldVal = this.baseLow;
        this.baseLow = baseLow;
        changeSupport.firePropertyChange("dbBaseLowSet", oldVal, baseLow);
    }   
   
    public LevelModel getBaseNormal() {
        return baseNormal;
    }

    public void setBaseNormal(LevelModel baseNormal) {
        LevelModel oldVal = this.baseNormal;
        this.baseNormal = baseNormal;
        changeSupport.firePropertyChange("dbBaseNormalSet", oldVal, baseNormal);
    }
   
    public LevelModel getBaseHigh() {
        return baseHigh;
    }

    public void setBaseHigh(LevelModel baseHigh) {
        LevelModel oldVal = this.baseHigh;
        this.baseHigh = baseHigh;
        changeSupport.firePropertyChange("dbBaseHighSet", oldVal, baseHigh);
    }
   
    public Map getAActions() {
        return aActions;
    }
   
    public Map getCActions() {
        return cActions;
    }
   
    public Map getIActions() {
        return iActions;
    }
   
    public ItemTypes getActiveItem() {
        return activeItem;
    }

    public void setActiveItem(ItemTypes activeItem) {
        ItemTypes oldVal = this.activeItem;
        this.activeItem = activeItem;
        changeSupport.firePropertyChange("dbActiveItemSet", oldVal, activeItem);
    }

    public PolicyLevel getActiveLevel() {
        return activeLevel;
    }

    public void setActiveLevel(PolicyLevel activeLevel) {
        PolicyLevel oldVal = this.activeLevel;
        this.activeLevel = activeLevel;
        changeSupport.firePropertyChange("dbActiveLevelSet", oldVal, activeLevel);
    }
   
    public void setCurrentApplication(ApplicationModel currentApplication) {
        ApplicationModel oldVal = this.currentApplication;
        this.currentApplication = currentApplication;
        changeSupport.firePropertyChange("dbCurrentApplicationSet", oldVal, currentApplication);
    }
   
    public ApplicationModel getCurrentApplication() {
        return currentApplication;
    }
   
    public void setCurrentReceiverList(ReceiverListModel currentReceiverList) {
        ReceiverListModel oldVal = this.currentReceiverList;
        this.currentReceiverList = currentReceiverList;
        changeSupport.firePropertyChange("dbCurrentReceiverListSet", oldVal, currentReceiverList);
    }
   
    public ReceiverListModel getCurrentReceiverList() {
        return currentReceiverList;
    }
   
    public void setCurrentPolicy(PolicyModel currentPolicy) {
        PolicyModel oldVal = this.currentPolicy;
        this.currentPolicy = currentPolicy;
        changeSupport.firePropertyChange("dbCurrentPolicySet", oldVal, currentPolicy);
    }
   
    public PolicyModel getCurrentPolicy() {
        return currentPolicy;
    }

    public void setApplications(List<ApplicationModel> applications) {
        List<ApplicationModel> oldVal = this.applications;
        this.applications = applications;
        changeSupport.firePropertyChange("dbApplicationsSet", oldVal, applications);
    }
   
    public List<ApplicationModel> getApplications() {
        return applications;
    }
   
    public boolean addApplication(ApplicationModel application) {
        if(!applications.contains(application)) {
            appKeys.add(application.getId());
            List<ApplicationModel> oldVal = new ArrayList(this.applications);
            applications.add(application);
            changeSupport.firePropertyChange("dbNewApplicationAdded", oldVal, applications);
            return true;
        } else {
            return false;
        }
    }
   
    public boolean removeApplication(ApplicationModel application) {
        if(applications.contains(application)) {
            appKeys.remove(application.getId());
            List<ApplicationModel> oldVal = new ArrayList(this.applications);
            applications.remove(application);
            changeSupport.firePropertyChange("dbApplicationRemoved", oldVal, applications);
            return true;
        } else {
            return false;
        }
    }   

    public void setReceiverLists(List<ReceiverListModel> receiverLists) {
        List<ReceiverListModel> oldVal = this.receiverLists;
        this.receiverLists = receiverLists;
        changeSupport.firePropertyChange("dbReceiverListsSet", oldVal, receiverLists);
    }
   
    public List<ReceiverListModel> getReceiverLists() {
        return receiverLists;
    }
   
    public boolean addReceiverList(ReceiverListModel list) {
        if(!receiverLists.contains(list)) {
            receiverListKeys.add(list.getId());
            List<ReceiverListModel> oldVal = new ArrayList(receiverLists);
            receiverLists.add(list);
            changeSupport.firePropertyChange("dbNewReceiverListAdded", oldVal, receiverLists);
            return true;
        } else {
            return false;
        }
    }
   
    public boolean removeReceiverList(ReceiverListModel list) {
        if(receiverLists.contains(list)) {
            receiverListKeys.remove(list.getId());
            List<ReceiverListModel> oldVal = new ArrayList(receiverLists);
            receiverLists.remove(list);
            changeSupport.firePropertyChange("dbReceiverListRemoved", oldVal, receiverLists);
            return true;
        } else {
            return false;
        }
    }   

    public void setAPolicies(List<PolicyModel> aPolicies) {
        List<PolicyModel> oldVal = this.aPolicies;
        this.aPolicies = aPolicies;
        changeSupport.firePropertyChange("dbPoliciesSet", oldVal, aPolicies);
    }
   
    public List<PolicyModel> getAPolicies() {
        return aPolicies;
    }
   
    public boolean addAPolicy(PolicyModel aPolicy) {
        if(!aPolicies.contains(aPolicy)) {
            policyAKeys.add(aPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(aPolicies);
            aPolicies.add(aPolicy);
            changeSupport.firePropertyChange("dbNewPolicyAdded", oldVal, aPolicies);
            return true;
        } else {
            return false;
        }
    }   
   
    public boolean removeAPolicy(PolicyModel aPolicy) {
        if(aPolicies.contains(aPolicy)) {
            policyAKeys.remove(aPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(aPolicies);
            aPolicies.remove(aPolicy);
            changeSupport.firePropertyChange("dbPolicyRemoved", oldVal, aPolicies);
            return true;
        } else {
            return false;
        }
    }    
   
    public void setCPolicies(List<PolicyModel> cPolicies) {
        List<PolicyModel> oldVal = this.cPolicies;
        this.cPolicies = cPolicies;
        changeSupport.firePropertyChange("dbPoliciesSet", oldVal, cPolicies);
    }
   
    public List<PolicyModel> getCPolicies() {
        return cPolicies;
    }
   
    public boolean addCPolicy(PolicyModel cPolicy) {
        if(!cPolicies.contains(cPolicy)) {
            policyCKeys.add(cPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(cPolicies);
            cPolicies.add(cPolicy);
            changeSupport.firePropertyChange("dbNewPolicyAdded", oldVal, cPolicies);
            return true;
        } else {
            return false;
        }
    }
   
    public boolean removeCPolicy(PolicyModel cPolicy) {
        if(cPolicies.contains(cPolicy)) {
            policyCKeys.remove(cPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(cPolicies);
            cPolicies.remove(cPolicy);
            changeSupport.firePropertyChange("dbPolicyRemoved", oldVal, cPolicies);
            return true;
        } else {
            return false;
        }
    }      
   
    public void setIPolicies(List<PolicyModel> iPolicies) {
        List<PolicyModel> oldVal = this.iPolicies;
        this.iPolicies = iPolicies;
        changeSupport.firePropertyChange("dbPoliciesSet", oldVal, iPolicies);
    }
   
    public List<PolicyModel> getIPolicies() {
        return iPolicies;
    }
   
    public boolean addIPolicy(PolicyModel iPolicy) {
        if(!iPolicies.contains(iPolicy)) {
            policyIKeys.add(iPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(iPolicies);
            iPolicies.add(iPolicy);
            changeSupport.firePropertyChange("dbNewPolicyAdded", oldVal, iPolicies);
            return true;
        } else {
            return false;
        }
    }
   
    public boolean removeIPolicy(PolicyModel iPolicy) {
        if(iPolicies.contains(iPolicy)) {
            policyIKeys.add(iPolicy.getId());
            List<PolicyModel> oldVal = new ArrayList(iPolicies);
            iPolicies.remove(iPolicy);
            changeSupport.firePropertyChange("dbPolicyRemoved", oldVal, iPolicies);
            return true;
        } else {
            return false;
        }
    }      
   
    public int getAppCount() {
        return applications.size();
    }
   
    public int getListCount() {
        return receiverLists.size();
    }
   
    public int getAPolicyCount() {
        return aPolicies.size();
    }
   
    public int getCPolicyCount() {
        return cPolicies.size();
    }
   
    public int getIPolicyCount() {
        return iPolicies.size();
    }
   
    public ChangeListModel getApplicationsAsListModel() {
        ChangeListModel clm = new ChangeListModel();
       
        for(int i=0; i<applications.size(); i++) {
            clm.addElement(applications.get(i));
        }
       
        return clm;
    }
   
    public ChangeListModel getReceiverListsAsListModel() {
        ChangeListModel clm = new ChangeListModel();
       
        for(int i=0; i<receiverLists.size(); i++) {
            clm.addElement(receiverLists.get(i));
        }
       
        return clm;
    }
   
    public ChangeListModel getAPoliciesAsListModel() {
        ChangeListModel clm = new ChangeListModel();
        Collections.sort(aPolicies);
        Collections.reverse(aPolicies);
       
        for(int i=0; i<aPolicies.size(); i++) {
            clm.addElement(aPolicies.get(i));
        }
       
        return clm;
    }
   
    public DefaultComboBoxModel getAPoliciesAsComboModel() {
        DefaultComboBoxModel cbm = new DefaultComboBoxModel();
       
        Collections.sort(aPolicies);
        Collections.reverse(aPolicies);
       
        for(int i=0; i<aPolicies.size(); i++) {
            cbm.addElement(aPolicies.get(i));
        }
       
        return cbm;
    }
   
    public ChangeListModel getCPoliciesAsListModel() {
        ChangeListModel clm = new ChangeListModel();
        Collections.sort(cPolicies);
        Collections.reverse(cPolicies);
       
        for(int i=0; i<cPolicies.size(); i++) {
            clm.addElement(cPolicies.get(i));
        }
       
        return clm;
    }
   
    public DefaultComboBoxModel getCPoliciesAsComboModel() {
        DefaultComboBoxModel cbm = new DefaultComboBoxModel();
       
        Collections.sort(cPolicies);
        Collections.reverse(cPolicies);
       
        for(int i=0; i<cPolicies.size(); i++) {
            cbm.addElement(cPolicies.get(i));
        }
       
        return cbm;
    }   
   
    public ChangeListModel getIPoliciesAsListModel() {
        ChangeListModel clm = new ChangeListModel();
        Collections.sort(iPolicies);
        Collections.reverse(iPolicies);
       
        for(int i=0; i<iPolicies.size(); i++) {
            clm.addElement(iPolicies.get(i));
        }
       
        return clm;
    }
   
    public DefaultComboBoxModel getIPoliciesAsComboModel() {
        DefaultComboBoxModel cbm = new DefaultComboBoxModel();
       
        Collections.sort(iPolicies);
        Collections.reverse(iPolicies);
       
        for(int i=0; i<iPolicies.size(); i++) {
            cbm.addElement(iPolicies.get(i));
        }
       
        return cbm;
    }   
   
    public DefaultComboBoxModel getAlgorithmModel(PolicyLevel level) {
        DefaultComboBoxModel dcm = null;
        if(level == PolicyLevel.A) {
           dcm = new DefaultComboBoxModel(Enums.getAAlgorithms().toArray());
        } else if(level == PolicyLevel.C) {
           dcm = new DefaultComboBoxModel(Enums.getCAlgorithms().toArray());
        } else if(level == PolicyLevel.I) {
           dcm = new DefaultComboBoxModel(Enums.getIAlgorithms().toArray());
       
        return dcm;
    }
   
    public DefaultComboBoxModel getCompatibleModes(Algorithms alg) {
        return new DefaultComboBoxModel(alg.getCompatibleModes().toArray());
    }
   
    public DefaultComboBoxModel getSecurityLevelAsComboBoxModel() {
        DefaultComboBoxModel dcm = new DefaultComboBoxModel(Enums.getSecurityLevels().toArray());
        return dcm;
    }
   

   
   

//    public int getAuthenticationLevel(int appID) {
//        return applications.get(appID).getAlevel();
//    }
//
//    public int getConfidentialityLevel(int appID) {
//        return applications.get(appID).getClevel();
//    }
//
//    public int getIntegrityLevel(int appID) {
//        return applications.get(appID).getIlevel();
//    }
//
//    public int getAuthenticationAlgorithm(int appID) {
//        return 0;
//    }
//
//    public int getConfidentialityAlgorithm(int appID) {
//        return 0;
//    }
//
//    public int getIntegrityAlgorithm(int appID) {
//        return 0;
//    }
}
TOP

Related Classes of de.netsysit.model.DataBaseModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.