Search in sources :

Example 1 with Designate

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");
}
Also used : Dictionary(java.util.Dictionary) ResourceProcessorException(org.osgi.service.deploymentadmin.spi.ResourceProcessorException) Designate(org.apache.felix.metatype.Designate) OCD(org.apache.felix.metatype.OCD) Filter(org.osgi.framework.Filter) MetaData(org.apache.felix.metatype.MetaData) DesignateObject(org.apache.felix.metatype.DesignateObject) ArrayList(java.util.ArrayList) List(java.util.List) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Example 2 with Designate

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);
            }
        }
    }
}
Also used : OCD(org.apache.felix.metatype.OCD) DesignateObject(org.apache.felix.metatype.DesignateObject) Iterator(java.util.Iterator) Designate(org.apache.felix.metatype.Designate) DefaultMetaTypeProvider(org.apache.felix.metatype.DefaultMetaTypeProvider) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Designate (org.apache.felix.metatype.Designate)2 DesignateObject (org.apache.felix.metatype.DesignateObject)2 OCD (org.apache.felix.metatype.OCD)2 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 DefaultMetaTypeProvider (org.apache.felix.metatype.DefaultMetaTypeProvider)1 MetaData (org.apache.felix.metatype.MetaData)1 Filter (org.osgi.framework.Filter)1 ResourceProcessorException (org.osgi.service.deploymentadmin.spi.ResourceProcessorException)1 ObjectClassDefinition (org.osgi.service.metatype.ObjectClassDefinition)1