/** * Set a data object in context, overwriting existing const by id. * * @param id * the id of the const to set and overwrite if exists. * @param rootTagName * the root tag name of the new const to set. * @param c * the new const * @param checkConflict * true to check id conflicts if there is conflict, exception * will be thrown, false not to. * @return the existing data, or null if there isn't existing data with the * id. */ public Object setConst(String id, String rootTagName, Object c, boolean checkConflict) { final Object existing = idConstsMap.put(id, c); if (existing != null && checkConflict) { throw new PaxmlRuntimeException("Id conflict: " + id); } if (null != rootTagName) { idToTagName.put(id, rootTagName); } return existing; }
/** * Set a data object in context, overwriting existing const by id. * * @param id * the id of the const to set and overwrite if exists. * @param rootTagName * the root tag name of the new const to set. * @param c * the new const * @param checkConflict * true to check id conflicts if there is conflict, exception * will be thrown, false not to. * @return the existing data, or null if there isn't existing data with the * id. */ public Object setConst(String id, String rootTagName, Object c, boolean checkConflict) { final Object existing = idConstsMap.put(id, c); if (existing != null && checkConflict) { throw new PaxmlRuntimeException("Id conflict: " + id); } if (null != rootTagName) { idToTagName.put(id, rootTagName); } return existing; }
/** * {@inheritDoc} */ public ObjectTree copy() { ObjectTree newTree = emptyCopy(); for (Map.Entry<String, Object> entry : entrySet()) { Object item = entry.getValue(); if (item instanceof IObjectContainer) { item = ((IObjectContainer) item).copy(); } newTree.put(entry.getKey(), item); } return newTree; } protected ObjectTree emptyCopy() {
/** * {@inheritDoc} */ @Override public ObjectTree copy() { ObjectTree newTree = emptyCopy(); newTree.xmlAttributes.addAll(xmlAttributes); for (Map.Entry<String, Object> entry : entrySet()) { Object item = entry.getValue(); if (item instanceof IObjectContainer) { item = ((IObjectContainer) item).copy(); } newTree.put(entry.getKey(), item); } return newTree; }
@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); } }
@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); } }
public void addValue(String key, Object value) { ObjectTree tree = new ObjectTree(); tree.put(key, checkToCopy(value)); add(tree); }
@Override public void addValue(String key, Object value) { ObjectTree tree = new ObjectTree(key); tree.put(key, checkToCopy(value)); add(tree); }