StringBuilder sb = new StringBuilder(); for(Object c: td.values()) { sb.append(formatLine(c, td.getTabularType().getRowType().getClassName())); sb.append(",");
td.getTabularType().getIndexNames(); List<String> header = new ArrayList<String>(td.getTabularType().getIndexNames()); for(String f: td.getTabularType().getRowType().keySet()) { if (!header.contains(f)) { header.add(f);
td.getTabularType().getIndexNames(); List<String> header = new ArrayList<String>(td.getTabularType().getIndexNames()); for(String f: td.getTabularType().getRowType().keySet()) { if (!header.contains(f)) { header.add(f);
private Object convertFromTabularData(TabularData data) { if (data.getTabularType().isArray()) {
private CompositeData extractCompositeDataFromPath(TabularData pTd, Stack<String> pPathStack) throws AttributeNotFoundException { // We first try it as a key TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); checkPathFitsIndexNames(pPathStack, indexNames); Object keys[] = new Object[indexNames.size()]; CompositeType rowType = type.getRowType(); List<String> pathPartsUsed = new ArrayList<String>(); for (int i = 0; i < indexNames.size(); i++) { String path = pPathStack.pop(); pathPartsUsed.add(path); keys[i] = getKey(rowType, indexNames.get(i), path); } if (pTd.containsKey(keys)) { return pTd.get(keys); } else { throw new AttributeNotFoundException("No entry with " + pathPartsUsed + " found"); } }
private Object convertTabularDataToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { TabularType type = pTd.getTabularType(); if (hasComplexKeys(type)) { return convertTabularDataDirectly(pTd, pExtraArgs, pConverter); } else { return convertToMaps(pTd, pExtraArgs, pConverter); } }
private Object convertTabularDataDirectly(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { if (!pExtraArgs.empty()) { throw new IllegalArgumentException("Cannot use a path for converting tabular data with complex keys (" + pTd.getTabularType().getRowType() + ")"); } JSONObject ret = new JSONObject(); JSONArray indexNames = new JSONArray(); TabularType type = pTd.getTabularType(); for (String index : type.getIndexNames()) { indexNames.add(index); } ret.put("indexNames",indexNames); JSONArray values = new JSONArray(); // Here no special handling for wildcard pathes since pathes are not supported for this use case (yet) for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { values.add(pConverter.extractObject(cd, pExtraArgs, true)); } ret.put("values",values); return ret; }
private Object convertToMaps(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); boolean found = false; for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { Stack<String> path = (Stack<String>) pExtraArgs.clone(); try { JSONObject targetJSONObject = ret; // TODO: Check whether all keys can be represented as simple types. If not, well // we dont do any magic and return the tabular data as an array. for (int i = 0; i < indexNames.size() - 1; i++) { Object indexValue = pConverter.extractObject(cd.get(indexNames.get(i)), null, true); targetJSONObject = getNextMap(targetJSONObject, indexValue); } Object row = pConverter.extractObject(cd, path, true); String finalIndex = indexNames.get(indexNames.size() - 1); Object finalIndexValue = pConverter.extractObject(cd.get(finalIndex), null, true); targetJSONObject.put(finalIndexValue, row); found = true; } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignoring filtered attributes } } if (!pTd.isEmpty() && !found) { throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
cd != null && checkForMxBeanMap(td.getTabularType()) ? cd.get("value") : cd, pPathParts, pJsonify); } catch (AttributeNotFoundException exp) { return checkForMxBeanMap(td.getTabularType()) ? convertMxBeanMapToJson(td,pPathParts,pConverter) : convertTabularDataToJson(td, pPathParts, pConverter);
TabularType tt = tds.getTabularType();
private static MBeanDump.MBeanValue getTabularDataValue(TabularData tabularData) { Set<String> attributeNames = tabularData.getTabularType().getRowType().keySet(); for (Object key : tabularData.keySet()) {
private static String tabularToString(TabularData tabularData) { TabularType type = tabularData.getTabularType(); StringBuilder b = new StringBuilder(); b.append("(").append(type.getTypeName()).append(")\n"); Collection<CompositeData> values = (Collection) tabularData.values(); for (CompositeData cd: values) { b.append(compositeToString(cd)); } return b.toString(); }
public String stringify(Object o) { final StringBuffer buf = new StringBuffer(); buf.append("Tabular data:\n"); final TabularData data = (TabularData) o; final TabularType type = data.getTabularType(); int rowIndex = 0; for( final Object temp : data.values() ) { final CompositeData item = (CompositeData)temp; final String s = CompositeDataStringifier.DEFAULT.stringify(item); // emit the row index followed by the row buf.append("[" + rowIndex + "] "); buf.append(s + "\n"); ++rowIndex; } return (buf.toString()); }
private CompositeData extractCompositeDataFromPath(TabularData pTd, Stack<String> pPathStack) throws AttributeNotFoundException { // We first try it as a key TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); checkPathFitsIndexNames(pPathStack, indexNames); Object keys[] = new Object[indexNames.size()]; CompositeType rowType = type.getRowType(); List<String> pathPartsUsed = new ArrayList<String>(); for (int i = 0; i < indexNames.size(); i++) { String path = pPathStack.pop(); pathPartsUsed.add(path); keys[i] = getKey(rowType, indexNames.get(i), path); } if (pTd.containsKey(keys)) { return pTd.get(keys); } else { throw new AttributeNotFoundException("No entry with " + pathPartsUsed + " found"); } }
private Object convertTabularDataToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { TabularType type = pTd.getTabularType(); if (hasComplexKeys(type)) { return convertTabularDataDirectly(pTd, pExtraArgs, pConverter); } else { return convertToMaps(pTd, pExtraArgs, pConverter); } }
private Object convertTabularDataToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { TabularType type = pTd.getTabularType(); if (hasComplexKeys(type)) { return convertTabularDataDirectly(pTd, pExtraArgs, pConverter); } else { return convertToMaps(pTd, pExtraArgs, pConverter); } }
private Object convertTabularDataToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { TabularType type = pTd.getTabularType(); if (hasComplexKeys(type)) { return convertTabularDataDirectly(pTd, pExtraArgs, pConverter); } else { return convertToMaps(pTd, pExtraArgs, pConverter); } }
@Override public Object getValue(final Object value) { final TabularData table = (TabularData) value; for (final Object rowData : table.values()) { final CompositeData row = (CompositeData) rowData; final RowPathSegment rowSegment = RowPathSegment.fromRow(table.getTabularType(), row); if (this.equals(rowSegment)) { return row; } } // row not found! return null; } }
@Override public Object getValue(final Object value) { final TabularData table = (TabularData) value; for (final Object rowData : table.values()) { final CompositeData row = (CompositeData) rowData; final RowPathSegment rowSegment = RowPathSegment.fromRow(table.getTabularType(), row); if (this.equals(rowSegment)) { return row; } } // row not found! return null; } }
static ObjectNode serialize(final TabularData src) { final ObjectNode result = ThreadLocalJsonFactory.getFactory().objectNode(); result.put(TYPE_FIELD, OpenTypeFormatter.serialize(src.getTabularType())); result.put(ROWS_FIELDS, serializeRows(src)); return result; } }