private Object encodeLiteral(final Literal literal) {
   final URI datatype = literal.getDatatype();
   if (datatype == null || datatype.equals(XMLSchema.STRING)) {
     final String language = literal.getLanguage();
     if (language == null) {
       return literal.getLabel();
     } else {
       return SerializerAvro.newGenericRecord(Schemas.STRING_LANG, literal.getLabel(), language);
     }
   } else if (datatype.equals(XMLSchema.BOOLEAN)) {
     return literal.booleanValue();
   } else if (datatype.equals(XMLSchema.LONG)) {
     return literal.longValue();
   } else if (datatype.equals(XMLSchema.INT)) {
     return literal.intValue();
   } else if (datatype.equals(XMLSchema.DOUBLE)) {
     return literal.doubleValue();
   } else if (datatype.equals(XMLSchema.FLOAT)) {
     return literal.floatValue();
   } else if (datatype.equals(XMLSchema.SHORT)) {
     return SerializerAvro.newGenericRecord(Schemas.SHORT, literal.intValue());
   } else if (datatype.equals(XMLSchema.BYTE)) {
     return SerializerAvro.newGenericRecord(Schemas.BYTE, literal.intValue());
   } else if (datatype.equals(XMLSchema.INTEGER)) {
     return SerializerAvro.newGenericRecord(Schemas.BIGINTEGER, literal.stringValue());
   } else if (datatype.equals(XMLSchema.DECIMAL)) {
     return SerializerAvro.newGenericRecord(Schemas.BIGDECIMAL, literal.stringValue());
   } else if (datatype.equals(XMLSchema.DATETIME)) {
     final XMLGregorianCalendar calendar = literal.calendarValue();
     return SerializerAvro.newGenericRecord(
         Schemas.CALENDAR,
         calendar.getTimezone(),
         calendar.toGregorianCalendar().getTimeInMillis());
   }
   throw new IllegalArgumentException("Unsupported literal: " + literal);
 }
  private RDFValueRange fillObjectRange(Value oVal) {
    if (oVal instanceof URI) {
      URI uri = (URI) oVal;
      PrefixRange pr = new PrefixRange();
      pr.getPrefixList().add(uri.stringValue());

      return new RDFValueRange(
          new RDFURIRange(pr.getPrefixList()),
          new RDFLiteralRange(Collections.<URI, RangeLength<?>>emptyMap()));
    } else if (oVal instanceof Literal) {
      Literal l = (Literal) oVal;
      Range literalRange = null;

      if (l.getDatatype().equals(XMLSchema.INT))
        literalRange =
            new RDFLiteralRange(XMLSchema.INT, new IntervalRange(l.intValue(), l.intValue()));
      else if (l.getDatatype().equals(XMLSchema.LONG))
        literalRange =
            new RDFLiteralRange(
                XMLSchema.LONG, new IntervalRange((int) l.longValue(), (int) l.longValue()));
      else if (l.getDatatype().equals(XMLSchema.STRING)) {
        PrefixRange pr = new PrefixRange();
        pr.getPrefixList().add(l.stringValue());
        literalRange = new RDFLiteralRange(XMLSchema.STRING, pr);
      } else if (l.getDatatype().equals(XMLSchema.DATETIME)) {
        Calendar cal = l.calendarValue().toGregorianCalendar();
        CalendarRange cr = new CalendarRange(cal.getTime(), cal.getTime());
        literalRange = new RDFLiteralRange(XMLSchema.DATETIME, cr);
      }

      if (literalRange != null)
        return new RDFValueRange(
            new RDFURIRange(Collections.<String>emptyList()), (RDFLiteralRange) literalRange);
    }

    return new RDFValueRange();
  }
Beispiel #3
0
 public static String literal(Literal l) {
   return literal(l.stringValue());
 }