Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ProfileFacade |
|
| 1.5555555555555556;1.556 |
1 | /* $Id: ProfileFacade.java 18335 2010-04-27 11:19:16Z bobtarling $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2007,2010 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * maurelio1234 - initial implementation | |
11 | * Tom Morris | |
12 | ***************************************************************************** | |
13 | * | |
14 | * Some portions of this file was previously release using the BSD License: | |
15 | */ | |
16 | ||
17 | // Copyright (c) 2007-2008 The Regents of the University of California. All | |
18 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
19 | // software and its documentation without fee, and without a written | |
20 | // agreement is hereby granted, provided that the above copyright notice | |
21 | // and this paragraph appear in all copies. This software program and | |
22 | // documentation are copyrighted by The Regents of the University of | |
23 | // California. The software program and documentation are supplied "AS | |
24 | // IS", without any accompanying services from The Regents. The Regents | |
25 | // does not warrant that the operation of the program will be | |
26 | // uninterrupted or error-free. The end-user understands that the program | |
27 | // was developed for research purposes and is advised not to rely | |
28 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
29 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
30 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
31 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
32 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
33 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
34 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
35 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
36 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
37 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
38 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
39 | ||
40 | package org.argouml.profile; | |
41 | ||
42 | import org.apache.log4j.Logger; | |
43 | import org.argouml.kernel.ProfileConfiguration; | |
44 | import org.argouml.model.InvalidElementException; | |
45 | ||
46 | /** | |
47 | * The <a href="http://en.wikipedia.org/wiki/Facade_pattern">Facade</a> of the | |
48 | * profile subsystem. | |
49 | * It provides a simplified interface to the subsystem, and access to objects | |
50 | * of the subsystem when the methods it provides directly aren't enough. | |
51 | * | |
52 | * @author Luis Sergio Oliveira (euluis) | |
53 | * @since 0.25.4 | |
54 | */ | |
55 | 0 | public class ProfileFacade { |
56 | ||
57 | 900 | private static final Logger LOG = Logger.getLogger(ProfileFacade.class); |
58 | ||
59 | /** | |
60 | * Register a profile in the {@link ProfileManager}. | |
61 | * @param profile the profile to be registered | |
62 | */ | |
63 | public static void register(Profile profile) { | |
64 | 0 | getManager().registerProfile(profile); |
65 | 0 | } |
66 | ||
67 | /** | |
68 | * Remove or unregister the profile from the {@link ProfileManager}. | |
69 | * @param profile the profile to be removed | |
70 | */ | |
71 | public static void remove(Profile profile) { | |
72 | 0 | getManager().removeProfile(profile); |
73 | 0 | } |
74 | ||
75 | /** | |
76 | * @return the profile manager | |
77 | */ | |
78 | public static ProfileManager getManager() { | |
79 | 3146 | if (manager == null) { |
80 | 0 | notInitialized("manager"); |
81 | } | |
82 | 3146 | return manager; |
83 | } | |
84 | ||
85 | private static void notInitialized(String string) { | |
86 | 0 | throw new RuntimeException("ProfileFacade's " + string |
87 | + " isn't initialized!"); | |
88 | } | |
89 | ||
90 | /** | |
91 | * @param profileManager the manager of the profiles to be used | |
92 | */ | |
93 | public static void setManager(ProfileManager profileManager) { | |
94 | 900 | manager = profileManager; |
95 | 900 | } |
96 | ||
97 | /** | |
98 | * Remove all registered profiles. | |
99 | */ | |
100 | static void removeAllProfiles() { | |
101 | 900 | if (manager != null) { |
102 | 0 | Profile[] profiles = manager.getRegisteredProfiles().toArray( |
103 | new Profile[0]); | |
104 | 0 | for (Profile p : profiles) { |
105 | try { | |
106 | 0 | manager.removeProfile(p); |
107 | 0 | } catch (InvalidElementException e) { |
108 | 0 | LOG.debug("Attempted to delete extent twice in removeAllProfiles "); |
109 | 0 | } |
110 | } | |
111 | } | |
112 | 900 | } |
113 | ||
114 | /** | |
115 | * Reset profile subsystem to initial state (primarily for testing). | |
116 | */ | |
117 | public static void reset() { | |
118 | 900 | removeAllProfiles(); |
119 | 900 | manager = null; |
120 | 900 | } |
121 | ||
122 | private static ProfileManager manager; | |
123 | ||
124 | /** | |
125 | * @return true is subsystem is initialized or false otherwise | |
126 | */ | |
127 | public static boolean isInitiated() { | |
128 | 3816 | return manager != null; |
129 | } | |
130 | ||
131 | /** | |
132 | * Applies the given ProfileConfiguration to ArgoUML | |
133 | * | |
134 | * @param pc the profile configuration | |
135 | */ | |
136 | public static void applyConfiguration(ProfileConfiguration pc) { | |
137 | 980 | getManager().applyConfiguration(pc); |
138 | 980 | } |
139 | ||
140 | } |