|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ModuleLabels.java | 75% | 77,8% | 66,7% | 75% |
|
1 | /* $Id: ModuleLabels.java,v 1.3 2007/04/12 23:50:04 m31 Exp $ | |
2 | * | |
3 | * This file is part of the project "Hilbert II" - http://www.qedeq.org | |
4 | * | |
5 | * Copyright 2000-2007, Michael Meyling <mime@qedeq.org>. | |
6 | * | |
7 | * "Hilbert II" is free software; you can redistribute | |
8 | * it and/or modify it under the terms of the GNU General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | */ | |
17 | ||
18 | package org.qedeq.kernel.bo.module; | |
19 | ||
20 | import java.util.HashMap; | |
21 | import java.util.Map; | |
22 | ||
23 | import org.qedeq.kernel.dto.module.NodeVo; | |
24 | ||
25 | ||
26 | /** | |
27 | * Maps labels of an module to their elements. | |
28 | * | |
29 | * @version $Revision: 1.3 $ | |
30 | * @author Michael Meyling | |
31 | */ | |
32 | public final class ModuleLabels { | |
33 | ||
34 | /** Maps labels to business objects. */ | |
35 | private final Map label2Bo; | |
36 | ||
37 | /** Maps labels to context of business objects. */ | |
38 | private final Map label2Context; | |
39 | ||
40 | /** | |
41 | * Constructs a new empty module label list. | |
42 | */ | |
43 | 67 | public ModuleLabels() { |
44 | 67 | label2Bo = new HashMap(); |
45 | 67 | label2Context = new HashMap(); |
46 | } | |
47 | ||
48 | /** | |
49 | * Add node with certain id. | |
50 | * | |
51 | * @param node For this node. | |
52 | * @param context With this context. | |
53 | * @throws IllegalModuleDataException The <code>id</code> already exists or is | |
54 | * <code>null</code>. | |
55 | */ | |
56 | 622 | public final void addNode(final ModuleContext context, final NodeVo node) |
57 | throws IllegalModuleDataException { | |
58 | 622 | if (null == node.getId()) { |
59 | 0 | throw new IllegalModuleDataException(10001, "An id was not defined.", context, null, |
60 | null); | |
61 | } | |
62 | 622 | if (label2Bo.containsKey(node.getId())) { |
63 | 2 | throw new IllegalModuleDataException(10001, "Id \"" + node.getId() |
64 | + "\" defined more than once.", context, | |
65 | (ModuleContext) label2Context.get(node.getId()), null); | |
66 | } | |
67 | 620 | label2Bo.put(node.getId(), node); |
68 | // don't forget to use the copy constructor because the context could change! | |
69 | 620 | label2Context.put(node.getId(), new ModuleContext(context)); |
70 | } | |
71 | ||
72 | /** | |
73 | * Get node for given id. | |
74 | * | |
75 | * @param id Label to search node for. | |
76 | * @return Node for given label. Maybe <code>null</code>. | |
77 | */ | |
78 | 0 | public final NodeVo getNode(final String id) { |
79 | 0 | return (NodeVo) label2Bo.get(id); |
80 | } | |
81 | ||
82 | } |
|