Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
StartupWindowProvider.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.logging.Level;
24 import org.openide.util.Lookup;
26 
36 
37  private static volatile StartupWindowProvider instance;
38  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
40 
42  if (instance == null) {
43  synchronized (StartupWindowProvider.class) {
44  if (instance == null) {
45  instance = new StartupWindowProvider();
46  instance.init();
47  }
48  }
49  }
50 
51  return instance;
52  }
53 
54  private void init() {
55  if (startupWindowToUse == null) {
56  //discover the registered windows
57  Collection<? extends StartupWindowInterface> startupWindows =
58  Lookup.getDefault().lookupAll(StartupWindowInterface.class);
59 
60  int windowsCount = startupWindows.size();
61  if (windowsCount > 2) {
62  logger.log(Level.WARNING, "More than 2 (" + windowsCount + ") start up windows discovered, will use the first custom one"); //NON-NLS
63  } else if (windowsCount == 1) {
64  startupWindowToUse = startupWindows.iterator().next();
65  logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
66  } else {
67  //pick the non default one
68  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
69  while (it.hasNext()) {
70  StartupWindowInterface window = it.next();
71  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
72  startupWindowToUse = window;
73  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
74  break;
75 
76  }
77  }
78 
79  if (startupWindowToUse == null) {
80  logger.log(Level.SEVERE, "Unexpected error, no custom startup window found, using the default"); //NON-NLS
81  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
82  }
83 
84  }
85 
86 
87  }
88  }
89 
90  @Override
91  public void open() {
92  if (startupWindowToUse != null) {
93  startupWindowToUse.open();
94  }
95  }
96 
97  @Override
98  public void close() {
99  if (startupWindowToUse != null) {
100  startupWindowToUse.close();
101  }
102  }
103 }
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.