@SuppressWarnings("unchecked")
 private Object createDefaultValue(RDFProperty property) {
   for (Iterator<AnnotationsWidgetPlugin> it = TriplesComponent.plugins(); it.hasNext(); ) {
     AnnotationsWidgetPlugin plugin = it.next();
     if (plugin.canEdit(subject, property, null)) {
       Object defaultValue = plugin.createDefaultValue(subject, property);
       if (defaultValue != null) {
         return defaultValue;
       }
     }
   }
   RDFResource range = property.getRange();
   if (range instanceof RDFSDatatype) {
     return ((RDFSDatatype) range).getDefaultValue();
   } else if (range instanceof OWLDataRange) {
     OWLDataRange dataRange = (OWLDataRange) range;
     RDFList oneOf = dataRange.getOneOf();
     Object firstValue = null;
     if (oneOf != null) {
       Collection values = oneOf.getValues();
       if (!values.isEmpty()) {
         firstValue = values.iterator().next();
       }
     }
     return firstValue;
   } else if (property instanceof OWLObjectProperty) {
     return null;
   } else {
     return "";
   }
 }
Beispiel #2
0
 public List getValues() {
   List result = new ArrayList();
   RDFList l = this;
   while (l != null && l.getFirst() != null) {
     result.add(l.getFirst());
     l = l.getRest();
   }
   return result;
 }
Beispiel #3
0
 public boolean isClosed() {
   RDFList rest = getRest();
   if (rest == null) {
     return false;
   } else if (rest.equals(getOWLModel().getRDFNil())) {
     return true;
   } else {
     return rest.isClosed();
   }
 }
Beispiel #4
0
 public static void removeListValue(
     RDFResource resource, RDFProperty property, RDFList li, int index) {
   if (index == 0) {
     RDFList rest = li.getRest();
     if (li.getOWLModel().getRDFNil().equals(rest)) {
       rest = null;
     }
     li.setRest(null);
     resource.setPropertyValue(property, rest);
     li.delete();
   } else {
     RDFList pred = null;
     while (index > 0) {
       index--;
       pred = li;
       li = li.getRest();
     }
     RDFList rest = li.getRest();
     li.setRest(null);
     pred.setRest(rest);
     li.delete();
   }
 }
Beispiel #5
0
 public boolean equalsStructurally(RDFObject object) {
   if (object instanceof RDFList) {
     RDFList list = (RDFList) object;
     if (getValues().size() == list.getValues().size()) {
       Iterator it = getValues().iterator();
       for (Iterator listIt = list.getValues().iterator(); listIt.hasNext(); ) {
         OWLModel model = getOWLModel();
         RDFObject curListObj = model.asRDFObject(listIt.next());
         RDFObject curThisObj = model.asRDFObject(it.next());
         if (curListObj != null && curThisObj != null) {
           if (curListObj.equalsStructurally(curThisObj) == false) {
             return false;
           }
         } else {
           if (curListObj != curThisObj) {
             return false;
           }
         }
       }
       return true;
     }
   }
   return false;
 }
Beispiel #6
0
  public void append(Object value) {

    boolean done = false;
    RDFList current = this;

    while (!done) {
      if (current.getFirst() == null) {
        current.setFirst(value);
        current.setRest(getOWLModel().getRDFNil());
        done = true;
      } else if (current.getRest() == null || getOWLModel().getRDFNil().equals(current.getRest())) {
        RDFSNamedClass listClass = (RDFSNamedClass) getDirectType();
        RDFList newRest = (RDFList) listClass.createAnonymousInstance();
        newRest.setFirst(value);
        newRest.setRest(getOWLModel().getRDFNil());
        current.setRest(newRest);
        done = true;
      } else {
        current = current.getRest(); // Recursion into tail
      }
    }
  }
Beispiel #7
0
 public static void removeListValue(RDFResource resource, RDFProperty property, Object value) {
   RDFList list = (RDFList) resource.getPropertyValue(property);
   List values = list.getValues();
   int index = values.indexOf(value);
   removeListValue(resource, property, list, index);
 }