@Override protected void writeAssociation(AssociationIF assoc, ContentHandler dh) throws SAXException { String objid = assoc.getObjectId(); if (alreadyExported.contains(objid)) return; alreadyExported.add(objid); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "association", EMPTY_ATTR_LIST); if (assoc.getType() != null) writeInstanceOf(assoc, dh); if (assoc.getScope().size() > 0) writeScope(assoc.getScope(), dh); if (assoc.getRoles().size() > 0 ) writeMembers(assoc, dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "association"); }
public void remove(AssociationIF association) { association.remove(); }
public static String toString(String impl, AssociationIF assoc) { String id = UNASSIGNED; try { if (assoc.getTopicMap() != null) id = assoc.getObjectId(); return "[" + impl + ", " + id + ", type: " + assoc.getType() + "]"; } catch (Throwable t) { return "[" + impl + ", " + id + "]"; } }
@Override public int compare(Object o1, Object o2) { AssociationIF assoc1 = (AssociationIF) o1; AssociationIF assoc2 = (AssociationIF) o2; int cmp = compareTopic(assoc1.getType(), assoc2.getType()); if (cmp == 0) cmp = collectionComparator.compare(assoc1.getRoles(), assoc2.getRoles()); if (cmp == 0) cmp = compareTopicSet(assoc1.getScope(), assoc2.getScope()); return cmp; } }
private Collection<AssociationRoleIF> getAssociationRoles(AssociationIF association, TopicIF roleType) { addMixInAnnotations(AssociationRoleIF.class, MAssociationRoleWithoutAssociation.class); if (roleType != null) { return association.getRolesByType(roleType); } else { return association.getRoles(); } }
while (it.hasNext()) { AssociationIF assoc = it.next(); if (assoc.getRoles().size() != 2 || !assoc.getScope().isEmpty() || assoc.getReifier() != null) continue; TopicIF insttopic = null; Iterator<AssociationRoleIF> it2 = assoc.getRoles().iterator(); while (it2.hasNext()) { AssociationRoleIF role = it2.next(); assoc.remove();
/** * INTERNAL: Grabs the association roles of the given association * * @param object the given object; AssociationIF * @return object which is a collection of AssociationRoleIF objects */ @Override public Collection<AssociationRoleIF> grab(AssociationIF object) { return object.getRoles(); }
/** * PUBLIC: Merges the source association into the target topic * map. Makes no attempt to verify that the source association is * not already present. * @return The new association in the target topic map. * @since 5.1.3 */ public static AssociationIF mergeInto(TopicMapIF topicmap, AssociationIF source) { TopicMapBuilderIF builder = topicmap.getBuilder(); TopicIF type = findTopic(topicmap, source.getType()); AssociationIF newa = builder.makeAssociation(type); for (TopicIF theme : source.getScope()) newa.addTheme(findTopic(topicmap, theme)); for (AssociationRoleIF role : source.getRoles()) { type = findTopic(topicmap, role.getType()); TopicIF player = findTopic(topicmap, role.getPlayer()); builder.makeAssociationRole(newa, type, player); } return newa; }
@Override public void run(MasterTest mt) { AssociationIF a = (AssociationIF)topicmap.getObjectById(mt.objectId); assertTrue("Added association not found", a != null); if (testInitialProperties) { assertTrue("Source locators is set", a.getItemIdentifiers().isEmpty()); assertTrue("Scope is set", a.getScope().isEmpty()); assertTrue("Type is set", a.getType() == null); assertTrue("Roles is set", a.getRoles().isEmpty()); } } });
private static void copyAssociation(TopicMapIF targettm, AssociationIF source, Map<TopicIF, TopicIF> mergemap, Set<String> assocs) { TopicMapBuilderIF builder = targettm.getBuilder(); AssociationIF target = builder.makeAssociation(resolveTopic(builder.getTopicMap(), source.getType(), mergemap)); copyScope(target, source, mergemap); Iterator<AssociationRoleIF> it = source.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF sourceRole = it.next(); builder.makeAssociationRole(target, resolveTopic(builder.getTopicMap(), sourceRole.getType(), mergemap), resolveTopic(builder.getTopicMap(), sourceRole.getPlayer(), mergemap)); } if (assocs.contains(KeyGenerator.makeAssociationKey(target))) target.remove(); else { copyReifier(target, source, mergemap); copySourceLocators(target, source); } }
retVal = associationRoleTypeComparator.compare(assoc1.getRoles(), assoc2.getRoles()); retVal = associationRolePlayerComparator.compare(assoc1.getRoles(), assoc2.getRoles()); retVal = associationRolesComparator.compare(assoc1.getRoles(), assoc2 .getRoles()); retVal = scopeComparator.compare(filterCollection(assoc1.getScope()), filterCollection(assoc2.getScope())); TopicIF reifier1 = assoc1.getReifier(); Collection<TopicIF> reifiers1 = (reifier1 == null ? Collections.<TopicIF>emptySet() : Collections.singleton(reifier1)); TopicIF reifier2 = assoc2.getReifier(); Collection<TopicIF> reifiers2 = (reifier2 == null ? Collections.<TopicIF>emptySet() : Collections.singleton(reifier2)); reifiers1 = filterCollection(reifiers1);
Iterator itRT = assoc.getRoles().iterator(); while (itRT.hasNext()) assocRoleTypes.add(((AssociationRoleIF) itRT.next()).getType()); max = Integer.MAX_VALUE; TypeSpecification typeSpec = constraint.getTypeSpecification(); Collection types = this.getMatchingTopics(assoc.getTopicMap(), typeSpec); int curNumber = this.getObjectsOfType(assocRoleTypes, types).size();
private void write(AssociationIF association, int number) { AttributesImpl attributes = reifier(association); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_ASSOCIATION, attributes); attributes.clear(); writeType(association); Object[] roles = association.getRoles().toArray(); Arrays.sort(roles, associationRoleComparator); for (int ix = 0; ix < roles.length; ix++) write((AssociationRoleIF) roles[ix], ix + 1); write(association.getScope()); writeLocators(association.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_ASSOCIATION); }
/** * Adds an association to the set of associations. */ protected void addAssociation(AssociationIF association) { // Check to see if association is already a member of this topic map if (association.getTopicMap() == this) return; // Check if used elsewhere. if (association.getTopicMap() != null) throw new ConstraintViolationException("Moving objects is not allowed."); // Notify listeners fireEvent(TopicMapIF.EVENT_ADD_ASSOCIATION, association, null); // Set topic map property ((Association)association).setTopicMap(this); }
protected void writeAssociation(AssociationIF assoc, ContentHandler dh) throws SAXException { Collection roles = filterCollection(assoc.getRoles()); if (roles.isEmpty()) { log.info("Not exporting association " + assoc + " with no roles"); return; // otherwise we're producing invalid XTM (bug #1024) } // Calculate attributes atts.clear(); addId(atts, assoc); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "association", atts); writeInstanceOf(assoc, dh); writeScope(assoc.getScope(), dh); writeMembers(roles, dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "association"); }
/** * Compares two AssociationIFs. */ @Override public int compare(AssociationIF a1, AssociationIF a2) { return ac.compare(a1.getObjectId(), a2.getObjectId()); }
@Override public void run() { AssociationIF a = (AssociationIF)this.data.remove("AssociationIF"); this.objectId = a.getObjectId(); a.remove(); } });
if (existing.getTopicMap() != null) { copySourceLocators(existing, assoc); assoc.remove();