@Override Object toNonNullOpenValue(Object value) throws OpenDataException { final Map<Object, Object> valueMap = (Map<Object, Object>) value; if (valueMap instanceof SortedMap) { Comparator comparator = ((SortedMap) valueMap).comparator(); if (comparator != null) { final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator; IllegalArgumentException iae = new IllegalArgumentException(msg); OpenDataException ode = new OpenDataException(msg); ode.initCause(iae); throw ode; } } final TabularType tabularType = (TabularType) getOpenType(); final TabularData table = new TabularDataSupport(tabularType); final CompositeType rowType = tabularType.getRowType(); for (Map.Entry entry : valueMap.entrySet()) { final Object openKey = keyConverter.toOpenValue(entry.getKey()); final Object openValue = valueConverter.toOpenValue(entry.getValue()); final CompositeData row; row = new CompositeDataSupport(rowType, keyValueArray, new Object[] {openKey, openValue}); table.put(row); } return table; }
lraCompData = new CompositeDataSupport(listRegionAttributesCompData, itemValuesHM); } catch (OpenDataException e) { e.printStackTrace(); lraCompData = null;
/** {@inheritDoc} */ @Override Object convertToObject(CompositeType pType, Object pFrom) { // break down the composite type to its field and recurse for converting each field JSONAware value = toJSON(pFrom); if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Conversion of " + value + " to " + pType + " failed because provided JSON type " + value.getClass() + " is not a JSONObject"); } Map<String, Object> givenValues = (JSONObject) value; Map<String, Object> compositeValues = new HashMap<String, Object>(); fillCompositeWithGivenValues(pType, compositeValues, givenValues); completeCompositeValuesWithDefaults(pType, compositeValues); try { return new CompositeDataSupport(pType, compositeValues); } catch (OpenDataException e) { throw new IllegalArgumentException("Internal error: " + e.getMessage(),e); } }
static OpenDataException openDataException(String msg, Throwable cause) { return new OpenDataException(msg); }
throw e; } catch (Exception e) { OpenDataException ode = new OpenDataException(e.getMessage()); ode.setStackTrace(e.getStackTrace()); throw ode;
@Override public Object get() throws OpenDataException { try { if (converter != null) { return converter.toOpenValue(getMethod.invoke(object)); } else { return getMethod.invoke(object); } } catch (IllegalAccessException | InvocationTargetException ex) { OpenDataException thr = new OpenDataException("Cannot get " + getMethod); thr.addSuppressed(ex); throw thr; } }
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e); return;
private TabularData convertToTabularTypeFromMap(TabularType pType, JSONObject pValue) { CompositeType rowType = pType.getRowType(); // A TabularData is requested for mapping a map for the call to an MXBean // as described in http://download.oracle.com/javase/6/docs/api/javax/management/MXBean.html // This means, we will convert a JSONObject to the required format TabularDataSupport tabularData = new TabularDataSupport(pType); @SuppressWarnings("unchecked") Map<String, String> jsonObj = (Map<String,String>) pValue; for(Map.Entry<String, String> entry : jsonObj.entrySet()) { Map<String, Object> map = new HashMap<String, Object>(); map.put("key", getDispatcher().convertToObject(rowType.getType("key"), entry.getKey())); map.put("value", getDispatcher().convertToObject(rowType.getType("value"), entry.getValue())); try { CompositeData compositeData = new CompositeDataSupport(rowType, map); tabularData.put(compositeData); } catch (OpenDataException e) { throw new IllegalArgumentException(e.getMessage(),e); } } return tabularData; }
static void mustBeComparable(Class collection, Type element) throws OpenDataException { if (!(element instanceof Class) || !Comparable.class.isAssignableFrom((Class<?>) element)) { final String msg = "Parameter class " + element + " of " + collection.getName() + " does not implement " + Comparable.class.getName(); throw new OpenDataException(msg); } }
throw e; } catch (Exception e) { OpenDataException ode = new OpenDataException(e.getMessage()); ode.setStackTrace(e.getStackTrace()); throw ode;
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e); return;
public static Object toJSON(Object value) throws OpenDataException { Object result = value; try { ObjectToJsonConverter converter = converters.getToJsonConverter(); result = converter.convertToJson(value, null, JsonConvertOptions.DEFAULT); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { OpenDataException odex = new OpenDataException("Cannot convert value: " + value.getClass().getName()); odex.initCause(ex); throw odex; } return result; }
CompositeData toCompositeData() throws JMRuntimeException { CompositeData result = null; Map<String, Object> items = new HashMap<String, Object>(); items.put(KEY, key); items.put(VALUE, value); try { result = new CompositeDataSupport(HEADER_TYPE, items); } catch (OpenDataException e) { throw new JMRuntimeException("Failed to create CompositeData for header [" + key + ":" + value + "] - " + e.getMessage()); } return result; }
public static CompositeData convert(Object message) throws OpenDataException { OpenTypeFactory f = getFactory(message.getClass()); if (f == null) { throw new OpenDataException("Cannot create a CompositeData for type: " + message.getClass().getName()); } CompositeType ct = f.getCompositeType(); Map<String, Object> fields = f.getFields(message); return new CompositeDataSupport(ct, fields); }
throw e; } catch (Exception e) { OpenDataException ode = new OpenDataException(e.getMessage()); ode.setStackTrace(e.getStackTrace()); throw ode;
@Override public TabularData viewRemoteClusterStatus() { wanInfo.clear(); String[] wan = JMXProperties.getInstance().getProperty(getKey("wanInfo"), "").split(" "); int cnt = 0; while (wan.length >= (cnt + 2)) { try { wanInfo.put(buildWanInfoType(new String(wan[cnt]), Boolean.parseBoolean(wan[cnt + 1]))); } catch (OpenDataException e) { e.printStackTrace(); } cnt += 2; } return (TabularData) wanInfo.clone(); }
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e); return;
public static Object toJSON(Object value) throws OpenDataException { Object result = value; try { ObjectToJsonConverter converter = converters.getToJsonConverter(); result = converter.convertToJson(value, null, JsonConvertOptions.DEFAULT); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { OpenDataException odex = new OpenDataException("Cannot convert value: " + value.getClass().getName()); odex.initCause(ex); throw odex; } return result; }
@Override public CompositeData getProperty(long bundleId, String key) throws IOException { CompositeData result = null; BundleContext bundleContext = assertBundleContext(bundleId); String value = bundleContext.getProperty(key); if (value != null) { String type = value.getClass().getSimpleName(); Map<String, Object> items = new HashMap<String, Object>(); items.put(JmxConstants.KEY, key); items.put(JmxConstants.VALUE, value); items.put(JmxConstants.TYPE, type); try { result = new CompositeDataSupport(JmxConstants.PROPERTY_TYPE, items); } catch (OpenDataException ex) { throw new JMRuntimeException("Failed to create CompositeData for property [" + key + ":" + value + "] - " + ex.getMessage()); } } if (log.isTraceEnabled()) log.trace("getProperty [bundleId=" + bundleId + ",key=" + key + "] => " + result); return result; }
final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName(); throw new OpenDataException(msg); throw new OpenDataException("Can't map " + c.getName() + " to an open data type");