View Javadoc

1   package com.atlassian.plugin.osgi.factory;
2   
3   import com.atlassian.plugin.IllegalPluginStateException;
4   import com.atlassian.plugin.module.ContainerAccessor;
5   import com.atlassian.plugin.osgi.container.OsgiContainerException;
6   import org.osgi.framework.Bundle;
7   import org.osgi.util.tracker.ServiceTracker;
8   
9   import java.io.InputStream;
10  import java.net.URL;
11  import java.util.Set;
12  
13  import static com.google.common.base.Preconditions.checkNotNull;
14  
15  /**
16   * Helper class that implements common behaviour to {@link OsgiPluginHelper} instances whether
17   * before installation or after deinstallation.
18   *
19   * @since 3.0.17
20   */
21  abstract class OsgiPluginNotInstalledHelperBase implements OsgiPluginHelper
22  {
23      private final String key;
24  
25      OsgiPluginNotInstalledHelperBase(final String key)
26      {
27          this.key = checkNotNull(key);
28      }
29  
30      public Bundle getBundle()
31      {
32          throw new IllegalPluginStateException(getNotInstalledMessage());
33      }
34  
35      public URL getResource(final String name)
36      {
37          throw new IllegalPluginStateException("Cannot getResource(" + name + "): " + getNotInstalledMessage());
38      }
39  
40      public InputStream getResourceAsStream(final String name)
41      {
42          throw new IllegalPluginStateException("Cannot getResourceAsStream(" + name + "): " + getNotInstalledMessage());
43      }
44  
45      public ClassLoader getClassLoader()
46      {
47          throw new IllegalPluginStateException(getNotInstalledMessage());
48      }
49  
50      public void onEnable(final ServiceTracker... serviceTrackers) throws OsgiContainerException
51      {
52          throw new IllegalPluginStateException(getNotInstalledMessage());
53      }
54  
55      public void onDisable() throws OsgiContainerException
56      {
57          throw new IllegalPluginStateException(getNotInstalledMessage());
58      }
59  
60      public void onUninstall() throws OsgiContainerException
61      {
62          throw new IllegalPluginStateException(getNotInstalledMessage());
63      }
64  
65      public Set<String> getRequiredPlugins()
66      {
67          throw new IllegalPluginStateException(getNotInstalledMessage());
68      }
69  
70      public void setPluginContainer(final Object container)
71      {
72          throw new IllegalPluginStateException(getNotInstalledMessage());
73      }
74  
75      public ContainerAccessor getContainerAccessor()
76      {
77          throw new IllegalPluginStateException(getNotInstalledMessage());
78      }
79  
80      public ContainerAccessor getRequiredContainerAccessor()
81      {
82          throw new IllegalPluginStateException(getNotInstalledMessage());
83      }
84  
85      protected String getKey()
86      {
87          return key;
88      }
89  
90      protected abstract String getNotInstalledMessage();
91  }