📄 activator.java
字号:
/* * WebCam Producer * * Copyright (C) 2004 Didier Donsez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contact: Didier Donsez (Didier.Donsez@ieee.org) * Contributor(s): ***/package fr.imag.adele.bundle.webcamproducer.impl;import java.io.InputStream;import java.util.Dictionary;import java.util.Enumeration;import java.util.Hashtable;import jmfdemo.FrameGrabber;import jmfdemo.FrameGrabberException;import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.BundleException;import org.osgi.framework.ServiceRegistration;import org.osgi.service.wireadmin.Producer;import fr.imag.adele.bundle.webcamproducer.ImageGrabber;/** * This activator read configuration properties from a file * and initialize a Producer service with these properties * and register it * * @version 1.0 22/02/2004 * @author Didier Donsez (Didier.Donsez@ieee.org) */public class Activator implements BundleActivator { protected BundleContext context = null; private FrameGrabber frameGrabber; private ServiceRegistration prodServReg; private ServiceRegistration imggrabServReg; /** * Called upon starting of the bundle. * * @param context The bundle context passed by the framework * @exception Exception */ public void start(BundleContext context) throws BundleException { this.context = context; // Load properties from configLocation file // and init the frame grabber try { InputStream is=config(context); if(is!=null) { frameGrabber = new FrameGrabber(is); } else { frameGrabber = new FrameGrabber(); } frameGrabber.start(); } catch (FrameGrabberException fge) { fge.printStackTrace(); throw new BundleException("Error creating frame grabber", fge); } Dictionary p; // instanciate the service implementation Producer prod=new ImageProducer(context,frameGrabber); // registered the ProducerService p=new Hashtable(); p.put( org.osgi.service.wireadmin.WireConstants.WIREADMIN_PRODUCER_FLAVORS, new Class[] { java.awt.Image.class }); p.put( org.osgi.framework.Constants.SERVICE_PID, "fr.imag.adele.osgi.util.webcam"); p.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "grabs a java.awt.Image from a WebCam"); prodServReg = context.registerService( Producer.class.getName(), prod, p); // instanciate the service implementation ImageGrabber imageGrabber=new ImageGrabberImpl(context,frameGrabber); // registered the ProducerService p=new Hashtable(); p.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "grabs a java.awt.Image from a WebCam"); imggrabServReg = context.registerService( ImageGrabber.class.getName(), imageGrabber, p ); } public void stop(BundleContext context) throws BundleException { frameGrabber.end(); } // configuration section protected static final String CONFIGFILE = "/config.properties"; protected InputStream config(BundleContext context) throws BundleException { // Get the Config-Location value from the manifest String configLocation = null; Dictionary dict = context.getBundle().getHeaders(); Enumeration enum1 = dict.keys(); while (enum1.hasMoreElements()) { Object nextKey = enum1.nextElement(); Object nextElem = dict.get(nextKey); if (nextKey.equals("Config-Location")) { configLocation = nextElem.toString(); break; } } if (configLocation == null) { configLocation = CONFIGFILE; } return getClass().getResourceAsStream(configLocation); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -