@Override public int hashCode() { if (cachedHashCode != Integer.MIN_VALUE) return cachedHashCode; cachedHashCode = getMetaType().hashCode(); for (String key : getMetaType().keySet()) { Object value = contents.get(key); if (value != null) cachedHashCode += value.hashCode(); } return cachedHashCode; }
/** * Construct Composite Value * * @param compositeMetaType the composite type of the data * @param items map of strings to values * @throws IllegalArgumentException for a null metaType */ public CompositeValueSupport(CompositeMetaType compositeMetaType, Map<String, MetaValue> items) { init(compositeMetaType, items); }
public MetaValue get(String key) { validateKey(key); return contents.get(key); }
@Override public MetaValue createMetaValue(MetaType metaType, SecurityMetaData object) { if(object == null) return null; if(metaType instanceof CompositeMetaType) { // Extract the meta types CompositeMetaType composite = (CompositeMetaType) metaType; EnumMetaType enumMetaType= (EnumMetaType) composite.getType(DeploymentTypeName); // Create the composite value CompositeValueSupport securityDomain = new CompositeValueSupport(composite); // Set a default deplooymentType SecurityDeploymentType deploymentType = object.getSecurityDeploymentType(); if(deploymentType == null) deploymentType = SecurityDeploymentType.NONE; // Set domain and deployment type securityDomain.set(DOMAIN, SimpleValueSupport.wrap(object.getDomain())); securityDomain.set(DeploymentTypeName, new EnumValueSupport(enumMetaType, deploymentType)); // return securityDomain; } throw new IllegalArgumentException("Cannot convert securityDomain " + object); }
@Override public MetaValue createMetaValue(MetaType metaType, ObjectName object) { String[] itemNames = {"domain", "keyPropertyList"}; PropertiesMetaValue keyValues = new PropertiesMetaValue(); for(Object key : object.getKeyPropertyList().keySet()) { Object value = object.getKeyProperty((String)key); keyValues.put(key, value); } MetaValue[] itemValues = {SimpleValueSupport.wrap(object.getDomain()), keyValues}; CompositeValueSupport mv = new CompositeValueSupport(ObjectNameTypeBuilder.META_TYPE, itemNames, itemValues); return mv; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj instanceof CompositeValue == false) return false; CompositeValue other = (CompositeValue) obj; if (getMetaType().equals(other.getMetaType()) == false) return false; for (String key : getMetaType().keySet()) { Object thisValue = this.get(key); Object otherValue = other.get(key); if ((thisValue == null && otherValue == null || thisValue != null && thisValue.equals(otherValue)) == false) return false; } return true; }
return null; CompositeValueSupport result = new CompositeValueSupport(type); mapping.put(value, result); result.set(name, item);
@Override public MetaValue createMetaValue(MetaType metaType, Map<String, ProtocolStackConfigInfo> object) { Map<String, MetaValue> result = new HashMap<String, MetaValue>(); for (Map.Entry<String, ProtocolStackConfigInfo> entry : object.entrySet()) { ProtocolStackConfigInfo info = entry.getValue(); Map<String, MetaValue> stackValue = new HashMap<String, MetaValue>(); stackValue.put("name", SimpleValueSupport.wrap(info.getName())); stackValue.put("description", SimpleValueSupport.wrap(info.getDescription())); ProtocolData[] data = info.getConfiguration(); stackValue.put("configuration", CONFIG_MAPPER.createMetaValue(CONFIG_MAPPER.getMetaType(), data)); result.put(entry.getKey(), new CompositeValueSupport(TYPE, stackValue)); } return new MapCompositeValueSupport(result, TYPE); }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj instanceof CompositeValue == false) return false; CompositeValue other = (CompositeValue) obj; if (getMetaType().equals(other.getMetaType()) == false) return false; for (String key : getMetaType().keySet()) { Object thisValue = this.get(key); Object otherValue = other.get(key); if ((thisValue == null && otherValue == null || thisValue != null && thisValue.equals(otherValue)) == false) return false; } return true; }
CompositeValueSupport result = new CompositeValueSupport(type); mapping.put(value, result); result.set(name, item);
/** * Create a table value * * @param type the type * @param value the value * @param mapping the mapping * @return the table value */ @SuppressWarnings("unchecked") public TableValue createTableValue(TableMetaType type, Map value, Map<Object, MetaValue> mapping) { if (value == null) return null; TableValueSupport table = new TableValueSupport(type); mapping.put(value, table); CompositeMetaType entryType = type.getRowType(); MetaType keyType = entryType.getType(DefaultMetaTypeFactory.MAP_KEY); MetaType valType = entryType.getType(DefaultMetaTypeFactory.MAP_VALUE); for (Iterator<Map.Entry> i = value.entrySet().iterator(); i.hasNext();) { Map.Entry entry = i.next(); MetaValue key = internalCreate(entry.getKey(), null, keyType); MetaValue val = internalCreate(entry.getValue(), null, valType); CompositeValueSupport data = new CompositeValueSupport(entryType, DefaultMetaTypeFactory.MAP_ITEM_NAMES, new MetaValue[] { key, val }); table.put(data); } return table; }
public MetaValue get(String key) { validateKey(key); return contents.get(key); }
@Override public int hashCode() { if (cachedHashCode != Integer.MIN_VALUE) return cachedHashCode; cachedHashCode = getMetaType().hashCode(); for (String key : getMetaType().keySet()) { Object value = contents.get(key); if (value != null) cachedHashCode += value.hashCode(); } return cachedHashCode; }
/** * Construct Composite Value * * @param compositeMetaType the composite type of the data * @param items map of strings to values * @throws IllegalArgumentException for a null metaType */ public CompositeValueSupport(CompositeMetaType compositeMetaType, Map<String, MetaValue> items) { init(compositeMetaType, items); }
/** * Create a table value * * @param type the type * @param value the value * @param mapping the mapping * @return the table value */ @SuppressWarnings("unchecked") public TableValue createTableValue(TableMetaType type, Map value, Map<Object, MetaValue> mapping) { if (value == null) return null; TableValueSupport table = new TableValueSupport(type); mapping.put(value, table); CompositeMetaType entryType = type.getRowType(); MetaType keyType = entryType.getType(DefaultMetaTypeFactory.MAP_KEY); MetaType valType = entryType.getType(DefaultMetaTypeFactory.MAP_VALUE); for (Iterator<Map.Entry> i = value.entrySet().iterator(); i.hasNext();) { Map.Entry entry = i.next(); MetaValue key = internalCreate(entry.getKey(), null, keyType); MetaValue val = internalCreate(entry.getValue(), null, valType); CompositeValueSupport data = new CompositeValueSupport(entryType, DefaultMetaTypeFactory.MAP_ITEM_NAMES, new MetaValue[] { key, val }); table.put(data); } return table; }
public MetaValue[] getAll(String[] keys) { if (keys == null) throw new IllegalArgumentException("Null keys"); MetaValue[] result = new MetaValue[keys.length]; for (int i = 0; i < keys.length; i++) { validateKey(keys[i]); result[i] = contents.get(keys[i]); } return result; }
/** * Validates the key against the composite type * * @param key the key to check * @return the meta type * @throws IllegalArgumentException for a null or empty key or when * the key not a valid item name for the composite type */ private MetaType validateKey(String key) { if (key == null || key.length() == 0) throw new IllegalArgumentException("null or empty key"); CompositeMetaType metaType = getMetaType(); MetaType result = metaType.getType(key); if (result == null) throw new IllegalArgumentException("no such item name " + key + " for composite type " + metaType); return result; }
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { ObjectInputStream.GetField getField = in.readFields(); SortedMap contents = (SortedMap) getField.get("contents", null); CompositeMetaType compositeType = (CompositeMetaType) getField.get("metaType", null); try { init(compositeType, contents); } catch (Exception e) { throw new RuntimeException("Error deserializing composite value", e); } } }
paramValues.put(params[j].getName(), new CompositeValueSupport(PROTOCOL_PARAMETER_TYPE, paramValue));
public MetaValue[] getAll(String[] keys) { if (keys == null) throw new IllegalArgumentException("Null keys"); MetaValue[] result = new MetaValue[keys.length]; for (int i = 0; i < keys.length; i++) { validateKey(keys[i]); result[i] = contents.get(keys[i]); } return result; }