Commit 6f9c76be authored by Paff's avatar Paff
Browse files

help methods for ast (component and port)

parent 192459bb
package secarc._ast;
import java.util.ArrayList;
import java.util.List;
import mc.umlp.arcd._ast.ASTArcElement;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTArcConnector;
import mc.umlp.arcd._ast.ASTArcSimpleConnector;
/**
* {@link ASTNode} for the respective production in MontiSecArc.mc
......@@ -10,19 +16,308 @@ import mc.umlp.arcd._ast.ASTArcElement;
*
*/
public class ASTSecArcFilterComponent extends PrototypeASTSecArcFilterComponent{
/**
* Lazy calculated trustlevel for component
*/
protected ASTSecArcTrustLevel trustlevel;
/**
* Lazy calculated configuratin for component
*/
protected ASTSecArcConfiguration configuration;
/**
* Lazy calculated cpe for component
*/
protected ASTSecArcCPE cpe;
/**
* Lazy calculated critical ports for component
*/
protected List<ASTArcPort> criticalPorts;
/**
* Lazy calculated roles for component
*/
protected ASTSecArcRole roles;
/**
* Lazy calculated filter for component
*/
protected ASTSecArcFilter filter;
/**
* Lazy calculated encrypted connectors
*/
protected List<ASTArcConnector> encryptedConnectors;
/**
* Lazy calculated encrypted simple connectors
*/
protected List<ASTArcSimpleConnector> encryptedSimpleConnectors;
/**
* Lazy calculated unencrypted connectors
*/
protected List<ASTArcConnector> unencryptedConnectors;
/**
* Lazy calculated unencrypted simple connectors
*/
protected List<ASTArcSimpleConnector> unencryptedSimpleConnectors;
/**
* Lazy calculated pep
*/
protected ASTSecArcPEP pep;
/**
* Lazy calculated trustlevel relations
*/
protected List<ASTSecArcTrustlevelRelation> trustlevelRelations;
/**
* default constructor
*/
public ASTSecArcFilterComponent() {
super();
}
/*
* (non-Javadoc)
* @see mc.umlp.arcd._ast.ASTArcComponent#checkComponentType()
*/
@Override
protected void checkComponentType() {
componentTypeCalculated = false;
super.checkComponentType();
criticalPorts = new ArrayList<ASTArcPort>();
encryptedConnectors = new ArrayList<ASTArcConnector>();
unencryptedConnectors = new ArrayList<ASTArcConnector>();
encryptedSimpleConnectors = new ArrayList<ASTArcSimpleConnector>();
unencryptedSimpleConnectors = new ArrayList<ASTArcSimpleConnector>();
trustlevelRelations = new ArrayList<ASTSecArcTrustlevelRelation>();
//Critical ports from ports
for(ASTArcPort port : this.getPorts()) {
if(((ASTSecArcPort) port).isCritical()) {
criticalPorts.add(port);
}
}
//encrypted connectors and unencrypted connectors from connectors
for(ASTArcConnector connector : this.getConnectors()) {
if(((ASTSecArcConnector) connector).isEncrypted()) {
encryptedConnectors.add(connector);
} else {
unencryptedConnectors.add(connector);
}
}
//encrypted simple connectors and unencrypted simple connectors from simple connectors
for(ASTArcSimpleConnector simpleConnector : this.getSimpleConnectors()) {
if(((ASTSecArcSimpleConnector) simpleConnector).isEncrypted()) {
encryptedSimpleConnectors.add(simpleConnector);
} else {
unencryptedSimpleConnectors.add(simpleConnector);
}
}
for (ASTArcElement elem : getBody().getArcElement()) {
//check for roles
if(elem instanceof ASTSecArcRole) {
roles = (ASTSecArcRole) elem;
}
//check for trustlevelrelations
if(elem instanceof ASTSecArcTrustlevelRelation) {
trustlevelRelations.add((ASTSecArcTrustlevelRelation) elem);
}
//check for configuration
if(elem instanceof ASTSecArcConfiguration) {
configuration = (ASTSecArcConfiguration) elem;
}
//check for cpe
if(elem instanceof ASTSecArcCPE) {
cpe = (ASTSecArcCPE) elem;
}
//check for pep
if(elem instanceof ASTSecArcPEP) {
pep = (ASTSecArcPEP) elem;
}
//check for trustlevel
if(elem instanceof ASTSecArcTrustLevel) {
trustlevel = (ASTSecArcTrustLevel) elem;
}
}
//check for filter
filter = this.getSecArcFilter();
componentTypeCalculated = true;
}
/**
* Returns trustlevel of component
*
* @return
* @return trustlevel
*/
public ASTSecArcTrustLevel getTrustlevel() {
for (ASTArcElement elem : getBody().getArcElement()) {
if(elem instanceof ASTSecArcTrustLevel) {
return (ASTSecArcTrustLevel) elem;
}
if(!componentTypeCalculated) {
checkComponentType();
}
return trustlevel;
}
/**
* Returns configuration for component
*
* @return configuration
*/
public ASTSecArcConfiguration getConfiguration() {
if(!componentTypeCalculated) {
checkComponentType();
}
return configuration;
}
/**
* Returns cpe for component
*
* @return cpe
*/
public ASTSecArcCPE getCPE() {
if(!componentTypeCalculated) {
checkComponentType();
}
return cpe;
}
/**
* Returns critical ports for component
*
* @return critical ports
*/
public List<ASTArcPort> getAllCriticalPorts() {
if (!componentTypeCalculated) {
checkComponentType();
}
return criticalPorts;
}
/**
* Returns roles for component
*
* @return roles
*/
public ASTSecArcRole getAllRoles() {
if(!componentTypeCalculated) {
checkComponentType();
}
return roles;
}
/**
* Returns filter for component
*
* @return filter
*/
public ASTSecArcFilter getFilter() {
if(!componentTypeCalculated) {
checkComponentType();
}
return filter;
}
/**
* Returns encrypted connectors for component
*
* @return encrypted connectors
*/
public List<ASTArcConnector> getAllEncryptedConnectors() {
if(!componentTypeCalculated) {
checkComponentType();
}
return encryptedConnectors;
}
/**
* Returns unencrypted connectors for component
*
* @return unencrypted connectors
*/
public List<ASTArcConnector> getAllUnencryptedConnectors() {
if(!componentTypeCalculated) {
checkComponentType();
}
return unencryptedConnectors;
}
/**
* Returns encrypted simple connectors for component
*
* @return encrypted simple connectors
*/
public List<ASTArcSimpleConnector> getAllEncryptedSimpleConnectors() {
if(!componentTypeCalculated) {
checkComponentType();
}
return encryptedSimpleConnectors;
}
/**
* Returns unencrypted simple connectors for component
*
* @return
*/
public List<ASTArcSimpleConnector> getAllUnencryptedSimpleConnectors() {
if(!componentTypeCalculated) {
checkComponentType();
}
return unencryptedSimpleConnectors;
}
/**
* Returns pep for component
*
* @return pep
*/
public ASTSecArcPEP getPEP() {
if(!componentTypeCalculated) {
checkComponentType();
}
return pep;
}
/**
* Returns trustlevel relations for component
*
* @return trustlevel relations
*/
public List<ASTSecArcTrustlevelRelation> getAllTrustlevelRelation() {
if(!componentTypeCalculated) {
checkComponentType();
}
return null;
return trustlevelRelations;
}
}
......@@ -4,6 +4,11 @@
package secarc._ast;
import java.util.ArrayList;
import java.util.List;
import mc.umlp.arcd._ast.ASTArcElement;
import de.se_rwth.commons.Names;
/**
......@@ -13,7 +18,17 @@ import de.se_rwth.commons.Names;
* @version $Revision$, $Date$
*/
public class ASTSecArcPort extends PrototypeASTSecArcPort {
/**
* Flags, if lazy informations have been calculated.
*/
protected boolean componentTypeCalculated;
/**
* Lazy calculated roles
*/
protected List<String> roles;
/**
* The package name of this port, that is, the package name of the parent
* component of this port.
......@@ -48,4 +63,41 @@ public class ASTSecArcPort extends PrototypeASTSecArcPort {
return this.simpleTypeName;
}
/**
* calculates the role type and collects ArcElements in their specific
* typed lists.
*/
protected void checkComponentType() {
componentTypeCalculated = false;
roles = new ArrayList<String>();
for (ASTArcElement elem : getMainParent().getBody().getArcElement()) {
if(elem instanceof ASTSecArcRoleInterface) {
ASTSecArcRefRoleList refRole = ((ASTSecArcRoleInterface) elem).getSecArcRefRole();
for(ASTSecArcRefRole role : refRole.getList()) {
if(role.getPortName().equals(getName())) {
roles.addAll(role.getRoles());
}
}
}
}
componentTypeCalculated = true;
}
/**
* Returns roles for port
*
* @return roles
*/
public List<String> getRoles() {
if(!componentTypeCalculated) {
checkComponentType();
}
return roles;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment