Skip to content

Commit

Permalink
support for parsing annotations of "member.*" or "coord.*"
Browse files Browse the repository at this point in the history
  • Loading branch information
iliasger committed Dec 4, 2015
1 parent 029bf45 commit 1791d7e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ static enum SECURITY_ROLE_LOAD_TYPE { SIMPLE, RECURSIVE }
static final Set<Class<? extends Annotation>> KNOWN_FIELD_ANNOTATIONS = new HashSet<>(
Arrays.asList(Local.class));

public static final String ALL_FIELDS_TOKEN = "ALL_FIELDS_TOKEN";

/**
* Places in the parsing process where the processor's extensions are called.
*/
Expand Down Expand Up @@ -1059,6 +1061,11 @@ Parameter createParameter(Class<?> type, Type genericType, int parameterIndex, A
Annotation directionAnnotation = getKindAnnotation(parameterAnnotations);
parameter.setKind(parameterAnnotationsToParameterKinds.get(directionAnnotation.annotationType()));
String path = getKindAnnotationValue(directionAnnotation);
if (path.equals("member.*")) {
path = "member." + ALL_FIELDS_TOKEN;
} else if (path.equals("coord.*")) {
path = "coord." + ALL_FIELDS_TOKEN;
}
parameter.setKnowledgePath(KnowledgePathHelper.createKnowledgePath(path,pathOrigin));
parameter.setType(type);
parameter.setGenericType(genericType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ public boolean isLocal(KnowledgePath knowledgePath) {
public Collection<KnowledgePath> getLocalPaths() {
return localKnowledgePaths;
}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.knowledge.ReadOnlyKnowledgeManager#getAllPaths()
*/
@Override
public Collection<KnowledgePath> getAllPaths() {
return knowledge.keySet();
}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager#addSecurityTag(cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgePath, cz.cuni.mff.d3s.deeco.model.runtime.api.SecurityTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public ValueSet get(Collection<KnowledgePath> knowledgeReferenceList)
*/
public Collection<KnowledgePath> getLocalPaths();

/**
* Gets all the knowledge paths
* @return the list of knowledge paths
*/
Collection<KnowledgePath> getAllPaths();

/**
* Local knowledge managers are associated with their local components; replica knowledge managers
* are associated with such local component that was used to decrypt the knowledge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper.getAbsoluteStrippedPath;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -10,6 +11,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import cz.cuni.mff.d3s.deeco.annotations.processor.AnnotationProcessor;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManagerContainer;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeNotFoundException;
Expand All @@ -23,10 +25,10 @@
import cz.cuni.mff.d3s.deeco.model.runtime.api.ParameterKind;
import cz.cuni.mff.d3s.deeco.model.runtime.api.SecurityRole;
import cz.cuni.mff.d3s.deeco.model.runtime.api.SecurityTag;
import cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper.KnowledgePathAndRoot;
import cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper;
import cz.cuni.mff.d3s.deeco.task.TaskInvocationException;
import cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper.KnowledgePathAndRoot;
import cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper.PathRoot;
import cz.cuni.mff.d3s.deeco.task.TaskInvocationException;

/**
* Performs security checks before knowledge exchange between two local components.
Expand Down Expand Up @@ -169,9 +171,9 @@ private boolean knowledgePresent(PathRoot localRole, Collection<KnowledgePath> p
}

if (absoluteKnowledgePathAndRoot.root == localRole) {
localPaths.add(absoluteKnowledgePathAndRoot.knowledgePath);
localPaths.addAll(getKnowledgePaths(localKnowledgeManager, absoluteKnowledgePathAndRoot.knowledgePath));
} else {
shadowPaths.add(absoluteKnowledgePathAndRoot.knowledgePath);
shadowPaths.addAll(getKnowledgePaths(shadowKnowledgeManager, absoluteKnowledgePathAndRoot.knowledgePath));
}
}

Expand All @@ -184,6 +186,21 @@ private boolean knowledgePresent(PathRoot localRole, Collection<KnowledgePath> p
}
}

/**
* @param knowledgeManager
* @param knowledgePath
* @return
*/
private Collection<KnowledgePath> getKnowledgePaths(ReadOnlyKnowledgeManager knowledgeManager, KnowledgePath knowledgePath) {
Collection<KnowledgePath> ret = new ArrayList<>();
if (knowledgePath.toString().equals(AnnotationProcessor.ALL_FIELDS_TOKEN)) {
ret.addAll(knowledgeManager.getAllPaths());
} else {
ret.add(knowledgePath);
}
return ret;
}

/**
* Checks whether the local component has role to access the given security tag.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper.getAbsoluteStrippedPath;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -11,6 +12,7 @@
import java.util.Map;
import java.util.Map.Entry;

import cz.cuni.mff.d3s.deeco.annotations.processor.AnnotationProcessor;
import cz.cuni.mff.d3s.deeco.integrity.RatingsManager;
import cz.cuni.mff.d3s.deeco.knowledge.ChangeSet;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
Expand Down Expand Up @@ -272,9 +274,9 @@ private ParameterKnowledgePaths getAllPathsWithRoots(PathRoot localRole, Knowled
private Object[] loadActualParams(PathRoot localRole, KnowledgeManager localKnowledgeManager,
ReadOnlyKnowledgeManager shadowKnowledgeManager, ParameterKnowledgePaths parameters)
throws KnowledgeNotFoundException, TaskInvocationException {
ValueSet localKnowledge = localKnowledgeManager.get(parameters.localInPaths);
ValueSet shadowKnowledge = shadowKnowledgeManager.get(parameters.shadowInPaths);

ValueSet localKnowledge = getKnowledge(localKnowledgeManager, parameters.localInPaths);
ValueSet shadowKnowledge = getKnowledge(shadowKnowledgeManager, parameters.shadowInPaths);

// Construct the parameters for the process method invocation
Object[] actualParams = new Object[parameters.formalParams.size()];
Expand All @@ -289,10 +291,10 @@ private Object[] loadActualParams(PathRoot localRole, KnowledgeManager localKnow

if (paramDir == ParameterKind.IN || paramDir == ParameterKind.INOUT || paramDir == ParameterKind.RATING) {
if (absoluteKnowledgePathAndRoot.root == localRole) {
paramValue = localKnowledge.getValue(absoluteKnowledgePathAndRoot.knowledgePath);
paramValue = getParamValue(localKnowledge, localKnowledgeManager, absoluteKnowledgePathAndRoot.knowledgePath);
knowledgeAuthor = localKnowledgeManager.getAuthor(absoluteKnowledgePathAndRoot.knowledgePath);
} else {
paramValue = shadowKnowledge.getValue(absoluteKnowledgePathAndRoot.knowledgePath);
paramValue = getParamValue(shadowKnowledge, shadowKnowledgeManager, absoluteKnowledgePathAndRoot.knowledgePath);
knowledgeAuthor = shadowKnowledgeManager.getAuthor(absoluteKnowledgePathAndRoot.knowledgePath);
}
}
Expand All @@ -316,6 +318,47 @@ private Object[] loadActualParams(PathRoot localRole, KnowledgeManager localKnow
return actualParams;
}

/**
* @param knowledgeManager
* @param paths
* @return
* @throws KnowledgeNotFoundException
*/
private ValueSet getKnowledge(ReadOnlyKnowledgeManager knowledgeManager,
Collection<KnowledgePath> paths) throws KnowledgeNotFoundException {
Collection<KnowledgePath> allPaths = new ArrayList<>();
for (KnowledgePath p : paths) {
if (p.toString().equals(AnnotationProcessor.ALL_FIELDS_TOKEN)) {
allPaths.addAll(knowledgeManager.getAllPaths());
} else {
allPaths.add(p);
}
}
return knowledgeManager.get(allPaths);
}

/**
* @param knowledge
* @param knowledgeManager
* @param knowledgePath
* @return
*/
private Object getParamValue(ValueSet knowledge, ReadOnlyKnowledgeManager knowledgeManager, KnowledgePath knowledgePath) {
Object ret = null;
if (knowledgePath.toString().equals(AnnotationProcessor.ALL_FIELDS_TOKEN)) {

List<Object> correlationDataValues = new ArrayList<>();
for (KnowledgePath path: knowledgeManager.getAllPaths()) {
correlationDataValues.add(knowledge.getValue(path));

}
ret = correlationDataValues.toArray();
} else {
ret = knowledge.getValue(knowledgePath);
}
return ret;
}

/**
* @param localRole
* @param shadowKnowledgeManager
Expand Down

0 comments on commit 1791d7e

Please sign in to comment.