|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ModuleLabels.java | 75% | 77,8% | 66,7% | 75% |
|
1 | /* $Id: ModuleLabels.java,v 1.10 2006/10/20 20:23:05 m31 Exp $ | |
2 | * | |
3 | * This file is part of the project "Hilbert II" - http://www.qedeq.org | |
4 | * | |
5 | * Copyright 2000-2006, 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.context.ModuleContext; | |
24 | import org.qedeq.kernel.dto.module.NodeVo; | |
25 | ||
26 | ||
27 | /** | |
28 | * Maps labels of an module to their elements. | |
29 | * | |
30 | * @version $Revision: 1.10 $ | |
31 | * @author Michael Meyling | |
32 | */ | |
33 | public final class ModuleLabels { | |
34 | ||
35 | /** Maps labels to business objects. */ | |
36 | private final Map label2Bo; | |
37 | ||
38 | /** Maps labels to context of business objects. */ | |
39 | private final Map label2Context; | |
40 | ||
41 | /** | |
42 | * Constructs a new empty module label list. | |
43 | */ | |
44 | 57 | public ModuleLabels() { |
45 | 57 | label2Bo = new HashMap(); |
46 | 57 | label2Context = new HashMap(); |
47 | } | |
48 | ||
49 | /** | |
50 | * Add node with certain id. | |
51 | * | |
52 | * @param node For this node. | |
53 | * @param context With this context. | |
54 | * @throws IllegalModuleDataException The <code>id</code> already exists or is | |
55 | * <code>null</code>. | |
56 | */ | |
57 | 306 | public final void addNode(final ModuleContext context, final NodeVo node) |
58 | throws IllegalModuleDataException { | |
59 | 306 | if (null == node.getId()) { |
60 | 0 | throw new IllegalModuleDataException(10001, "An id was not defined.", context, null, |
61 | null); | |
62 | } | |
63 | 306 | if (label2Bo.containsKey(node.getId())) { |
64 | 2 | throw new IllegalModuleDataException(10001, "Id \"" + node.getId() |
65 | + "\" defined more than once.", context, | |
66 | (ModuleContext) label2Context.get(node.getId()), null); | |
67 | } | |
68 | 304 | label2Bo.put(node.getId(), node); |
69 | // don't forget to use the copy constructor because the context could change! | |
70 | 304 | label2Context.put(node.getId(), new ModuleContext(context)); |
71 | } | |
72 | ||
73 | /** | |
74 | * Get node for given id. | |
75 | * | |
76 | * @param id Label to search node for. | |
77 | * @return Node for given label. Maybe <code>null</code>. | |
78 | */ | |
79 | 0 | public final NodeVo getNode(final String id) { |
80 | 0 | return (NodeVo) label2Bo.get(id); |
81 | } | |
82 | ||
83 | } |
|