users@glassfish.java.net

Re: NPE - java.lang.reflect.UndeclaredThrowableException

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Fri, 03 Feb 2012 22:03:24 +0530

I am surprised you asked this. You should be able to fix that
compilation error by making ds a public field in SessionHandleImpl or
adding a suitable setter method - whatever...

Sahoo
On Friday 03 February 2012 09:24 PM, forums_at_java.net wrote:
> 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
>
>