use of org.apache.felix.metatype.OCD 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.OCD 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);
}
}
}
}
use of org.apache.felix.metatype.OCD in project fabric8 by jboss-fuse.
the class ProfileMetadata method addMetaData.
protected void addMetaData(MetaTypeSummaryDTO summary, MetaData metadata, Properties resources) {
Map<String, Object> map = metadata.getDesignates();
Map<String, Object> objects = metadata.getObjectClassDefinitions();
Set<Map.Entry<String, Object>> entries = map.entrySet();
for (Map.Entry<String, Object> entry : entries) {
String pid = entry.getKey();
Object value = objects.get(pid);
if (value instanceof OCD) {
OCD ocd = (OCD) value;
MetaTypeObjectSummaryDTO object = summary.getOrCreateMetaTypeSummaryDTO(pid);
object.setId(pid);
object.setName(localize(resources, ocd.getName()));
object.setDescription(localize(resources, ocd.getDescription()));
}
}
}
use of org.apache.felix.metatype.OCD in project fabric8 by jboss-fuse.
the class ProfileMetadata method getPidMetaTypeObject.
@Override
public MetaTypeObjectDTO getPidMetaTypeObject(String versionId, String profileId, final String pid) throws Exception {
final AtomicReference<MetaTypeObjectDTO> answer = new AtomicReference<>(null);
MetadataHandler handler = new MetadataHandler() {
@Override
public void invoke(MetaData metadata, Properties resources) {
Map<String, Object> map = metadata.getDesignates();
Map<String, Object> objects = metadata.getObjectClassDefinitions();
Set<Map.Entry<String, Object>> entries = map.entrySet();
for (Map.Entry<String, Object> entry : entries) {
String aPid = entry.getKey();
Object value = objects.get(aPid);
if (Objects.equal(pid, aPid) && value instanceof OCD) {
OCD ocd = (OCD) value;
answer.set(createMetaTypeObjectDTO(resources, ocd));
}
}
}
};
findMetadataForProfile(versionId, profileId, handler);
return answer.get();
}
use of org.apache.felix.metatype.OCD in project bndtools by bndtools.
the class CapabilityBasedTemplate method getMetadata.
@Override
public ObjectClassDefinition getMetadata(IProgressMonitor monitor) throws Exception {
String resourceId = ResourceUtils.getIdentityCapability(capability.getResource()).osgi_identity();
final CompositeOCD compositeOcd = new CompositeOCD(name, description, null);
if (metaTypePath != null) {
try (JarFile bundleJarFile = new JarFile(fetchBundle())) {
JarEntry metaTypeEntry = bundleJarFile.getJarEntry(metaTypePath);
try (InputStream entryInput = bundleJarFile.getInputStream(metaTypeEntry)) {
MetaData metaData = new MetaDataReader().parse(entryInput);
@SuppressWarnings("rawtypes") Map ocdMap = metaData.getObjectClassDefinitions();
if (ocdMap != null) {
if (ocdMap.size() == 1) {
@SuppressWarnings("unchecked") Entry<String, OCD> entry = (Entry<String, OCD>) ocdMap.entrySet().iterator().next();
// match.
if (ocdRef == null || ocdRef.equals(entry.getKey())) {
compositeOcd.addDelegate(new FelixOCDAdapter(entry.getValue()));
} else {
log(IStatus.WARNING, String.format("MetaType entry '%s' from resource '%s' did not contain an Object Class Definition with id '%s'", metaTypePath, resourceId, ocdRef), null);
}
} else {
// 'ocd' property.
if (ocdRef != null) {
OCD felixOcd = (OCD) ocdMap.get(ocdRef);
if (felixOcd != null) {
compositeOcd.addDelegate(new FelixOCDAdapter(felixOcd));
} else {
log(IStatus.WARNING, String.format("MetaType entry '%s' from resource '%s' did not contain an Object Class Definition with id '%s'", metaTypePath, resourceId, ocdRef), null);
}
} else {
log(IStatus.WARNING, String.format("MetaType entry '%s' from resource '%s' contains multiple Object Class Definitions, and no 'ocd' property was specified.", metaTypePath, resourceId), null);
}
}
}
}
}
}
// Add attribute definitions for any parameter names found in the templates and not already
// loaded from the Metatype XML.
ObjectClassDefinitionImpl ocdImpl = new ObjectClassDefinitionImpl(name, description, null);
ResourceMap inputs = getInputSources();
Map<String, String> params = engine.getTemplateParameters(inputs, monitor);
for (Entry<String, String> entry : params.entrySet()) {
AttributeDefinitionImpl ad = new AttributeDefinitionImpl(entry.getKey(), entry.getKey(), 0, AttributeDefinition.STRING);
if (entry.getValue() != null)
ad.setDefaultValue(new String[] { entry.getValue() });
ocdImpl.addAttribute(ad, true);
}
compositeOcd.addDelegate(ocdImpl);
return compositeOcd;
}
Aggregations