@Override public Set<Class<?>> findSupportingTypes(Component component) { Set<Class<?>> set = new HashSet<>(); try { Class componentType = getTypeRepository().loadClass(component.getType().getType()); if (componentType.isInterface()) { Class type = TypeUtils.findFirstImplementationOfInterface(componentType, getTypeRepository().getAllTypes()); if (type != null) { set.add(type); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + component.getType().getType()); } return set; }
private Set<Class<?>> getReferencedTypesInPackage(String type) { return getTypeRepository() .findReferencedTypes(type) .stream() .filter(this::accepts) .collect(toSet()); }
private boolean accepts(final Class<?> clazz) { final String type = clazz.getCanonicalName(); if (type != null) { for (final String packageName : getTypeRepository().getPackages()) { if (type.startsWith(packageName)) { return true; } } } return false; }
protected Set<Class<?>> findTypesAnnotatedWith(Class<? extends Annotation> annotation) { return TypeUtils.findTypesAnnotatedWith(annotation, getTypeRepository().getAllTypes()); }
/** * Finds the category of a given type. * * @param typeRepository the repository where types should be loaded from * @param typeName the fully qualified type name * @return a TypeCategory object representing the category (e.g. class, interface, enum, etc) */ public static TypeCategory getCategory(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); if (type.isInterface()) { return TypeCategory.INTERFACE; } else if (type.isEnum()) { return TypeCategory.ENUM; } else { if (Modifier.isAbstract(type.getModifiers())) { return TypeCategory.ABSTRACT_CLASS; } else{ return TypeCategory.CLASS; } } } catch (ClassNotFoundException e) { log.warn("Category for type " + typeName + " could not be found."); return null; } }
Set<Class<?>> componentTypes = new HashSet<>(); Set<Class<?>> types = getTypeRepository().getAllTypes(); for (Class<?> type : types) { if (type.isInterface()) {
/** * Finds the visibility of a given type. * * @param typeRepository the repository where types should be loaded from * @param typeName the fully qualified type name * @return a TypeVisibility object representing the visibility (e.g. public, package, etc) */ public static TypeVisibility getVisibility(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); int modifiers = type.getModifiers(); if (Modifier.isPrivate(modifiers)) { return TypeVisibility.PRIVATE; } else if (Modifier.isPublic(modifiers)) { return TypeVisibility.PUBLIC; } else if (Modifier.isProtected(modifiers)) { return TypeVisibility.PROTECTED; } else { return TypeVisibility.PACKAGE; } } catch (ClassNotFoundException e) { log.warn("Visibility for type " + typeName + " could not be found."); return null; } }
@Override protected Set<Component> doFindComponents() { Set<Component> components = new HashSet<>(); Set<Class<?>> types = getTypeRepository().getAllTypes(); for (Class type : types) { for (TypeMatcher typeMatcher : typeMatchers) { if (typeMatcher.matches(type)) { final Container container = getComponentFinder().getContainer(); Component newComponent = addComponent( container, type.getSimpleName(), type.getCanonicalName(), typeMatcher.getDescription(), typeMatcher.getTechnology()); if (newComponent != null) { components.add(newComponent); } } } } return components; }
/** * This will add a description to existing component dependencies, where they have * been annotated @UsesComponent. */ private void findUsesComponentAnnotations(Component component, String typeName) { try { Class type = getTypeRepository().loadClass(typeName); for (Field field : type.getDeclaredFields()) { UsesComponent annotation = field.getAnnotation(UsesComponent.class); if (annotation != null) { String name = field.getType().getCanonicalName(); String description = field.getAnnotation(UsesComponent.class).description(); String technology = annotation.technology(); Component destination = componentFinder.getContainer().getComponentOfType(name); if (destination != null) { for (Relationship relationship : component.getRelationships()) { if (relationship.getDestination() == destination && StringUtils.isNullOrEmpty(relationship.getDescription())) { // only change the details of relationships that have no description component.getModel().modifyRelationship(relationship, description, technology); } } } else { log.warn("A component of type \"" + name + "\" could not be found."); } } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }
private void addEfferentDependencies(Component component, String type, Set<String> typesVisited) { typesVisited.add(type); for (Class<?> referencedType : getTypeRepository().findReferencedTypes(type)) { try { if (!isNestedClass(referencedType)) { String referencedTypeName = referencedType.getCanonicalName(); if (!StringUtils.isNullOrEmpty(referencedTypeName)) { Component destinationComponent = componentFinder.getContainer().getComponentOfType(referencedTypeName); if (destinationComponent != null) { if (component != destinationComponent) { component.uses(destinationComponent, ""); } } else if (!typesVisited.contains(referencedTypeName)) { addEfferentDependencies(component, referencedTypeName, typesVisited); } } } } catch (Throwable t) { log.warn(t); } } }
/** * Finds @UsedByContainer annotations. */ private void findUsedByContainerAnnotations(Component component, String typeName) { try { Class<?> type = getTypeRepository().loadClass(typeName); UsedByContainer[] annotations = type.getAnnotationsByType(UsedByContainer.class); for (UsedByContainer annotation : annotations) { String name = annotation.name(); String description = annotation.description(); String technology = annotation.technology(); Container container = findContainerByNameOrCanonicalName(component, name); if (container != null) { container.uses(component, description, technology); } else { log.warn("A container named \"" + name + "\" could not be found."); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }
/** * Find the @UsesContainer annotations. */ private void findUsesContainerAnnotations(Component component, String typeName) { try { Class<?> type = getTypeRepository().loadClass(typeName); UsesContainer[] annotations = type.getAnnotationsByType(UsesContainer.class); for (UsesContainer annotation : annotations) { String name = annotation.name(); String description = annotation.description(); String technology = annotation.technology(); Container container = findContainerByNameOrCanonicalName(component, name); if (container != null) { component.uses(container, description, technology); } else { log.warn("A container named \"" + name + "\" could not be found."); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }
/** * Find the @UsesSoftwareSystem annotations. */ private void findUsesSoftwareSystemsAnnotations(Component component, String typeName) { try { Class<?> type = getTypeRepository().loadClass(typeName); UsesSoftwareSystem[] annotations = type.getAnnotationsByType(UsesSoftwareSystem.class); for (UsesSoftwareSystem annotation : annotations) { String name = annotation.name(); String description = annotation.description(); String technology = annotation.technology(); SoftwareSystem softwareSystem = component.getModel().getSoftwareSystemWithName(name); if (softwareSystem != null) { component.uses(softwareSystem, description, technology); } else { log.warn("A software system named \"" + name + "\" could not be found."); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }
/** * Finds @UsedByPerson annotations. */ private void findUsedByPersonAnnotations(Component component, String typeName) { try { Class<?> type = getTypeRepository().loadClass(typeName); UsedByPerson[] annotations = type.getAnnotationsByType(UsedByPerson.class); for (UsedByPerson annotation : annotations) { String name = annotation.name(); String description = annotation.description(); String technology = annotation.technology(); Person person = component.getModel().getPersonWithName(name); if (person != null) { person.uses(component, description, technology); } else { log.warn("A person named \"" + name + "\" could not be found."); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }
/** * Finds @UsedBySoftwareSystem annotations. */ private void findUsedBySoftwareSystemAnnotations(Component component, String typeName) { try { Class<?> type = getTypeRepository().loadClass(typeName); UsedBySoftwareSystem[] annotations = type.getAnnotationsByType(UsedBySoftwareSystem.class); for (UsedBySoftwareSystem annotation : annotations) { String name = annotation.name(); String description = annotation.description(); String technology = annotation.technology(); SoftwareSystem softwareSystem = component.getModel().getSoftwareSystemWithName(name); if (softwareSystem != null) { softwareSystem.uses(component, description, technology); } else { log.warn("A software system named \"" + name + "\" could not be found."); } } } catch (ClassNotFoundException e) { log.warn("Could not load type " + typeName); } }