All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.taverna.robundle.manifest.PathMetadata Maven / Gradle / Ivy

There is a newer version: 0.15.1-incubating
Show newest version
package org.apache.taverna.robundle.manifest;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */


import java.net.URI;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder(value = { "uri", "mediatype", "createdOn", "createdBy",
		"authoredOn", "authoredBy", "conformsTo", "bundledAs" })
public class PathMetadata {

	private static URI ROOT = URI.create("/");

	private List authoredBy = new ArrayList<>();
	private FileTime authoredOn;
	private Proxy bundledAs;

	private URI conformsTo;
	private Agent createdBy;

	private FileTime createdOn;
	private Path file;

	private String mediatype;

	private URI uri;

	protected PathMetadata() {
	}

	@JsonCreator
	public PathMetadata(String uriStr) {
		setUri(URI.create(uriStr));
	}

	public List getAuthoredBy() {
		return authoredBy;
	}

	public FileTime getAuthoredOn() {
		return authoredOn;
	}

	public Proxy getBundledAs() {
		return bundledAs;
	}

	public URI getConformsTo() {
		return conformsTo;
	}

	public Agent getCreatedBy() {
		return createdBy;
	}

	public FileTime getCreatedOn() {
		return createdOn;
	}

	@JsonIgnore
	public Path getFile() {
		return file;
	}

	@JsonIgnore
	@Deprecated
	public Path getFolder() {
		Proxy bundledAs = getBundledAs();
		if (bundledAs == null) {
			return null;
		}
		return bundledAs.getFolder();
	}

	public String getMediatype() {
		return mediatype;
	}

	@JsonIgnore
	public Proxy getOrCreateBundledAs() {
		if (bundledAs == null) {
			bundledAs = new Proxy();
			setProxy();
		}
		return bundledAs;
	}

	@JsonIgnore
	@Deprecated
	public URI getProxy() {
		Proxy bundledAs = getBundledAs();
		if (bundledAs == null) {
			return null;
		}
		return bundledAs.getURI();
	}

	public URI getUri() {
		return uri;
	}

	public void setAuthoredBy(List authoredBy) {
		if (authoredBy == null) {
			throw new NullPointerException("authoredBy list can't be empty");
		}
		this.authoredBy = authoredBy;
	}

	public void setAuthoredOn(FileTime authoredOn) {
		this.authoredOn = authoredOn;
	}

	public void setBundledAs(Proxy bundledAs) {
		if (bundledAs == null) {
			throw new NullPointerException(
					"bundledAs can't be empty (try a new Proxy instance)");
		}
		this.bundledAs = bundledAs;
	}

	public void setConformsTo(URI conformsTo) {
		this.conformsTo = conformsTo;
	}

	public void setCreatedBy(Agent createdBy) {
		this.createdBy = createdBy;
	}

	public void setCreatedOn(FileTime createdOn) {
		this.createdOn = createdOn;
	}

	public void setFile(Path file) {
		this.file = file;
		Path root = this.file.resolve("/");
		URI uri = ROOT.resolve(root.toUri().relativize(file.toUri()));
		setUri(uri);
	}

	@Deprecated
	public void setFolder(Path folder) {
		getOrCreateBundledAs().setFolder(folder);
	}

	public void setMediatype(String mediatype) {
		this.mediatype = mediatype;
	}

	@Deprecated
	public void setProxy() {
		getOrCreateBundledAs().setURI();
	}

	@Deprecated
	public void setProxy(URI proxy) {
		getOrCreateBundledAs().setURI(proxy);
	}

	public void setUri(URI uri) {
		this.uri = uri;
		if (!uri.isAbsolute()) {
			// TODO: How to create a Path without knowing the root?
			// file = uri;
			// this.uri = null;
		}
	}

	@Override
	public String toString() {
		if (getUri() != null) {
			return getUri().toString();
		}
		if (getFile() != null) {
			return getFile().toString();
		}
		if (getProxy() != null) {
			return getProxy().toString();
		}
		return "PathMetadata ";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy