View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   */
19  
20  package no.feide.moria.directory.backend;
21  
22  import no.feide.moria.directory.DirectoryManagerConfigurationException;
23  
24  import org.jdom.Element;
25  
26  /***
27   * Factory class for dummy backends.
28   */
29  public class DummyBackendFactory
30  implements DirectoryManagerBackendFactory {
31  
32      /*** Holds the dummy backend configuration. */
33      private Element myConfig;
34  
35  
36      /***
37       * Configures use of the dummy backends. May be called repeatedly to update
38       * used configuration. <br>
39       * <br>
40       * Note that much of the parsing of the configuration element is done in the
41       * <code>DummyBackend</code> class.
42       * @param config
43       *            The new or updated configuration for the dummy backend. Cannot
44       *            be <code>null</code>.
45       * @throws IllegalArgumentException
46       *             If <code>config</code> is <code>null</code>.
47       * @throws DirectoryManagerConfigurationException
48       *             If <code>config</code> is not a <code>Backend</code>
49       *             element.
50       * @see DirectoryManagerBackendFactory#setConfig(Element)
51       */
52      public final void setConfig(final Element config) {
53  
54          // Sanity checks.
55          if (config == null)
56              throw new IllegalArgumentException("Backend configuration element cannot be NULL");
57          if (!config.getName().equalsIgnoreCase("Backend"))
58              throw new DirectoryManagerConfigurationException("Cannot find backend configuration element");
59  
60          myConfig = (Element) config.clone();
61  
62      }
63  
64  
65      /***
66       * Creates a new <code>DummyBackend</code> instance.
67       * @param sessionTicket
68       *            Ignored for instances of <code>DummyBackend</code>.
69       * @see no.feide.moria.directory.backend.DirectoryManagerBackendFactory#createBackend
70       * @return The new DummyBackend.
71       * @see DummyBackend
72       */
73      public final DirectoryManagerBackend createBackend(final String sessionTicket) {
74  
75          DummyBackend newBackend = new DummyBackend(myConfig);
76          return newBackend;
77  
78      }
79  
80  }