View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.slc.core.attachment;
17  
18  import java.io.Serializable;
19  import java.util.UUID;
20  
21  public class SimpleAttachment implements Attachment, Serializable {
22  	private static final long serialVersionUID = 6615155908800610606L;
23  	private String uuid = UUID.randomUUID().toString();
24  	private String name;
25  	private String contentType = "";
26  
27  	public SimpleAttachment() {
28  	}
29  
30  	public SimpleAttachment(String uuid, String name, String contentType) {
31  		super();
32  		this.uuid = uuid;
33  		this.name = name;
34  		this.contentType = contentType;
35  	}
36  
37  	public String getUuid() {
38  		return uuid;
39  	}
40  
41  	public void setUuid(String uuid) {
42  		this.uuid = uuid;
43  	}
44  
45  	public String getName() {
46  		return name;
47  	}
48  
49  	public void setName(String name) {
50  		this.name = name;
51  	}
52  
53  	public String getContentType() {
54  		return contentType;
55  	}
56  
57  	public void setContentType(String contentType) {
58  		this.contentType = contentType;
59  	}
60  
61  	public String toString() {
62  		return "Attachment #" + uuid + "(" + name + ", " + contentType + ")";
63  	}
64  
65  	public boolean equals(Object obj) {
66  		if (obj instanceof Attachment) {
67  			Attachment attachment = (Attachment) obj;
68  			if (uuid != null && attachment.getUuid() != null)
69  				return uuid.equals(attachment.getUuid());
70  
71  			if (name != null && attachment.getName() != null)
72  				return name.equals(attachment.getName());
73  
74  			return hashCode() == attachment.hashCode();
75  		}
76  		return false;
77  	}
78  }