/** * Get the the above/below rank role of a given rank association. * @param source The association to get the rank role from. * @param up Indicates whether to get the role moving up or down in rank. * @return the the above/below rank role played by 'source'. */ private AssociationRoleIF getRankRole(AssociationIF source, boolean up) { TopicIF targetRoleType = up ? rankAboveRoleType : rankBelowRoleType; // Get the above/below rank role of the given association. Collection rankRoles = source.getRolesByType(targetRoleType); if (rankRoles.size() > 1) { String nextTo = up ? "above" : "below"; throw new OntopiaRuntimeException("Error in configuration: Every rank" + " association must have exactly one rank-" + nextTo + "-role."); } AssociationRoleIF belowRole = (AssociationRoleIF)rankRoles.iterator() .next(); return belowRole; }
private Collection<AssociationRoleIF> getAssociationRoles(AssociationIF association, TopicIF roleType) { addMixInAnnotations(AssociationRoleIF.class, MAssociationRoleWithoutAssociation.class); if (roleType != null) { return association.getRolesByType(roleType); } else { return association.getRoles(); } }
/** * @return an array with all the associations a given topic map. */ private Object[] getAssociations(TopicMapIF topicmap) { ClassInstanceIndexIF index = (ClassInstanceIndexIF) topicmap .getIndex("net.ontopia.topicmaps.core.index.ClassInstanceIndexIF"); if (index.getTopicTypes().isEmpty()) return topicmap.getAssociations().toArray(); Collection assocs = new ArrayList(topicmap.getAssociations()); Iterator it = index.getTopicTypes().iterator(); while (it.hasNext()) { TopicIF thetype = (TopicIF) it.next(); Iterator it2 = index.getTopics(thetype).iterator(); while (it2.hasNext()) { TopicIF theinstance = (TopicIF) it2.next(); AssociationIF assoc = new FakeAssociation(thetype, theinstance); recordRole(thetype, assoc.getRolesByType(type)); recordRole(theinstance, assoc.getRolesByType(instance)); assocs.add(assoc); } } return assocs.toArray(); }
@Override public Set<Role> getRoles(Topic type) { Check.typeNotNull(type); return topicMap.wrapSet(wrapped.getRolesByType(topicMap.unwrapTopic(type))); }
topic = fieldInput; Collection roles = association.getRolesByType(roleType); if (roles.isEmpty()) builder.makeAssociationRole(association, roleType, topic);
protected Set<TopicIF> fetchChildren(TopicMapIF topicmap, TopicIF topic) { TopicIF parentChildType = TopicMapPreferencesOntology.PARENTCHILD.t(topicmap); TopicIF parentType = TopicMapPreferencesOntology.PARENT.t(topicmap); TopicIF childType = TopicMapPreferencesOntology.CHILD.t(topicmap); TopicIF preferenceType = TopicMapPreferencesOntology.PREFERENCE.t(topicmap); Set<TopicIF> result = new HashSet<TopicIF>(); for (AssociationRoleIF role1 : revitalize(topic, topicmap).getRolesByType(parentType, parentChildType)) { for (AssociationRoleIF role2 : role1.getAssociation().getRolesByType(childType)) { TopicIF child = role2.getPlayer(); if (child.getTypes().contains(preferenceType)) { result.add(child); } } } return result; }
public void testRolesByType() { TopicIF rtype1 = builder.makeTopic(); TopicIF rtype2 = builder.makeTopic(); assertTrue("roles by non-existent type initially not empty", assoc.getRolesByType(rtype1).size() == 0); AssociationRoleIF role = builder.makeAssociationRole(assoc, rtype1, builder.makeTopic()); assertTrue("roles of correct type not found", assoc.getRolesByType(rtype1).size() == 1); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, rtype2, builder.makeTopic()); // builder adds role to assoc assertTrue("role with no type found", assoc.getRolesByType(rtype1).size() == 1); assertTrue("role with no type not found", assoc.getRolesByType(rtype2).size() == 1); }
Collection rolesB = association.getRolesByType(typeB); if (rolesB.isEmpty()) throw new ActionRuntimeException("No role of type " + typeB +