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 org.apache.commons.digester.Digester;
22  
23  import java.util.ArrayList;
24  
25  /***
26   * Helper class to be able to read locations from an xml structure. This class is capable to handle all formats.
27   *
28   * @author D.A. Smedes
29   * @version $Id: LocationDescriptor.java,v 1.7 2004/10/26 22:48:00 hippe Exp $
30   */
31  public class LocationDescriptor {
32  
33    private String id = null;
34    private String type = null;
35  
36    private String host = null;
37    private String port = null;
38    private String repository = null;
39    private String moduleOffset = null;
40    private String protocol = null;
41  
42    public String getId() {
43      return id;
44    }
45  
46    public void setId(String id) {
47      this.id = id;
48    }
49  
50    public String getType() {
51      return type;
52    }
53  
54    public void setType(String type) {
55      this.type = type;
56    }
57  
58    public String getHost() {
59      return host;
60    }
61  
62    public void setHost(String host) {
63      this.host = host;
64    }
65  
66    public String getPort() {
67      return port;
68    }
69  
70    public void setPort(String port) {
71      this.port = port;
72    }
73  
74    public String getRepository() {
75      return repository;
76    }
77  
78    public void setRepository(String repository) {
79      this.repository = repository;
80    }
81  
82    public String getModuleOffset() {
83      return moduleOffset;
84    }
85  
86    public void setModuleOffset(String moduleOffset) {
87      this.moduleOffset = moduleOffset;
88    }
89  
90    public String getProtocol() {
91      return protocol;
92    }
93  
94    public void setProtocol(String protocol) {
95      this.protocol = protocol;
96    }
97  
98    /***
99     * Creates a <code>Digester</code> to read xml structures for locations. This digester will create an
100    * <code>ArrayList</code> of <code>LocationDescriptor</code> instances.
101    *
102    * @return A digester instance
103    */
104   public static Digester getDigester() {
105 
106     Digester digester = new Digester();
107 
108     digester.setNamespaceAware(true);
109 
110     digester.addObjectCreate("*/locations", ArrayList.class);
111     
112     digester.addObjectCreate("*/locations/location", LocationDescriptor.class);
113     digester.addSetProperties("*/locations/location");
114 
115     digester.addCallMethod("*/locations/location/protocol", "setProtocol", 0);
116     digester.addCallMethod("*/locations/location/host", "setHost", 0);
117     digester.addCallMethod("*/locations/location/port", "setPort", 0);
118     digester.addCallMethod("*/locations/location/repository", "setRepository", 0);
119     digester.addCallMethod("*/locations/location/module-offset", "setModuleOffset", 0);
120     digester.addSetNext("*/locations/location", "add");
121 
122     return digester;
123   }
124 
125 }