Apache Felix Maven-Bundle-Plugin 则使用另一套机制:使用Maven-Bundle-Plugin,在开发时可以没有MANIFEST.MF文件!Maven-Bundle-Plugin在pom.xml中复制了一套MANIFEST.MF的元数据,完全可以通过pom.xml文件中的定义生成出完整的MANIFEST.MF文件。
"JBoss Fuse combines core Enterprise Service Bus capabilities (based on Apache Camel, Apache CXF, Apache ActiveMQ), Apache Karaf and Fuse Fabric in a single integrated distribution."
”Apache ServiceMix is a flexible, open-source integration container that unifies the features and functionality of Apache ActiveMQ, Camel, CXF, ODE, Karaf into a powerful runtime platform you can use to build your own integrations solutions. It provides a complete, enterprise ready ESB exclusively powered by OSGi.“
OHLCSeries ohlcSeries = new OHLCSeries(""); TimeSeries volumeSeries =new TimeSeries("");
try{ URL url = new URL("http://table.finance.yahoo.com/table.csv?ignore=.csv&s=000001.ss&a=00&b=01&c=2013&d=11&e=31&f=2013&g=d"); InputStream is = url.openStream(); InputStreamReader reader = new InputStreamReader(is,"UTF-8");
BufferedReader buffer = new BufferedReader(reader);
String newLine = buffer.readLine();// 标题行
while ((newLine = buffer.readLine()) != null) { String item[] = newLine.trim().split(","); Date date = df.parse(item[0]); float open = Float.valueOf(item[1]); float high = Float.valueOf(item[2]); float low = Float.valueOf(item[3]); float close = Float.valueOf(item[4]); float volume = Float.valueOf(item[5]); float adj_close = Float.valueOf(item[6]);
public class MyActivator implements org.osgi.framework.BundleActivator{
@Override public void start(BundleContext context) throws Exception { context.registerService(MyService.class.getName(), new MyServiceImpl(), null); System.out.println(MyService.class.getName() + " has been registred as a service"); } …… }
// Method will be used by DS to set the service public synchronized void setMyService(MyService service) { System.out.println("Service was set. Thank you DS!"); this.service = service; }
// Method will be used by DS to unset the service public synchronized void unsetMyService(MyService service) { System.out.println("Service was unset."); if (this.service == service) { this.service = null; }
// Tracks the active part @Inject @Optional public void receiveActivePart(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) { if (activePart != null) { System.out.println("Active part changed " + activePart.getLabel()); } }
// tracks the active shell @Inject @Optional public void receiveActiveShell(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { if (shell != null) { System.out.println("Active shell (Window) changed"); } }
Activate and deactivate key bindings defined as BindingContext in the application model. The content referred to in this service is the BindingContext and not the IEclipseContext.
Logger
org.eclipse.e4.core.services插件中的Logger提供了日志功能
Adapter
An adapter can adapt an object to the specified type, allowing clients to request domain-specific behavior for an object. It integrates IAdaptable and IAdapterManager
// Showing and hiding parts detailsTodoPart = partService.findPart("com.example.todo.rcp.parts.tododetails"); partService.hidePart(detailsTodoPart); …… detailsTodoPart.setVisible(true); partService.showPart(detailsTodoPart, PartState.VISIBLE);
//Switching perspectives @Execute public void execute(MApplication app, EPartService partService, EModelService modelService) { MPerspective element = (MPerspective) modelService.find("secondperspective", app); // now switch perspective partService.switchPerspective(element); }
// creating parts dynamically @Execute public void execute(EPartService partService) {
// create a new Part based on a PartDescriptor // in the application model // assume the ID is used for the PartDescriptor MPart part = partService .createPart("com.example.e4.rcp.todo.partdescriptor.fileeditor"); part.setLabel("New Dynamic Part");
// If multiple parts of this type are now allowed // in the application model, // then the provided part will be shown // and returned partService.showPart(part, PartState.ACTIVATE); }
//switch perspective @Execute public void execute(MApplication app, EPartService partService, EModelService modelService) { MPerspective element = (MPerspective) modelService.find("secondperspective", app); partService.switchPerspective(element); }
@PostConstruct public void createControls(Composite parent) { Button button = new Button(parent, SWT.PUSH); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { dirty.setDirty(true); } }); }
@Persist public void save(MDirtyable dirty, ITodoService todoService) { // save changes via ITodoService for example todoService.saveTodo(todo); // save was successful dirty.setDirty(false); } }
//or use code: Logger log = (Logger) context.get(Logger.class.getName());
# 实现自己的服务
Usually services have two parts: the interface definition and the implementation. How these two are linked is defined by a context function , an OSGi service or plain context value setting (IEclipseContext). Please note that there can be more than one service implementation for an interface.