users@glassfish.java.net

Re: NPE - java.lang.reflect.UndeclaredThrowableException

From: <forums_at_java.net>
Date: Fri, 3 Feb 2012 09:54:54 -0600 (CST)

I followed your instructions. Cannot find variable ds:

http://i39.tinypic.com/14xdw5c.png

This is the code:

package org.DX_57.osgi.SH_27.impl;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;
import org.DX_57.osgi.SH_27.api.SessionHandle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
public class SessionHandleApp implements BundleActivator {
   
    private static final String DSNAME = "jdbc/Oracle";
    private ServiceTracker st;
   
    @Override
    public void start(final BundleContext bc) throws Exception {
        debug("Activator started");
 //       bc.registerService(SessionHandle.class.getName(), new
SessionHandleImpl(), new Properties());
       
        Filter filter = bc.createFilter("(&" + "(" +
Constants.OBJECTCLASS
                + "=" + DataSource.class.getName() + ")" +
"(jndi-name="
                + DSNAME + ")" + ")");
        st = new ServiceTracker(bc, filter, null) {
            @Override
            public Object addingService(ServiceReference reference)
{
                DataSource ds = (DataSource)
bc.getService(reference);
                try {
                    debug(ds.getConnection().toString());
                SessionHandle sh = new SessionHandleImpl();
                                     sh.ds
= ds;
                bc.registerService(SessionHandle.class.getName(),
sh, null);
                } catch (SQLException e) {
                }
                return super.addingService(reference);
            }
            @Override
            public void removedService(ServiceReference reference,
                    Object service) {
                super.removedService(reference, service);
            }
        };
        st.open();       
       
    }
    public void stop(BundleContext bc) throws Exception {
       
bc.ungetService(bc.getServiceReference(SessionHandle.class.getName()));
        st.close();
    }
   
    private void debug(String msg) {
        System.out.println("JDBCTestBundleActivator: " + msg);
    }
}
 


--
[Message sent by forum member 'rcbandit']
View Post: http://forums.java.net/node/883210