public static Object resolve()

in taverna-databundle/src/main/java/org/apache/taverna/databundle/DataBundles.java [560:654]


	public static Object resolve(Path path, ResolveOptions... options) throws IOException {
		EnumSet<ResolveOptions> opt;
		if (options.length == 0) {
			opt = EnumSet.of(ResolveOptions.DEFAULT); // no-op
		} else {
			opt = EnumSet.of(ResolveOptions.DEFAULT, options);
		}
		
		if (opt.contains(ResolveOptions.BYTES) && opt.contains(ResolveOptions.STRING)) {
			throw new IllegalArgumentException("Incompatible options: BYTES and STRING");
		}
		if (opt.contains(ResolveOptions.BYTES) && opt.contains(ResolveOptions.PATH)) {
			throw new IllegalArgumentException("Incompatible options: BYTES and PATH");
		}
		if (opt.contains(ResolveOptions.BYTES) && opt.contains(ResolveOptions.URI)) {
			throw new IllegalArgumentException("Incompatible options: BYTES and URI");
		}
		if (opt.contains(ResolveOptions.STRING) && opt.contains(ResolveOptions.PATH)) {
			throw new IllegalArgumentException("Incompatible options: STRING and PATH");
		}
		if (opt.contains(ResolveOptions.STRING) && opt.contains(ResolveOptions.URI)) {
			throw new IllegalArgumentException("Incompatible options: STRING and URI");
		}
		if (opt.contains(ResolveOptions.PATH) && opt.contains(ResolveOptions.URI)) {
			throw new IllegalArgumentException("Incompatible options: PATH and URI");
		}

		
		if (path == null || isMissing(path)) {
			if (! opt.contains(ResolveOptions.REPLACE_NULL)) { 
				return null;
			}
			if (opt.contains(ResolveOptions.BYTES)) {
				return new byte[0];
			}
			if (opt.contains(ResolveOptions.PATH)) { 
				return path;
			}
			if (opt.contains(ResolveOptions.URI)) {
				return path.toUri();
			}
			// STRING and DEFAULT
			return "";			
			
 
		}
		
		if (isList(path)) {
			List<Path> list = getList(path);
			List<Object> objectList = new ArrayList<Object>(list.size());
			for (Path pathElement : list) {
				objectList.add(resolve(pathElement, options));
			}
			return objectList;
		}		
		if (opt.contains(ResolveOptions.PATH)) {
			return path;
		}		
		if (isError(path)) {
			if (opt.contains(ResolveOptions.REPLACE_ERRORS)) {
				return opt.contains(ResolveOptions.REPLACE_NULL) ? "" : null;	
			}
			return getError(path);
		}
		if (opt.contains(ResolveOptions.URI)) {
			if (isReference(path)) {
				return getReference(path);
			} else {
				return path.toUri();
			}
		}
		if (isReference(path)) {
			URI reference = getReference(path);
			String scheme = reference.getScheme();
			if ("file".equals(scheme)) {
				return new File(reference);
			} else {
				try { 
					return reference.toURL();
				} catch (IllegalArgumentException|MalformedURLException e) {
					return reference;
				}
			}
		}
		if (isValue(path)) {
			if (opt.contains(ResolveOptions.BYTES)) {
				return Files.readAllBytes(path);
			}
			if (opt.contains(ResolveOptions.STRING)) {
				return getStringValue(path);
			}
		}
		// Fall-back - return Path as-is
		return path;
	}