protected List<Entity> parseIntoList(CommitRequest commitRequest, JSONArray nodeList) throws JSONException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IntrospectionException, ParseException { List<Entity> result = new ArrayList<>(nodeList.length()); for (int j = 0; j < nodeList.length(); j++) { JSONObject jsonObject = nodeList.getJSONObject(j); InstanceRef ref = commitRequest.parseInstanceRefAndRegister(jsonObject.getString("id")); MetaClass metaClass = ref.getMetaClass(); Entity instance = ref.getInstance(); asJavaTree(commitRequest, instance, metaClass, jsonObject); result.add(instance); } return result; }
private Object parseEntityReference(Node node, CommitRequest commitRequest) throws InstantiationException, IllegalAccessException, InvocationTargetException, IntrospectionException { Node childNode = node.getFirstChild(); if (ELEMENT_NULL_REF.equals(childNode.getNodeName())) { return null; } InstanceRef ref = commitRequest.parseInstanceRefAndRegister(getIdAttribute(childNode)); return ref.getInstance(); }
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; }
String id = commitInstanceEl.attributeValue("id"); InstanceRef ref = commitRequest.parseInstanceRefAndRegister(id); Entity instance = ref.getInstance(); parseEntity(commitInstanceEl, instance, commitRequest); commitInstances.add(instance); String id = removeInstance.attributeValue("id"); InstanceRef ref = commitRequest.parseInstanceRefAndRegister(id); Entity instance = ref.getInstance(); removeInstances.add(instance);
private List parseNodeList(CommitRequest commitRequest, NodeList entitiesNodeList) throws InstantiationException, IllegalAccessException, InvocationTargetException, IntrospectionException, ParseException { List entities = new ArrayList(entitiesNodeList.getLength()); for (int j = 0; j < entitiesNodeList.getLength(); j++) { Node entityNode = entitiesNodeList.item(j); if (ELEMENT_INSTANCE.equals(entityNode.getNodeName())) { InstanceRef ref = commitRequest.parseInstanceRefAndRegister(getIdAttribute(entityNode)); MetaClass metaClass = ref.getMetaClass(); Object instance = ref.getInstance(); parseEntity(commitRequest, instance, metaClass, entityNode); entities.add(instance); } } return entities; }
childMetaClass = ref.getMetaClass(); child = ref.getInstance(); } else { childMetaClass = property.getRange().asClass(); Entity child = ref.getInstance(); coll.add(child); asJavaTree(commitRequest, child, ref.getMetaClass(), jsonChild);