use of org.apache.felix.metatype.Designate in project felix by apache.
the class StoreResourceTask method process.
public void process(String name, InputStream stream) throws ResourceProcessorException {
m_log.log(LogService.LOG_DEBUG, "processing " + name);
// initial validation
assertInDeploymentSession("Can not process resource without a Deployment Session");
Map<String, List<AutoConfResource>> toBeInstalled;
synchronized (m_lock) {
toBeInstalled = new HashMap<String, List<AutoConfResource>>(m_toBeInstalled);
}
MetaData data = parseAutoConfResource(stream);
// process resources
Filter filter = getFilter(data);
// add to session data
if (!toBeInstalled.containsKey(name)) {
toBeInstalled.put(name, new ArrayList<AutoConfResource>());
}
List<Designate> designates = data.getDesignates();
if (designates == null || designates.isEmpty()) {
// if there are no designates, there's nothing to process
m_log.log(LogService.LOG_INFO, "No designates found in the resource, so there's nothing to process.");
return;
}
Map<String, OCD> localOcds = data.getObjectClassDefinitions();
if (localOcds == null) {
localOcds = Collections.emptyMap();
}
for (Designate designate : designates) {
// check object
DesignateObject objectDef = designate.getObject();
if (objectDef == null) {
throw new ResourceProcessorException(CODE_OTHER_ERROR, "Designate Object child missing or invalid");
}
// check attributes
if (objectDef.getAttributes() == null || objectDef.getAttributes().isEmpty()) {
throw new ResourceProcessorException(CODE_OTHER_ERROR, "Object Attributes child missing or invalid");
}
// check ocdRef
String ocdRef = objectDef.getOcdRef();
if (ocdRef == null || "".equals(ocdRef)) {
throw new ResourceProcessorException(CODE_OTHER_ERROR, "Object ocdRef attribute missing or invalid");
}
// determine OCD
ObjectClassDefinition ocd = null;
OCD localOcd = localOcds.get(ocdRef);
// ask meta type service for matching OCD if no local OCD has been defined
ocd = (localOcd != null) ? new ObjectClassDefinitionImpl(localOcd) : getMetaTypeOCD(data, designate);
if (ocd == null) {
throw new ResourceProcessorException(CODE_OTHER_ERROR, "No Object Class Definition found with id=" + ocdRef);
}
// determine configuration data based on the values and their type definition
Dictionary dict = MetaTypeUtil.getProperties(designate, ocd);
if (dict == null) {
// designate does not match it's definition, but was marked optional, ignore it
continue;
}
AutoConfResource resource = new AutoConfResource(name, designate.getPid(), designate.getFactoryPid(), designate.getBundleLocation(), designate.isMerge(), dict, filter);
toBeInstalled.get(name).add(resource);
}
synchronized (m_lock) {
m_toBeInstalled.putAll(toBeInstalled);
}
m_log.log(LogService.LOG_DEBUG, "processing " + name + " done");
}
use of org.apache.felix.metatype.Designate in project felix by apache.
the class MetaTypeInformationImpl method addMetaData.
// ---------- setters to fill the values -----------------------------------
protected void addMetaData(MetaData md) {
if (md.getDesignates() != null) {
// meta type provide to register by PID
DefaultMetaTypeProvider dmtp = new DefaultMetaTypeProvider(this.bundle, md);
Iterator designates = md.getDesignates().iterator();
while (designates.hasNext()) {
Designate designate = (Designate) designates.next();
// get the OCD reference, ignore the designate if none
DesignateObject object = designate.getObject();
String ocdRef = (object == null) ? null : object.getOcdRef();
if (ocdRef == null) {
continue;
}
// get ocd for the reference, ignore designate if none
final Map map = md.getObjectClassDefinitions();
OCD ocd = (OCD) (map == null ? null : map.get(ocdRef));
if (ocd == null) {
continue;
}
// gather pids and factory pids and register provider
if (designate.getFactoryPid() != null) {
this.factoryPids.add(designate.getFactoryPid());
this.addMetaTypeProvider(designate.getFactoryPid(), dmtp);
} else {
this.pids.add(designate.getPid());
this.addMetaTypeProvider(designate.getPid(), dmtp);
}
}
}
}
Aggregations