/** * INTERNAL: Grabs the topic playing the role in the given association role * * @param object the given object; AssociationRoleIF * @return object which is the role player; an object implementing TopicIF */ @Override public TopicIF grab(AssociationRoleIF object) { return object.getPlayer(); }
/** * Returns the element id of the player of a given associaiton role. For roles * with no specified player, returns a default string. */ private String lazyPlayerElementId(AssociationRoleIF role) { TopicIF player = role.getPlayer(); if (player == null) return "unspecified:player"; return getElementId(player); }
private boolean arePlayersVisible(AssociationIF association, TopicIF source) { for (Iterator rolesIt = association.getRoles().iterator(); rolesIt.hasNext();) { TopicIF player = ((AssociationRoleIF) rolesIt.next()).getPlayer(); if (player == null) continue; if (!source.equals(player) && configman.isVisible(player)) return true; } return false; }
protected TopicIF getPlayer(AssociationIF assoc, TopicIF roleType) { Iterator<AssociationRoleIF> it = assoc.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); if (roleType.equals(role.getType())) return role.getPlayer(); } return null; }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { AssociationIF assoc = (AssociationIF)object; Iterator<AssociationRoleIF> iter = assoc.getRoles().iterator(); while (iter.hasNext()) { AssociationRoleIF role = iter.next(); TopicIF topic = role.getPlayer(); if (topic != null) topicModified(topic); } } }
protected void writeMembers(AssociationIF assoc, ContentHandler dh) throws SAXException { Iterator iter = assoc.getRoles().iterator(); while (iter.hasNext()){ AssociationRoleIF role = (AssociationRoleIF)iter.next(); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "member", EMPTY_ATTR_LIST); if (role.getType() != null) writeRoleSpec(role.getType(), dh); if (role.getPlayer() != null) writeTopicRef(role.getPlayer(), dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "member"); } }
protected String printAssociationRole(AssociationRoleIF role) { StringBuilder buf = new StringBuilder(); buf.append("<tr><th>Association role player</th><td>" + printTopic(role.getPlayer()) + "</td></tr>\n"); buf.append("<tr><th>Association role type</th><td>" + printTopic(role.getType()) + "</td></tr>\n"); return buf.toString(); }
protected boolean includeAssociation(AssociationIF assoc) { for (AssociationRoleIF role : assoc.getRoles()) if (includeTopic(role.getPlayer())) return true; return false; // not keeping any of the players, so... }
protected boolean includeAssociation(AssociationIF assoc) { for (AssociationRoleIF role : assoc.getRoles()) if (includeTopic(role.getPlayer())) return true; return false; // not keeping any of the players, so... }
@Override public int compare(Object o1, Object o2) { AssociationRoleIF role1 = (AssociationRoleIF) o1; AssociationRoleIF role2 = (AssociationRoleIF) o2; int cmp = compareTopic(role1.getPlayer(), role2.getPlayer()); if (cmp == 0) cmp = compareTopic(role1.getType(), role2.getType()); // No need to compare the parent assocaitions since this comparator only // compares roles within one assocaition. return cmp; } }
/** * PUBLIC: Makes a key for an association role. The key is made up * of the role and the player. * @since 1.2.0 * @param role The association role. * @return The key. */ public static String makeAssociationRoleKey(AssociationRoleIF role) { return makeTypedKey(role) + ":" + role.getPlayer().getObjectId(); }
@Override public int compare(AssociationRoleIF role1, AssociationRoleIF role2) { if (Objects.equals(role1, role2)) return 0; // Compare types int cval2 = compareObjects(role1.getType(), role2.getType(), TopicComparator.getInstance()); if (cval2 != 0) return cval2; // Compare players return compareObjects(role1.getPlayer(), role2.getPlayer(), TopicComparator.getInstance()); } }
/** * PUBLIC: Makes a key for an association role, as it would look in * another topic map. * @since 5.1.3 */ public static String makeAssociationRoleKey(AssociationRoleIF role, TopicMapIF othertm) { TopicIF otherplayer = MergeUtils.findTopic(othertm, role.getPlayer()); return makeTypedKey(role, othertm) + ":" + otherplayer.getObjectId(); }
public void testPlayer() { assertTrue("player null initially", role.getPlayer() != null); TopicIF player = builder.makeTopic(); role.setPlayer(player); assertTrue("player not set properly", role.getPlayer().equals(player)); try { role.setPlayer(null); fail("player could be set to null"); } catch (NullPointerException e) { } assertTrue("player not retained", role.getPlayer().equals(player)); }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { AssociationRoleIF added = (AssociationRoleIF) new_value; // ignore event if player is null TopicIF player = added.getPlayer(); if (player == null) return; // register entry addEntry(new ParameterArray(new Object[] { i(tm), i(player), i(added.getType()) }), added); } }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { AssociationRoleIF removed = (AssociationRoleIF) old_value; // ignore event if player is null TopicIF player = removed.getPlayer(); if (player == null) return; // unregister entry removeEntry(new ParameterArray(new Object[] { i(tm), i(player), i(removed.getType()) }), removed); } }
private void write(AssociationRoleIF role, int number) { AttributesImpl attributes = reifier(role); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_ROLE, attributes); attributes.clear(); startElement("player", topicRef(role.getPlayer())); endElement("player"); writeType(role); writeLocators(role.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_ROLE); }
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); TopicIF player = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Role player is not set" + player, player.equals(r.getPlayer())); assertTrue("Player role is not set", player.getRoles().contains(r)); } });
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); TopicIF player = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Role player is set", r.getPlayer().getSubjectIdentifiers().contains(URILocator.create("player:cleared"))); assertTrue("Player roles is set", player.getRoles().isEmpty()); } });
@Test public void testAssociationRole() throws Exception { AssociationIF assoc = tm1.getBuilder().makeAssociation(tm1.getBuilder().makeTopic()); AssociationRoleIF role = tm1.getBuilder().makeAssociationRole(assoc, foo1, foo1); role.setReifier(foo1); concurrentCommit(); // verify no inconsistenties were created check(tm1, role.getType(), "Association role", "type"); check(tm1, role.getPlayer(), "Association role", "player"); check(tm1, role.getReifier(), "Association role", "reifier"); }