1 | package genius.core.repository;
|
---|
2 |
|
---|
3 | import java.net.URL;
|
---|
4 | import java.util.ArrayList;
|
---|
5 |
|
---|
6 | import javax.xml.bind.annotation.XmlAttribute;
|
---|
7 | import javax.xml.bind.annotation.XmlElement;
|
---|
8 | import javax.xml.bind.annotation.XmlRootElement;
|
---|
9 |
|
---|
10 | import genius.core.exceptions.Warning;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * A DomainRepItem is a domain reference that can be put in the domain
|
---|
14 | * repository. It contains only a unique reference to an xml file with the
|
---|
15 | * domain description.
|
---|
16 | *
|
---|
17 | * @author wouter
|
---|
18 | */
|
---|
19 | @XmlRootElement
|
---|
20 | public class DomainRepItem implements RepItem {
|
---|
21 | private static final long serialVersionUID = 6672725212678925392L;
|
---|
22 | @XmlAttribute
|
---|
23 | private URL url;
|
---|
24 | @XmlElement(name = "profile")
|
---|
25 | private ArrayList<ProfileRepItem> profiles = new ArrayList<ProfileRepItem>(); // default
|
---|
26 |
|
---|
27 | /** for serialization support */
|
---|
28 | @SuppressWarnings("unused")
|
---|
29 | private DomainRepItem() {
|
---|
30 | try {
|
---|
31 | url = new URL("file:unknownfilename");
|
---|
32 | } catch (Exception e) {
|
---|
33 | new Warning("default url failed!?", e);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public DomainRepItem(URL newurl) {
|
---|
38 | url = newurl;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public URL getURL() {
|
---|
42 | return url;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public ArrayList<ProfileRepItem> getProfiles() {
|
---|
46 | return profiles;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public String toString() {
|
---|
51 | return getName();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public String getFullName() {
|
---|
55 | return "DomainRepItem[" + url + "," + profiles + "]";
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public boolean equals(Object o) {
|
---|
60 | if (!(o instanceof DomainRepItem)) {
|
---|
61 | return false;
|
---|
62 | }
|
---|
63 | return url.equals(((DomainRepItem) o).getURL());
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public int hashCode() {
|
---|
68 | int hash = 7;
|
---|
69 | hash = 89 * hash + (this.url != null ? this.url.hashCode() : 0);
|
---|
70 | return hash;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public String getName() {
|
---|
74 | String name = url.getFile();
|
---|
75 | int dotindex = name.lastIndexOf('.'), slashindex = name
|
---|
76 | .lastIndexOf('/');
|
---|
77 |
|
---|
78 | if (slashindex < 0)
|
---|
79 | slashindex = 0;
|
---|
80 | if (dotindex < 0)
|
---|
81 | dotindex = name.length() - 1;
|
---|
82 | name = name.substring(slashindex + 1, dotindex);
|
---|
83 |
|
---|
84 | return name;
|
---|
85 | }
|
---|
86 |
|
---|
87 | }
|
---|