/** * If this request is for a single attribute, this attribute is returned * by this getter. * @return single attribute * @throws IllegalArgumentException if no or more than one attribute are used when this request was * constructed. */ public String getAttribute() { if (!hasSingleAttribute()) { throw new IllegalArgumentException("More than one attribute given for this request"); } return attributes.get(0); }
/** {@inheritDoc} */ @Override JSONObject toJson() { JSONObject ret = super.toJson(); if (hasSingleAttribute()) { ret.put("attribute",attributes.get(0)); } else if (!hasAllAttributes()) { JSONArray attrs = new JSONArray(); attrs.addAll(attributes); ret.put("attribute",attrs); } if (path != null) { ret.put("path",path); } return ret; }
/** {@inheritDoc} */ @Override List<String> getRequestParts() { if (hasSingleAttribute()) { List<String> ret = super.getRequestParts(); ret.add(getAttribute()); addPath(ret,path); return ret; } else if (hasAllAttributes() && path == null) { return super.getRequestParts(); } // A GET request cant be used for multiple attribute fetching or for fetching // all attributes with a path return null; }
if (request.hasSingleAttribute()) {
/** * Get all attributes obtained. This method can be only used, if the requested MBean * was not a pattern (i.e. the request was for a single MBean). * * @return a list of attributes for this request. If the request was performed for * only a single attribute, the attribute name of the request is returend as * a single valued list. For more than one attribute, the attribute names * a returned from the returned list. */ public Collection<String> getAttributes() { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException( "Attributes can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: return request.getAttributes(); } else { JSONObject attributes = getValue(); return attributes.keySet(); } }