Beispiel #1
0
 /**
  * Call this method to convert a value (v) as a Java object to a typed Literal matching the range
  * of the property.
  *
  * @param m
  * @param prop
  * @param v
  * @return
  * @throws Exception
  */
 public static synchronized Literal getLiteralMatchingDataPropertyRange(
     OntModel m, OntProperty prop, Object v) throws Exception {
   Literal val = null;
   String errMsg = null;
   if (prop.isAnnotationProperty()) {
     return m.createTypedLiteral(v);
   }
   // SADL only has DoubleLiterals--if this property has range float convert v to Float.
   OntResource rng = prop.getRange();
   String rnguri = rng != null ? rng.getURI() : null;
   if (rng == null) {
     errMsg = "Range not given.";
   } else if (rng.isAnon()) {
     // this is a complex range--needs work. Try to do something with it....
     // If value is a String
     if (v instanceof String) {
       v = stripQuotes((String) v);
       val = m.createTypedLiteral(v);
     } else {
       val = m.createTypedLiteral(v);
       if (val == null) {
         errMsg =
             "Range is an unsupported complex type, failed to create a Literal value for '"
                 + v.toString()
                 + "'.";
       }
     }
   } else {
     val = getLiteralMatchingDataPropertyRange(m, rnguri, v);
   }
   if (errMsg != null) {
     errMsg += " (Property is '" + prop.getLocalName() + "'.)";
     throw new Exception(errMsg);
   }
   return val;
 }