use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizer method normalizeRepositories.
private static synchronized void normalizeRepositories(ServiceGraph graph) {
logger.debug(LogFormat.indent(1, "repositories"));
for (Entity repository : graph.getChildren(ToscaStructure.REPOSITORIES)) {
logger.debug(LogFormat.indent(2, repository.getId()));
normalize(graph, repository, Repository.URL.name);
}
}
use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method holdsFunction.
/**
* @param entity holds function if entity is a MappingEntity and has a child entity with its name exactly matching
* one of the supported intrinsic function names.
* @return true if given entity holds a tosca intrinsic function, false otherwise
*/
public static boolean holdsFunction(Entity entity) {
if (entity instanceof MappingEntity) {
MappingEntity mappingEntity = (MappingEntity) entity;
Collection<Entity> children = mappingEntity.getChildren();
if (children.size() == 1) {
Entity child = children.iterator().next();
for (ToscaFunction toscaFunction : ToscaFunction.values()) {
if (toscaFunction.name.equals(child.getName())) {
return true;
}
}
}
}
return false;
}
use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method getPropertyOrAttributeTarget.
private static Entity getPropertyOrAttributeTarget(Entity functionEntity, ToscaFunction function) throws AttributeNotSetException {
Collection<Entity> targetAddress = functionEntity.getChildren();
if (targetAddress.size() < 2) {
throw new ToscaTemplateException(String.format("Illegal amount of parameters for function at '%s'", functionEntity.getId()));
}
Iterator<Entity> it = targetAddress.iterator();
Entity targetNode = getTargetNodeEntity(it.next(), functionEntity);
List<Entity> possibleLocations = getPossibleTargetLocations(function.location, targetNode);
if (possibleLocations.isEmpty()) {
return noTargetFound(function, functionEntity);
}
for (Entity possibleLocation : possibleLocations) {
Entity current = findTarget(possibleLocation, it);
if (current != null) {
return current;
}
}
return (noTargetFound(function, functionEntity));
}
use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method findTarget.
private static Entity findTarget(Entity current, Iterator<Entity> it) {
while (it.hasNext()) {
Entity next = it.next();
Optional<Entity> child = current.getChild(((ScalarEntity) next).getValue());
if (child.isPresent()) {
current = child.get();
} else {
return null;
}
}
return current;
}
use of org.opentosca.toscana.core.parse.model.Entity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method getTarget.
private static Entity getTarget(MappingEntity functionHolder) throws AttributeNotSetException {
Entity functionEntity = functionHolder.getChildren().iterator().next();
ToscaFunction function = ToscaFunction.getFunction(functionEntity.getName());
switch(function) {
case GET_INPUT:
return getInputTarget(functionEntity);
case GET_PROPERTY:
case GET_ATTRIBUTE:
return getPropertyOrAttributeTarget(functionEntity, function);
default:
throw new UnsupportedOperationException(String.format("Function %s not supported yet", function));
}
}
Aggregations