public Collection getScope() { return assoc.getScope(); }
public static List<AssociationRoleIF> findRoles(TopicIF aType, TopicIF rType, TopicIF player, Collection<TopicIF> scope) { List<AssociationRoleIF> result = new ArrayList<AssociationRoleIF>(); Iterator<AssociationRoleIF> it = player.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF association = role.getAssociation(); if (Objects.equals(role.getType(), rType) && Objects.equals(association.getType(), aType) && CollectionUtils.equalsUnorderedSet(association.getScope(), scope)) result.add(role); } return result; }
@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 static Collection<TopicIF> findBinaryPlayers(TopicMap tm, TopicIF aType, TopicIF player1, TopicIF rType1, TopicIF rType2, TopicIF theme) { List<TopicIF> result = new ArrayList<TopicIF>(); Iterator<AssociationRoleIF> iter = player1.getRoles().iterator(); while (iter.hasNext()) { AssociationRoleIF role1 = iter.next(); AssociationIF assoc = role1.getAssociation(); Collection<TopicIF> scope = assoc.getScope(); if (!(scope.size() == 1 && scope.contains(theme))) continue; Collection<AssociationRoleIF> roles = assoc.getRoles(); if (roles.size() != 2) continue; if (Objects.equals(role1.getType(), rType1) && Objects.equals(assoc.getType(), aType)) { Iterator<AssociationRoleIF> riter = roles.iterator(); while (riter.hasNext()) { AssociationRoleIF role2 = riter.next(); if (!Objects.equals(role1, role2) && role2.getType().equals(rType2)) { result.add(role2.getPlayer()); } } } } return result; }
@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; } }
public static List<AssociationRoleIF> findRoles(TopicIF aType, TopicIF rType, TopicIF player, Collection<TopicIF> scope) { List<AssociationRoleIF> result = new ArrayList<AssociationRoleIF>(); Iterator<AssociationRoleIF> it = player.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF association = role.getAssociation(); if (ObjectUtils.equals(role.getType(), rType) && ObjectUtils.equals(association.getType(), aType) && CollectionUtils.equalsUnorderedSet(association.getScope(), scope)) result.add(role); } return result; }
public boolean isVisible(AssociationIF assoc) { // Only check the visibility of the association // The visibility of the roles is taken care of in #assertNode() return isAssociationTypeVisible(assoc.getType()) && matchesFilter(assoc.getScope()); }
public static Collection<TopicIF> findBinaryPlayers(TopicMap tm, TopicIF aType, TopicIF player1, TopicIF rType1, TopicIF rType2, TopicIF theme) { List<TopicIF> result = new ArrayList<TopicIF>(); Iterator<AssociationRoleIF> iter = player1.getRoles().iterator(); while (iter.hasNext()) { AssociationRoleIF role1 = iter.next(); AssociationIF assoc = role1.getAssociation(); Collection<TopicIF> scope = assoc.getScope(); if (!(scope.size() == 1 && scope.contains(theme))) continue; Collection<AssociationRoleIF> roles = assoc.getRoles(); if (roles.size() != 2) continue; if (ObjectUtils.equals(role1.getType(), rType1) && ObjectUtils.equals(assoc.getType(), aType)) { Iterator<AssociationRoleIF> riter = roles.iterator(); while (riter.hasNext()) { AssociationRoleIF role2 = riter.next(); if (ObjectUtils.different(role1, role2) && role2.getType().equals(rType2)) { result.add(role2.getPlayer()); } } } } return result; }
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"); }
@Override public void run(MasterTest mt) { AssociationIF a = (AssociationIF)topicmap.getObjectById(mt.objectId); assertTrue("Association theme is set", a.getScope().isEmpty()); } });
Collection associationScope = association.getScope();
@Override public int compare(AssociationIF assoc1, AssociationIF assoc2) { if (Objects.equals(assoc1, assoc2)) return 0; // Compare type int cval1 = compareObjects(assoc1.getType(), assoc2.getType(), TopicComparator.getInstance()); if (cval1 != 0) return cval1; // Compare scope int cval2 = compareCollections(assoc1.getScope(), assoc2.getScope(), TopicComparator.getInstance()); if (cval2 != 0) return cval2; // Compare roles return compareCollections(assoc1.getRoles(), assoc2.getRoles(), AssociationRoleComparator.getInstance()); } }
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); }
AssociationIF assoc = it.next(); if (assoc.getRoles().size() != 2 || !assoc.getScope().isEmpty() || assoc.getReifier() != null) continue;
@Override public void run(MasterTest mt) { AssociationIF a = (AssociationIF)topicmap.getObjectById(mt.objectId); TopicIF theme = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Association theme is not set", a.getScope().contains(theme)); } });
AssociationIF assoc = role.getAssociation(); findPrefixFor(assoc.getType()); findPrefixFor(assoc.getScope());
@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()); } } });
public void testMergeAssociationScopeUse() { try { TopicIF atype = builder1.makeTopic(); TopicIF t1 = builder1.makeTopic(); TopicIF t2 = builder1.makeTopic(); AssociationIF assoc = builder1.makeAssociation(atype); assoc.addTheme(t2); MergeUtils.mergeInto(t1, t2); assertTrue("association scope corrupted", assoc.getScope().size() == 1); assertTrue("association theme replacement not done correctly", assoc.getScope().contains(t1)); } catch (ConstraintViolationException e) { fail("merge of topics unaccountably failed" + e.getMessage()); } }
/** * 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; }