예제 #1
0
 private Object normalizeValue(Topic topic, FieldDefinition fieldDefinition, Object fieldValue) {
   switch (fieldDefinition.getFieldType()) {
     case FieldDefinition.FIELD_TYPE_NAME:
       return ((TopicNameIF) fieldValue).getValue();
     case FieldDefinition.FIELD_TYPE_IDENTITY:
       return ((LocatorIF) fieldValue).getExternalForm();
     case FieldDefinition.FIELD_TYPE_OCCURRENCE:
       return ((OccurrenceIF) fieldValue).getValue();
     case FieldDefinition.FIELD_TYPE_ROLE:
       RoleField roleField = (RoleField) fieldDefinition;
       RoleField.ValueIF value = (RoleField.ValueIF) fieldValue;
       int arity = value.getArity();
       if (arity == 2) {
         for (RoleField rf : value.getRoleFields()) {
           if (!rf.equals(roleField)) {
             Topic valueTopic = value.getPlayer(rf, topic);
             return new OntopolyTopic(session, valueTopic);
           }
         }
         return null;
       } else {
         throw new RuntimeException("N-ary role fields not supported.");
       }
     case FieldDefinition.FIELD_TYPE_QUERY:
       if (fieldValue instanceof Topic) {
         return new OntopolyTopic(session, (Topic) fieldValue);
       } else {
         return fieldValue;
       }
     default:
       throw new RuntimeException("Unknown field type: " + fieldDefinition);
   }
 }
예제 #2
0
  public List<Object> getValues(PrestoField field) {
    FieldDefinition fieldDefinition =
        FieldDefinition.getFieldDefinition(
            session.getTopicById(field.getId()), session.getTopicMap());

    Collection<? extends Object> fieldValues = fieldDefinition.getValues(topic);
    List<Object> result = new ArrayList<Object>(fieldValues.size());
    if (fieldDefinition.getFieldType() == FieldDefinition.FIELD_TYPE_ROLE
        && ((RoleField) fieldDefinition).getAssociationField().getArity() == 1) {
      result.add(!fieldValues.isEmpty());
    } else {
      for (Object value : fieldValues) {
        result.add(normalizeValue(topic, fieldDefinition, value));
      }
    }
    return result;
  }