/** * Add a data object with id and tag name for xpath usage. * * @param id * the id of the object * @param rootTagName * the root tag name for xpath usage. * @param c * the data object * @param checkConflict * true to prevent id conflicts, false to overwrite the existing * value with the same id. * */ public void addConst(String id, String rootTagName, Object c, boolean checkConflict) { if (checkConflict && idConstsMap.get(id) != null) { throw new PaxmlRuntimeException("Const with id '" + id + "' already exists!"); } idConstsMap.addValue(id, c); if (null != rootTagName) { idToTagName.put(id, rootTagName); } }
/** * Add a data object with id and tag name for xpath usage. * * @param id * the id of the object * @param rootTagName * the root tag name for xpath usage. * @param c * the data object * @param checkConflict * true to prevent id conflicts, false to overwrite the existing * value with the same id. * */ public void addConst(String id, String rootTagName, Object c, boolean checkConflict) { if (checkConflict && idConstsMap.get(id) != null) { throw new PaxmlRuntimeException("Const with id '" + id + "' already exists!"); } idConstsMap.addValue(id, c); if (null != rootTagName) { idToTagName.put(id, rootTagName); } }
/** * Get a data object with id. * * @param id * the id * @param searchParent * true to search in parent contexts, false not to. * @return null if not found, otherwise the data object. */ public Object getConst(String id, boolean searchParent) { if (idConstsMap.containsKey(id)) { return idConstsMap.get(id); } if (searchParent && parent != null) { return parent.getConst(id, true); } return null; }
/** * Get a data object with id. * * @param id * the id * @param searchParent * true to search in parent contexts, false not to. * @return null if not found, otherwise the data object. */ public Object getConst(String id, boolean searchParent) { if (idConstsMap.containsKey(id)) { return idConstsMap.get(id); } if (searchParent && parent != null) { return parent.getConst(id, true); } return null; }
@Override public void addValue(String key, Object value) { list.add(value); Object existing = get(key); if (existing == null) { // put will do the copying work, if copy-able put(key, value); // getting a copy of it, if copied Object v = get(key); if (v instanceof ObjectList) { ((ObjectList) v)._dynamic = false; } } else if (existing instanceof ObjectList) { ObjectList existingList = ((ObjectList) existing); if (existingList._dynamic) { ObjectList list = (ObjectList) existing; list.add(value); } else { ObjectList list = new ObjectList(key, true, existing, value); put(key, list); } } else { ObjectList list = new ObjectList(key, true, existing, value); put(key, list); } }
@Override public void addValue(String key, Object value) { Object existing = get(key); if (existing == null) { put(key, value); Object v = get(key); if (v instanceof ObjectList) { ((ObjectList) v)._dynamic = false; } } else if (existing instanceof ObjectList) { ObjectList existingList = ((ObjectList) existing); if (existingList._dynamic) { ObjectList list = (ObjectList) existing; list.add(value); } else { ObjectList list = new ObjectList(true, existing, value); put(key, list); } } else { ObjectList list = new ObjectList(true, existing, value); put(key, list); } }