コード例 #1
0
ファイル: QueryService.java プロジェクト: GerritBoers/exist
 /**
  * Convert the given object into a value appropriate for being defined as the value of a variable
  * in an XQuery. This will extract a sequence out of all database objects, convert collections and
  * arrays into sequences recursively, convert <code>null</code> into an empty sequence, and pass
  * other objects through untouched. Convertible objects that are defined in the JDK will be
  * automatically converted by eXist.
  *
  * @see org.exist.xquery.XPathUtil#javaObjectToXPath(Object, XQueryContext, boolean)
  * @param o the object to convert to a database value
  * @return the converted value, ready for assignment to an XQuery variable
  */
 @SuppressWarnings("unchecked")
 private Object convertValue(Object o) {
   if (o == null) return Collections.emptyList();
   if (o instanceof Resource) {
     try {
       return ((Resource) o).convertToSequence();
     } catch (UnsupportedOperationException e) {
       return o;
     }
   }
   List<Object> list = null;
   if (o instanceof Collection) list = new ArrayList<Object>((Collection) o);
   else if (o instanceof Object[]) list = new ArrayList<Object>(Arrays.asList((Object[]) o));
   if (list != null) {
     for (ListIterator<Object> it = list.listIterator(); it.hasNext(); ) {
       it.set(convertValue(it.next()));
     }
     return list;
   }
   return DataUtils.toXMLObject(o);
 }