import java.util.Map;
import java.util.TreeMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsException;
import org.argeo.node.DataModelNamespace;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleWiring;
class DataModels implements BundleListener {
+ private final static Log log = LogFactory.getLog(DataModels.class);
+
private Map<String, DataModel> dataModels = new TreeMap<>();
public DataModels(BundleContext bc) {
protected void processBundle(Bundle bundle) {
BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ if (wiring == null) {
+ log.warn("Bundle " + bundle.getSymbolicName() + " #" + bundle.getBundleId() + " (" + bundle.getLocation()
+ + ") cannot be adapted to a wiring");
+ return;
+ }
List<BundleCapability> providedDataModels = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
if (providedDataModels.size() == 0)
return;
List<BundleWire> requiredDataModels = wiring.getRequiredWires(CMS_DATA_MODEL_NAMESPACE);
+ // process requirements first
+ for (BundleWire bundleWire : requiredDataModels) {
+ processBundle(bundleWire.getProvider().getBundle());
+ }
for (BundleCapability bundleCapability : providedDataModels) {
- DataModel dataModel = new DataModel(bundleCapability, requiredDataModels);
- dataModels.put(dataModel.getName(), dataModel);
+ String name = (String) bundleCapability.getAttributes().get(DataModelNamespace.NAME);
+ assert name != null;
+ if (!dataModels.containsKey(name)) {
+ DataModel dataModel = new DataModel(name, bundleCapability, requiredDataModels);
+ dataModels.put(dataModel.getName(), dataModel);
+ }
}
}
private final String cnd;
private final List<DataModel> required;
- private DataModel(BundleCapability bundleCapability, List<BundleWire> requiredDataModels) {
+ private DataModel(String name, BundleCapability bundleCapability, List<BundleWire> requiredDataModels) {
assert CMS_DATA_MODEL_NAMESPACE.equals(bundleCapability.getNamespace());
+ this.name = name;
Map<String, Object> attrs = bundleCapability.getAttributes();
- name = (String) attrs.get(DataModelNamespace.NAME);
- assert name != null;
abstrct = KernelUtils.asBoolean((String) attrs.get(DataModelNamespace.ABSTRACT));
// standalone = KernelUtils.asBoolean((String)
// attrs.get(DataModelNamespace.CAPABILITY_STANDALONE_ATTRIBUTE));