private String debugObjectGraph( final ObjectAdapter object, final int level, final Vector<ObjectAdapter> recursiveElements) { final StringBuffer s = new StringBuffer(); recursiveElements.addElement(object); // work through all its fields final List<ObjectAssociation> fields = object.getSpecification().getAssociations(Contributed.EXCLUDED); for (int i = 0; i < fields.size(); i++) { final ObjectAssociation field = fields.get(i); final Object obj = field.get(object); final String id = field.getId(); indent(s, level); if (field.isOneToManyAssociation()) { s.append( id + ": \n" + debugCollectionGraph((ObjectAdapter) obj, level + 1, recursiveElements)); } else { if (recursiveElements.contains(obj)) { s.append(id + ": " + obj + "*\n"); } else { s.append(id + ": " + obj); s.append(debugGraph((ObjectAdapter) obj, level + 1, recursiveElements)); } } } return s.toString(); }
/** Walking the graph. */ public void resolveField(final ObjectAdapter object, final ObjectAssociation association) { ensureOpened(); ensureInTransaction(); final ObjectAdapter referencedCollectionAdapter = association.get(object); // this code originally brought in from the JPA impl, but seems reasonable. if (association.isOneToManyAssociation()) { ensureThatState(referencedCollectionAdapter, is(notNullValue())); final Object referencedCollection = referencedCollectionAdapter.getObject(); ensureThatState(referencedCollection, is(notNullValue())); // if a proxy collection, then force it to initialize. just 'touching' the object is // sufficient. // REVIEW: I wonder if this is actually needed; does JDO use proxy collections? referencedCollection.hashCode(); } // the JPA impl used to also call its lifecycle listener on the referenced collection object, eg // List, // itself. I don't think this makes sense to do for JDO (the collection is not a // PersistenceCapable). }
private static void specificationFields( final ObjectSpecification specification, final DebugBuilder debugBuilder) { final List<ObjectAssociation> fields = specification.getAssociations(Contributed.EXCLUDED); debugBuilder.appendln("All"); debugBuilder.indent(); for (int i = 0; i < fields.size(); i++) { debugBuilder.appendln((i + 1) + "." + fields.get(i).getId()); } debugBuilder.unindent(); final List<ObjectAssociation> fields2 = specification.getAssociations( Contributed.EXCLUDED, ObjectAssociation.Filters.VISIBLE_AT_LEAST_SOMETIMES); debugBuilder.appendln("Static"); debugBuilder.indent(); for (int i = 0; i < fields2.size(); i++) { debugBuilder.appendln((i + 1) + "." + fields2.get(i).getId()); } debugBuilder.unindent(); debugBuilder.appendln(); try { if (fields.size() == 0) { debugBuilder.appendln("none"); } else { for (int i = 0; i < fields.size(); i++) { final ObjectAssociation field = fields.get(i); debugBuilder.appendln( (i + 1) + "." + field.getId() + " (" + field.getClass().getName() + ")"); debugBuilder.indent(); final String description = field.getDescription(); if (description != null && !description.equals("")) { debugBuilder.appendln("Description", description); } final String help = field.getHelp(); if (help != null && !help.equals("")) { debugBuilder.appendln( "Help", help.substring(0, Math.min(30, help.length())) + (help.length() > 30 ? "..." : "")); } debugBuilder.appendln("ID", field.getIdentifier()); debugBuilder.appendln("Short ID", field.getId()); debugBuilder.appendln("Name", field.getName()); final String type = field.isOneToManyAssociation() ? "Collection" : field.isOneToOneAssociation() ? "Object" : "Unknown"; debugBuilder.appendln("Type", type); final ObjectSpecification fieldSpec = field.getSpecification(); final boolean hasIdentity = !(fieldSpec.isParentedOrFreeCollection() || fieldSpec.isParented() || fieldSpec.isValue()); debugBuilder.appendln("Has identity", hasIdentity); debugBuilder.appendln("Spec", fieldSpec.getFullIdentifier()); debugBuilder.appendln( "Flags", (field.isAlwaysHidden() ? "" : "Visible ") + (field.isNotPersisted() ? "Not Persisted " : " ") + (field.isMandatory() ? "Mandatory " : "")); final Class<? extends Facet>[] facets = field.getFacetTypes(); if (facets.length > 0) { debugBuilder.appendln("Facets"); debugBuilder.indent(); boolean none = true; for (final Class<? extends Facet> facet : facets) { debugBuilder.appendln(field.getFacet(facet).toString()); none = false; } if (none) { debugBuilder.appendln("none"); } debugBuilder.unindent(); } debugBuilder.appendln(field.debugData()); debugBuilder.unindent(); } } } catch (final RuntimeException e) { debugBuilder.appendException(e); } }
private void updateBuild( final View view, final Axes axes, final ObjectAdapter object, final List<ObjectAssociation> flds) { LOG.debug(" as update build"); /* * 1/ To remove fields: look through views and remove any that don't * exists in visible fields * * 2/ From remaining views, check for changes as already being done, and * replace if needed * * 3/ Finally look through fields to see if there is no existing * subview; and add one */ View[] subviews = view.getSubviews(); // remove views for fields that no longer exist outer: for (int i = 0; i < subviews.length; i++) { final FieldContent fieldContent = ((FieldContent) subviews[i].getContent()); for (int j = 0; j < flds.size(); j++) { final ObjectAssociation field = flds.get(j); if (fieldContent.getField() == field) { continue outer; } } view.removeView(subviews[i]); } // update existing fields if needed subviews = view.getSubviews(); for (int i = 0; i < subviews.length; i++) { final View subview = subviews[i]; final ObjectAssociation field = ((FieldContent) subview.getContent()).getField(); final ObjectAdapter value = field.get(object); if (field.isOneToManyAssociation()) { subview.update(value); } else if (field.isOneToOneAssociation()) { final ObjectAdapter existing = subview.getContent().getAdapter(); // if the field is parseable then it may have been modified; we // need to replace what was // typed in with the actual title. if (!field.getSpecification().isParseable()) { final boolean changedValue = value != existing; final boolean isDestroyed = existing != null && existing.isDestroyed(); if (changedValue || isDestroyed) { View fieldView; fieldView = createFieldView(view, axes, object, i, field); if (fieldView != null) { view.replaceView(subview, decorateSubview(axes, fieldView)); } else { view.addView(new FieldErrorView("No field for " + value)); } } } else { if (AdapterUtils.exists(value) && !AdapterUtils.wrappedEqual(value, existing)) { final View fieldView = createFieldView(view, axes, object, i, field); view.replaceView(subview, decorateSubview(axes, fieldView)); } else { subview.refresh(); } } } else { throw new UnknownTypeException(field.getName()); } } // add new fields outer2: for (int j = 0; j < flds.size(); j++) { final ObjectAssociation field = flds.get(j); for (int i = 0; i < subviews.length; i++) { final FieldContent fieldContent = ((FieldContent) subviews[i].getContent()); if (fieldContent.getField() == field) { continue outer2; } } addField(view, axes, object, field, j); } }