View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  package nl.toolforge.karma.core.location;
20  
21  import nl.toolforge.karma.core.boot.WorkingContext;
22  import nl.toolforge.karma.core.vc.AuthenticatorKey;
23  
24  /***
25   * <code>BaseLocation</code> implements some generic <code>Location</code> functionality.
26   *
27   * @author D.A. Smedes
28   * @version $Id: BaseLocation.java,v 1.12 2004/11/03 20:54:15 asmedes Exp $
29   */
30  public abstract class BaseLocation implements Location {
31  
32    private String id = null;
33    private LocationType type = null;
34    private WorkingContext workingContext = null;
35  
36    /***
37     * Constructs a <code>Location</code> skeleton.
38     *
39     * @param id   The unique identifier for the location. Cannot be null.
40     * @param type The type of the location. Cannot be null.
41     */
42    public BaseLocation(String id, LocationType type) {
43  
44      if (id == null) {
45        throw new IllegalArgumentException("Location id must be set.");
46      }
47      if (type == null) {
48        throw new IllegalArgumentException("Location must be set.");
49      }
50      this.id = id;
51      this.type = type;
52    }
53  
54    public final LocationType getType() {
55      return type;
56    }
57  
58    public final String getId() {
59      return id;
60    }
61  
62    public boolean equals(Object obj) {
63  
64      if (obj instanceof BaseLocation) {
65        if (((BaseLocation) obj).getId().equals(getId())) {
66          return true;
67        }
68      }
69      return false;
70    }
71  
72    public int hashCode() {
73      return getId().hashCode();
74    }
75  
76    // todo hmm, not happy with the workingcontext dependency.
77    //
78    public final void setWorkingContext(WorkingContext workingContext) {
79      this.workingContext = workingContext;
80    }
81  
82    public AuthenticatorKey getAuthenticatorKey() {
83      return new AuthenticatorKey(workingContext.getName(), getId());
84    }
85  }