public StatisticsReportingTask(final ConfiguredObject<?> root, final Subject subject) { _root = root; _typeRegistry = root.getModel().getTypeRegistry(); _subject = subject; }
private Set<String> getManagedInterfaces(Class<? extends ConfiguredObject> type, final Model model) { Set<String> interfaces = new HashSet<>(); for (Class<?> classObject : model.getTypeRegistry().getManagedInterfaces(type)) { interfaces.add(classObject.getSimpleName()); } return interfaces; }
private ConfiguredObjectTypeRegistry getTypeRegistry() { return getModel().getTypeRegistry(); }
private String getOnlyValidChildTypeIfKnown(final ConfiguredObject<?> parent, final String category) { if(parent != null) { final Collection<String> validChildTypes = _model.getTypeRegistry().getValidChildTypes(parent.getTypeClass(), category); if (validChildTypes != null && validChildTypes.size() == 1) { return validChildTypes.iterator().next(); } } return null; }
private ConfiguredObjectAttribute<?, ?> getConfiguredObjectAttribute(final String name) { return _configuredObject.getModel() .getTypeRegistry() .getAttributeTypes(_configuredObject.getClass()) .get(name); } }
private String getTypeName(final Class<? extends ConfiguredObject> type, Model model) { return type.getAnnotation(ManagedObject.class).type() == null ? model.getTypeRegistry().getTypeClass(type).getSimpleName() : type.getAnnotation(ManagedObject.class).type(); }
private void validateExchangeDeclareArguments(final Map<String, Object> attributes, final Model model) { final ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry(); final List<ConfiguredObjectAttribute<?, ?>> types = new ArrayList<>(typeRegistry.getAttributeTypes(Exchange.class).values()); typeRegistry.getTypeSpecialisations(Exchange.class).forEach(type -> types.addAll(typeRegistry.getTypeSpecificAttributes(type))); final Set<String> unsupported = attributes.keySet() .stream() .filter(name -> types.stream().noneMatch(a -> Objects.equals(name, a.getName()) && !a.isDerived())) .collect(Collectors.toSet()); if (!unsupported.isEmpty()) { throw new IllegalArgumentException(String.format( "Unsupported exchange declare arguments : %s", String.join(",", unsupported))); } }
private void validateExchangeDeclareArguments(final Map<String, Object> attributes) { final ConfiguredObjectTypeRegistry typeRegistry = getModel().getTypeRegistry(); final List<ConfiguredObjectAttribute<?, ?>> types = new ArrayList<>(typeRegistry.getAttributeTypes(Exchange.class).values()); typeRegistry.getTypeSpecialisations(Exchange.class).forEach(type -> types.addAll(typeRegistry.getTypeSpecificAttributes(type))); final Set<String> unsupported = attributes.keySet() .stream() .filter(name -> types.stream().noneMatch(a -> Objects.equals(name, a.getName()) && !a.isDerived())) .collect(Collectors.toSet()); if (!unsupported.isEmpty()) { throw new IllegalArgumentException(String.format( "Unsupported exchange declare arguments : %s", String.join(",", unsupported))); } }
static String interpolate(Model model, String value) { return Strings.expand(value, false, JSON_SUBSTITUTION_RESOLVER, Strings.JAVA_SYS_PROPS_RESOLVER, Strings.ENV_VARS_RESOLVER, model.getTypeRegistry().getDefaultContextResolver()); }
private Map<String, Map> processCategory(final Class<? extends ConfiguredObject> clazz, final Model model) { Map<String, Map> typeToDataMap = new TreeMap<>(); ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry(); for (Class<? extends ConfiguredObject> type : typeRegistry.getTypeSpecialisations(clazz)) { typeToDataMap.put(ConfiguredObjectTypeRegistry.getType(type), processType(type, model)); } return typeToDataMap; }
private Map<String, Collection<String>> getValidChildTypes(final Class<? extends ConfiguredObject> type, final Model model) { Map<String, Collection<String>> validChildTypes = new HashMap<>(); for (Class<? extends ConfiguredObject> childType : model.getChildTypes(ConfiguredObjectTypeRegistry.getCategory( type))) { Collection<String> validValues = model.getTypeRegistry().getValidChildTypes(type, childType); if (validValues != null) { validChildTypes.put(childType.getSimpleName(), validValues); } } return validChildTypes; }
private Set<Protocol> getPortProtocolsAttribute(Map<String, Object> attributes) { Object object = attributes.get(Port.PROTOCOLS); if (object == null) { return null; } Model model = _parent.getModel(); ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry(); Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(Port.class); ConfiguredSettableAttribute protocolsAttribute = (ConfiguredSettableAttribute) attributeTypes.get(Port.PROTOCOLS); return (Set<Protocol>) protocolsAttribute.convert(object,_parent); }
private Map<String, String> getContextDependencies(final Class<? extends ConfiguredObject> type, final Model model) { final Collection<ManagedContextDefault> contextDependencies = model.getTypeRegistry().getContextDependencies(type); Map<String,String> result = new TreeMap<>(); if(contextDependencies != null) { for(ManagedContextDefault contextDefault : contextDependencies) { result.put(contextDefault.name(), contextDefault.description()); } } return result; }
private void writeStatistics(final PrintWriter writer, final Class<? extends ConfiguredObject> configuredClass, final Model model, final List<Class<? extends ConfiguredObject>> types) { writer.println("<a name=\"types\"><h2>Statistics</h2></a>"); writer.println("<h2>Common Statistics</h2>"); writeStatisticsTable(writer, model.getTypeRegistry().getStatistics(configuredClass)); for(Class<? extends ConfiguredObject> type : types) { String typeName = getTypeName(type, model); Collection<ConfiguredObjectStatistic<?, ?>> typeSpecificStatistics = model.getTypeRegistry().getTypeSpecificStatistics(type); if(!typeSpecificStatistics.isEmpty()) { writer.println("<h2><span class=\"type\">"+typeName+"</span> Specific Statistics</h2>"); writeStatisticsTable(writer, typeSpecificStatistics); } } }
private void writeAttributes(final PrintWriter writer, final Class<? extends ConfiguredObject> configuredClass, final Model model, final List<Class<? extends ConfiguredObject>> types) { writer.println("<a name=\"types\"><h2>Attributes</h2></a>"); writer.println("<h2>Common Attributes</h2>"); writeAttributesTable(writer, model.getTypeRegistry().getAttributeTypes(configuredClass).values()); for(Class<? extends ConfiguredObject> type : types) { String typeName = getTypeName(type, model); Collection<ConfiguredObjectAttribute<?, ?>> typeSpecificAttributes = model.getTypeRegistry().getTypeSpecificAttributes(type); if(!typeSpecificAttributes.isEmpty()) { writer.println("<h2><span class=\"type\">"+typeName+"</span> Specific Attributes</h2>"); writeAttributesTable(writer, typeSpecificAttributes); } } }
private void writeContext(final PrintWriter writer, final Class<? extends ConfiguredObject> configuredClass, final Model model, final List<Class<? extends ConfiguredObject>> types) { writer.println("<a name=\"types\"><h2>Context Variables</h2></a>"); writer.println("<h2>Common Context Variables</h2>"); Collection<ManagedContextDefault> defaultContexts = model.getTypeRegistry().getContextDependencies(configuredClass); writeContextDefaults(writer, defaultContexts); for(Class<? extends ConfiguredObject> type : types) { String typeName = getTypeName(type, model); Collection<ManagedContextDefault> typeSpecificDefaults = model.getTypeRegistry().getTypeSpecificContextDependencies(type); if(!typeSpecificDefaults.isEmpty() && type != configuredClass) { writer.println("<h2><span class=\"type\">"+typeName+"</span> Specific Context Variables</h2>"); writeContextDefaults(writer, typeSpecificDefaults); } } }
public static String getDefaultValue(String attrName) { Model model = SystemConfigBootstrapModel.getInstance(); ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry(); final ConfiguredObjectAttribute<?, ?> attr = typeRegistry.getAttributeTypes(SystemConfig.class).get(attrName); if(attr instanceof ConfiguredSettableAttribute) { return interpolate(model, ((ConfiguredSettableAttribute)attr).defaultValue()); } else { return null; } }
public ConfiguredObjectFinder(final ConfiguredObject<?> root) { _root = root; _model = root.getModel(); final Class<? extends ConfiguredObject> managedCategory = root.getCategoryClass(); addManagedHierarchies(managedCategory, managedCategory); for (ConfiguredObjectOperation operation : _model.getTypeRegistry().getOperations(managedCategory).values()) { if (operation.isAssociateAsIfChildren() && returnsCollectionOfConfiguredObjects(operation)) { Class<? extends ConfiguredObject> associatedChildCategory = (getCollectionMemberType((ParameterizedType) operation.getGenericReturnType())); _associatedChildrenOperations.put(associatedChildCategory, operation); addManagedHierarchies(associatedChildCategory, associatedChildCategory); } } }
static String interpolate(ConfiguredObject<?> object, String value) { if(object == null) { return value; } else { Map<String, String> inheritedContext = new HashMap<String, String>(); generateInheritedContext(object.getModel(), object, inheritedContext); return Strings.expand(value, false, JSON_SUBSTITUTION_RESOLVER, getOwnAttributeResolver(object), getAncestorAttributeResolver(object), new Strings.MapResolver(inheritedContext), Strings.JAVA_SYS_PROPS_RESOLVER, Strings.ENV_VARS_RESOLVER, object.getModel().getTypeRegistry().getDefaultContextResolver()); } }
public NameDependency(final Class<X> clazz, final String attributeName, final String attrValue) { super(clazz, attributeName); _name = attrValue; }