private NamedDescription findNamedDescription(String name, List<NamedDescription> namedDescriptions) { for (NamedDescription nd : namedDescriptions) { if (name.equals(nd.getName())) return nd; } return null; } }
/** * Result of a successful read-resource operation. * * @param description description of the result of a read-resource operation. * @param childNames the children (if any) of the managed resource. * */ public ReadResourceModel(String description, Set<String> childNames) { if (description == null) throw new IllegalArgumentException("description was null"); if (childNames == null) throw new IllegalArgumentException("childNames was null"); this.description = description; this.children = new ArrayList<NamedDescription>(childNames.size()); for (String childName : childNames) { // Core implementation will add the descriptions after so 'dynamic' extensions don't have to. children.add(new NamedDescription(childName, null)); } childDescriptionsSet = false; }
public void setChildDescription(String name, String description) { NamedDescription found = findNamedDescription(name, children); if (found != null) { found.setDescription(description); childDescriptionsSet = true; } }
for (NamedDescription operationDescribed : readResource.getOperations()) Operation operation = new Operation(operationDescribed.getName(), operationDescribed.getDescription(), null); operations.add(operation); if (operationDescribed.getName().equals(OperationNames.READ_RESOURCE)) else if (operationDescribed.getName().equals(OperationNames.EXPORT_RESOURCE)) else if (operationDescribed.getName().equals(OperationNames.IMPORT_RESOURCE)) .rel("operation").replaceQueryParam("op", operationDescribed.getName()).build(); for (NamedDescription childDescribed : readResource.getChildDescriptions()) Link link = new LinkBuilder(uriBuilder).rel("child").path(childDescribed.getName()).build(); children.add(new Child(childDescribed.getName(), childDescribed.getDescription(), link));
if (nd != null) json.key("description").value(nd.getDescription()); for (NamedDescription nd : model.getOperations()) json.object().key("operation-name").value(nd.getName()).key("operation-description").value(nd.getDescription()).endObject();
public Set<String> getChildren() { Set<String> childNames = new LinkedHashSet<String>(children.size()); for (NamedDescription nd : children) { childNames.add(nd.getName()); } return Collections.unmodifiableSet(childNames); }
@Override public ReadResourceModel execute(OperationContext operationContext) { ManagedResource resource = operationContext.getManagedResource(); PathAddress address = operationContext.getAddress(); Set<String> children = resource.getSubResourceNames(address); ReadResourceModel readResourceModel = new ReadResourceModel("Available operations and children (sub-resources).", children); // Set children descriptions for (String child : children) { ManagedDescription desc = resource.getResourceDescription(address.append(child)); readResourceModel.setChildDescription(child, desc.getDescription()); } // Set operation descriptions Map<String, ManagedDescription> descriptions = resource.getOperationDescriptions(address); for (Map.Entry<String, ManagedDescription> desc : descriptions.entrySet()) { readResourceModel.addOperation(new NamedDescription(desc.getKey(), desc.getValue().getDescription())); } return readResourceModel; }
for (Map.Entry<String, ManagedDescription> desc : descriptions.entrySet()) readResource.addOperation(new NamedDescription(desc.getKey(), desc.getValue().getDescription()));