View Javadoc

1   /*
2    * Copyright 2006-2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.osgi.extender.event;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.osgi.framework.Bundle;
24  import org.osgi.framework.Filter;
25  import org.springframework.context.ApplicationContext;
26  import org.springframework.osgi.context.event.OsgiBundleContextFailedEvent;
27  import org.springframework.osgi.service.importer.event.OsgiServiceDependencyEvent;
28  
29  /**
30   * Bootstrapping event indicating a context has failed to initializsed due to unsatisfied mandatory dependencies.
31   * 
32   * @author Costin Leau
33   */
34  public class BootstrappingDependenciesFailedEvent extends OsgiBundleContextFailedEvent {
35  
36  	private final Collection<OsgiServiceDependencyEvent> dependencyEvents;
37  	private final Collection<String> dependencyFilters;
38  	private final Filter dependenciesFilter;
39  
40  	public BootstrappingDependenciesFailedEvent(ApplicationContext source, Bundle bundle, Throwable th,
41  			Collection<OsgiServiceDependencyEvent> nestedEvents, Filter filter) {
42  		super(source, bundle, th);
43  
44  		this.dependencyEvents = nestedEvents;
45  		this.dependenciesFilter = filter;
46  
47  		List<String> depFilters = new ArrayList<String>(dependencyEvents.size());
48  
49  		for (OsgiServiceDependencyEvent dependency : nestedEvents) {
50  			depFilters.add(dependency.getServiceDependency().getServiceFilter().toString());
51  		}
52  
53  		dependencyFilters = Collections.unmodifiableCollection(depFilters);
54  	}
55  
56  	/**
57  	 * Returns the nested, dependency event that caused the bootstrapping event to be raised.
58  	 * 
59  	 * @return associated dependency event
60  	 */
61  	public Collection<OsgiServiceDependencyEvent> getDependencyEvents() {
62  		return dependencyEvents;
63  	}
64  
65  	public Filter getDependenciesAsFilter() {
66  		return dependenciesFilter;
67  	}
68  
69  	public Collection<String> getDependencyFilters() {
70  		return dependencyFilters;
71  	}
72  }