use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ApiDocsServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws ServletException, IOException {
ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
final Class<? extends ConfiguredObject> configuredClass;
final Class<? extends ConfiguredObject>[] hierarchy;
final String[] servletPathParts = request.getServletPath().split("/");
final Model model = managedObject.getModel();
if (servletPathParts.length < 4) {
configuredClass = null;
hierarchy = null;
} else {
configuredClass = getConfiguredClass(request, managedObject);
if (configuredClass == null) {
sendError(response, HttpServletResponse.SC_NOT_FOUND);
return;
}
hierarchy = finder.getHierarchy(configuredClass);
if (hierarchy == null) {
sendError(response, HttpServletResponse.SC_NOT_FOUND);
return;
}
if (!_typeSpecialisations.containsKey(configuredClass)) {
List<Class<? extends ConfiguredObject>> types = new ArrayList<>(model.getTypeRegistry().getTypeSpecialisations(configuredClass));
_typeSpecialisations.putIfAbsent(configuredClass, types);
}
}
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = response.getWriter();
writePreamble(writer);
writeHead(writer, hierarchy, configuredClass);
if (hierarchy == null) {
writer.println("<table class=\"api\">");
writer.println("<thead>");
writer.println("<tr>");
writer.println("<th class=\"type\">Type</th>");
writer.println("<th class=\"path\">Path</th>");
writer.println("<th class=\"description\">Description</th>");
writer.println("</tr>");
writer.println("</thead>");
writer.println("<tbody>");
SortedSet<Class<? extends ConfiguredObject>> managedCategories = new TreeSet<>(CLASS_COMPARATOR);
managedCategories.addAll(finder.getManagedCategories());
String pathStem = "/" + servletPathParts[1] + "/" + (servletPathParts.length == 2 ? "latest" : servletPathParts[2]) + "/";
for (Class<? extends ConfiguredObject> category : managedCategories) {
Class<? extends ConfiguredObject> objClass = category;
String path = pathStem + category.getSimpleName().toLowerCase();
writer.println("<tr>");
writer.println("<td class=\"type\"><a href=" + ((servletPathParts.length == 2) ? "\"latest/" : "") + objClass.getSimpleName().toLowerCase() + "\">" + objClass.getSimpleName() + "</a></td>");
writer.println("<td class=\"path\">" + path + "</td>");
writer.println("<td class=\"description\">" + objClass.getAnnotation(ManagedObject.class).description() + "</td>");
writer.println("</tr>");
}
writer.println("</tbody>");
writer.println("</table>");
} else {
final List<Class<? extends ConfiguredObject>> types = _typeSpecialisations.get(configuredClass);
writeCategoryDescription(writer, configuredClass);
writeUsage(writer, request, hierarchy, configuredClass);
writeTypes(writer, model, types);
writeAttributes(writer, configuredClass, model, types);
writeStatistics(writer, configuredClass, model, types);
writeOperations(writer, configuredClass, model, types);
writeContext(writer, configuredClass, model, types);
}
writeFoot(writer);
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class BrokerQueryServlet method getAllObjects.
@Override
protected List<ConfiguredObject<?>> getAllObjects(final Broker<?> broker, final Class<? extends ConfiguredObject> category, final HttpServletRequest request) {
if (category == Broker.class) {
return Collections.<ConfiguredObject<?>>singletonList(broker);
} else {
final Model brokerModel = broker.getModel();
List<Class<? extends ConfiguredObject>> hierarchy = new ArrayList<>();
Class<? extends ConfiguredObject> element = category;
while (element != null && element != Broker.class) {
hierarchy.add(element);
Class<? extends ConfiguredObject> parentType = brokerModel.getParentType(element);
if (parentType == null) {
break;
} else {
element = parentType;
}
}
Collections.reverse(hierarchy);
Collection<ConfiguredObject<?>> parents = Collections.<ConfiguredObject<?>>singletonList(broker);
Collection<ConfiguredObject<?>> children = Collections.emptyList();
for (Class<? extends ConfiguredObject> childClass : hierarchy) {
children = new HashSet<>();
for (ConfiguredObject<?> parent : parents) {
children.addAll((Collection<? extends ConfiguredObject<?>>) parent.getChildren(childClass));
}
parents = children;
}
return new ArrayList<>(children);
}
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectToMapConverter method incorporateChildrenIntoMap.
private void incorporateChildrenIntoMap(final ConfiguredObject confObject, Class<? extends ConfiguredObject> clazz, Map<String, Object> object, ConverterOptions converterOptions) {
List<Class<? extends ConfiguredObject>> childTypes = new ArrayList<>(confObject.getModel().getChildTypes(clazz));
Collections.sort(childTypes, new Comparator<Class<? extends ConfiguredObject>>() {
@Override
public int compare(final Class<? extends ConfiguredObject> o1, final Class<? extends ConfiguredObject> o2) {
return o1.getSimpleName().compareTo(o2.getSimpleName());
}
});
ConverterOptions childConverterOptions = new ConverterOptions(converterOptions, converterOptions.getDepth() - 1);
for (Class<? extends ConfiguredObject> childClass : childTypes) {
Collection children = confObject.getChildren(childClass);
if (children != null) {
List<? extends ConfiguredObject> sortedChildren = new ArrayList<ConfiguredObject>(children);
if (Comparable.class.isAssignableFrom(childClass)) {
Collections.sort((List) sortedChildren);
} else {
Collections.sort(sortedChildren, new Comparator<ConfiguredObject>() {
@Override
public int compare(final ConfiguredObject o1, final ConfiguredObject o2) {
return o1.getName().compareTo(o2.getName());
}
});
}
List<Map<String, Object>> childObjects = new ArrayList<>();
for (ConfiguredObject child : sortedChildren) {
childObjects.add(convertObjectToMap(child, childClass, childConverterOptions));
}
if (!childObjects.isEmpty()) {
String childTypeSingular = childClass.getSimpleName().toLowerCase();
object.put(childTypeSingular + (childTypeSingular.endsWith("s") ? "es" : "s"), childObjects);
}
}
}
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectToMapConverter method collectInheritedActualContext.
private void collectInheritedActualContext(ConfiguredObject<?> confObject, Map<String, Object> contextValues) {
ConfiguredObject parent = confObject.getParent();
if (parent != null) {
collectInheritedActualContext(parent, contextValues);
}
Object value = confObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
if (value instanceof Map) {
contextValues.putAll((Map<String, Object>) value);
}
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class MetaDataServlet method processOperations.
private Map<String, Map> processOperations(final Class<? extends ConfiguredObject> type, final Model model) {
Collection<ConfiguredObjectOperation<?>> operations = model.getTypeRegistry().getOperations(type).values();
Map<String, Map> attributeDetails = new LinkedHashMap<>();
for (ConfiguredObjectOperation<?> operation : operations) {
Map<String, Object> attrDetails = new LinkedHashMap<>();
attrDetails.put("name", operation.getName());
attrDetails.put("returnType", operation.getReturnType().getSimpleName());
if (!"".equals(operation.getDescription())) {
attrDetails.put("description", operation.getDescription());
}
List<OperationParameter> parameters = operation.getParameters();
if (!parameters.isEmpty()) {
Map<String, Map> paramDetails = new LinkedHashMap<>();
for (OperationParameter param : parameters) {
Map<String, Object> paramAttrs = new LinkedHashMap<>();
paramAttrs.put("type", param.getType().getSimpleName());
paramAttrs.put("mandatory", param.isMandatory());
if (!"".equals(param.getDefaultValue())) {
paramAttrs.put("defaultValue", param.getDefaultValue());
}
paramDetails.put(param.getName(), paramAttrs);
}
attrDetails.put("parameters", paramDetails);
}
attributeDetails.put(operation.getName(), attrDetails);
}
return attributeDetails;
}
Aggregations