下面列出了org.osgi.framework.ServiceListener#org.osgi.service.component.ComponentInstance 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
*/
ComponentInstance newInstance(Dictionary<String,Object> instanceProps) {
if (!isSatisfied()) {
throw new ComponentException("Factory is not satisfied");
}
String ccId = cmConfig.isEmpty() ? NO_CCID : cmConfig.getCCIds()[0];
final ComponentConfiguration cc = newComponentConfiguration(ccId, instanceProps);
scr.postponeCheckin();
ComponentContextImpl cci;
try {
cci = cc.activate(null, true);
} finally {
scr.postponeCheckout();
}
if (isSatisfied()) {
cc.registerComponentService(null);
return cci.getComponentInstance();
} else {
// Make sure it is disposed, perhaps we should "lock" protect this code instead
cc.dispose(KF_DEACTIVATION_REASON_COMPONENT_DEACTIVATING, true);
throw new ComponentException("Factory is/has been deactivated");
}
}
/**
* @see org.apache.felix.scr.Component.getComponentInstance
*/
public ComponentInstance getComponentInstance() {
final ComponentConfiguration cc = getFirstComponentConfiguration();
if (cc != null) {
// TODO: what about factories
final ComponentContext ctxt = cc.getActiveContext(null, null);
if (ctxt != null) {
return ctxt.getComponentInstance();
}
}
return null;
}
/**
*
*/
public ComponentInstance newInstance(@SuppressWarnings("rawtypes") Dictionary instanceProps) {
final FactoryComponent fc = factoryComponent;
if (fc != null) {
@SuppressWarnings("unchecked")
final
Dictionary<String, Object> ip = instanceProps;
return fc.newInstance(ip);
}
throw new ComponentException("Component factory has been disposed");
}
@Override
synchronized ComponentContextImpl getContext(Bundle b, Object instance) {
if (instance != null) {
for (ComponentContextImpl cci : ccis) {
ComponentInstance ci = cci.getComponentInstance();
if (ci != null && ci.getInstance() == instance) {
return cci;
}
}
}
return null;
}
@Override
public ComponentInstance getComponentInstance() {
return null;
}
/**
*
*/
public ComponentInstance getComponentInstance() {
return componentInstance;
}
@Override
public ComponentInstance getComponentInstance() {
return null;
}
@Override
public ComponentInstance getComponentInstance() {
return null;
}
@Override
public ComponentInstance getComponentInstance() {
return null;
}
@Override
public ComponentInstance getComponentInstance() {
throw new NoSuchMethodError("Unimplemented method");
}
@Override
public ComponentInstance getComponentInstance() {
throw new NoSuchMethodError("Unimplemented method");
}
@Override
public ComponentInstance getComponentInstance() {
throw new NoSuchMethodError("Unimplemented method");
}
@Override
public ComponentInstance getComponentInstance() {
return null;
}
/**
* Returns the <code>org.osgi.service.component.ComponentInstance</code>
* representing this component or <code>null</code> if this component
* is not been activated yet.
*
* @since 1.2
*/
ComponentInstance getComponentInstance();