You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2006/05/03 18:07:51 UTC

svn commit: r399344 - /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java

Author: pauls
Date: Wed May  3 09:07:49 2006
New Revision: 399344

URL: http://svn.apache.org/viewcvs?rev=399344&view=rev
Log:
BundleContext throws an IllegalStateException if invalid (FELIX-66)

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java?rev=399344&r1=399343&r2=399344&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java Wed May  3 09:07:49 2006
@@ -56,17 +56,23 @@
 
     public String getProperty(String name)
     {
+        checkBundleContextValid();
+        
         return m_felix.getProperty(name);
     }
 
     public Bundle getBundle()
     {
+        checkBundleContextValid();
+        
         return m_bundle;
     }
 
     public Filter createFilter(String expr)
         throws InvalidSyntaxException
     {
+        checkBundleContextValid();
+        
         return new FilterImpl(m_felix.getLogger(), expr);
     }
 
@@ -79,26 +85,36 @@
     public Bundle installBundle(String location, InputStream is)
         throws BundleException
     {
+        checkBundleContextValid();
+        
         return m_felix.installBundle(location, is);
     }
 
     public Bundle getBundle(long id)
     {
+        checkBundleContextValid();
+        
         return m_felix.getBundle(id);
     }
 
     public Bundle[] getBundles()
     {
+        checkBundleContextValid();
+        
         return m_felix.getBundles();
     }
 
     public void addBundleListener(BundleListener l)
     {
+        checkBundleContextValid();
+        
         m_felix.addBundleListener(m_bundle, l);
     }
 
     public void removeBundleListener(BundleListener l)
     {
+        checkBundleContextValid();
+        
         m_felix.removeBundleListener(l);
     }
 
@@ -117,21 +133,29 @@
     public void addServiceListener(ServiceListener l, String s)
         throws InvalidSyntaxException
     {
+        checkBundleContextValid();
+        
         m_felix.addServiceListener(m_bundle, l, s);
     }
 
     public void removeServiceListener(ServiceListener l)
     {
+        checkBundleContextValid();
+        
         m_felix.removeServiceListener(l);
     }
 
     public void addFrameworkListener(FrameworkListener l)
     {
+        checkBundleContextValid();
+        
         m_felix.addFrameworkListener(m_bundle, l);
     }
 
     public void removeFrameworkListener(FrameworkListener l)
     {
+        checkBundleContextValid();
+        
         m_felix.removeFrameworkListener(l);
     }
 
@@ -144,11 +168,15 @@
     public ServiceRegistration registerService(
         String[] clazzes, Object svcObj, Dictionary dict)
     {
+        checkBundleContextValid();
+        
         return m_felix.registerService(m_bundle, clazzes, svcObj, dict);
     }
 
     public ServiceReference getServiceReference(String clazz)
     {
+        checkBundleContextValid();
+        
         try
         {
             ServiceReference[] refs = getServiceReferences(clazz, null);
@@ -247,6 +275,8 @@
 
     public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
     {
+        checkBundleContextValid();
+        
         // TODO: Implement BundleContext.getAllServiceReferences()
         return null;
     }
@@ -254,11 +284,15 @@
     public ServiceReference[] getServiceReferences(String clazz, String filter)
         throws InvalidSyntaxException
     {
+        checkBundleContextValid();
+        
         return m_felix.getServiceReferences(m_bundle, clazz, filter);
     }
 
     public Object getService(ServiceReference ref)
     {
+        checkBundleContextValid();
+        
         if (ref == null)
         {
             throw new NullPointerException("Specified service reference cannot be null.");
@@ -268,6 +302,8 @@
 
     public boolean ungetService(ServiceReference ref)
     {
+        checkBundleContextValid();
+        
         if (ref == null)
         {
             throw new NullPointerException("Specified service reference cannot be null.");
@@ -279,6 +315,21 @@
 
     public File getDataFile(String s)
     {
+        checkBundleContextValid();
+        
         return m_felix.getDataFile(m_bundle, s);
+    }
+
+    private void checkBundleContextValid()
+    {
+        switch(m_bundle.getState())
+        {
+            case Bundle.ACTIVE:
+            case Bundle.STARTING:
+            case Bundle.STOPPING:
+                return;
+        }
+        
+        throw new IllegalStateException("Invalid BundleContext.");
     }
 }