public InstanceRef parseInstanceRefAndRegister(String fullId) throws InstantiationException, IllegalAccessException { EntityLoadInfo loadInfo; if (!fullId.startsWith("NEW-")) { loadInfo = EntityLoadInfo.parse(fullId); if (loadInfo == null) { throw new RuntimeException("Cannot parse id: " + fullId); } InstanceRef existingRef = instanceRefs.get(loadInfo.getMetaClass().getName() + "-" + loadInfo.getId().toString()); if (existingRef != null) { return existingRef; } } else { int idDashIndex = StringUtils.ordinalIndexOf(fullId, "-", 2); if (idDashIndex == -1) { String entityName = fullId.substring("NEW-".length()); String generatedId = generateId(entityName); fullId = fullId + "-" + generatedId; } loadInfo = EntityLoadInfo.parse(fullId); if (loadInfo == null) { throw new RuntimeException("Cannot parse id: " + fullId); } } if (loadInfo.isNewEntity()) newInstanceIds.add(loadInfo.toString()); InstanceRef result = new InstanceRef(loadInfo); instanceRefs.put(loadInfo.getMetaClass().getName() + "-" + loadInfo.getId().toString(), result); return result; }