View Javadoc

1   package org.musicontroller.core;
2   
3   import java.io.File;
4   import java.util.Date;
5   
6   public class Link {
7   	private static MusicDirProvider _musicDirProvider = null;
8   	
9   	private long _id;
10  	private Date _changed,_inserted;
11  	private String _url;
12  	
13  	public Link() {
14  		_id=-1L;
15  		_inserted=new Date();
16  		_url="";
17  	}
18  
19  	public Link(String url) {
20  		_id=-1L;
21  		_inserted=new Date();
22  		_url=url;
23  	}
24  	
25  	public Date getChanged() {
26  		return _changed;
27  	}
28  	
29  	public void setChanged(Date changed) {
30  		_changed = changed;
31  	}
32  	
33  	public long getId() {
34  		return _id;
35  	}
36  	
37  	public void setId(long id) {
38  		_id = id;
39  	}
40  	
41  	public Date getInserted() {
42  		return _inserted;
43  	}
44  	
45  	public void setInserted(Date inserted) {
46  		_inserted = inserted;
47  	}
48  	
49  	public String getUrl() {
50  		return _url;
51  	}
52  	
53  	public void setUrl(String url) {
54  		_url = url;
55  	}
56  	
57  	/*
58  	 * (non-Javadoc)
59  	 * @see java.lang.Object#toString()
60  	 */
61  	@Override
62  	public String toString() {
63  		return getUrl();
64  	}
65  	
66  	/**
67  	 * Directly returns the File this Link links to. However, if this Link links
68  	 * to an object that is not on the filesystem, the returned File is
69  	 * unusable!
70  	 * @return The File this Link links.
71  	 */
72  	public File getFile() {
73  		String prefix = _musicDirProvider==null ? "" : _musicDirProvider.getMusicDirectory();
74  		String url = _url.startsWith(prefix) ? _url : prefix + File.separator + _url;
75  		return new File(url); 
76  	}
77  	
78  	/**
79  	 * Sets the MusicDirProvider. This provider is used in the getFile method
80  	 * to contruct a valid filesystem object. 
81  	 * @param musicDirProvider The MusicDirProvider to use.
82  	 */
83  	public void setMusicDirProvider(MusicDirProvider musicDirProvider) {
84  		_musicDirProvider = musicDirProvider;
85  	}
86  	
87  	/**
88  	 * Returns the MusicDirProvider.
89  	 * @return The MusicDirProvider.
90  	 */
91  	public MusicDirProvider getMusicDirProvider() {
92  		return _musicDirProvider;
93  	}
94  
95  }