-
1. Re: Supporting OSGi properties via qualifiers
kabirkhan Dec 23, 2009 10:03 AM (in response to kabirkhan)kabir.khan@jboss.com wrote:
The JIRA sub-task: https://jira.jboss.org/jira/browse/JBKERNEL-70
The plumbing for supporting new/unanticipated qualifier types has been done in kernel. See BeanQualifiersTestCase.testCustomMatcherAndParser() for an example.
Briefly there is a new package org.jboss.kernel.spi.qualifier:
QualfierMatchers contains a registry of QualfierMatchers and QualifierParsers
When parsing the qualifier metadata to populate the MDR and the injection point qualifiers, the correct QualifierParser for the QualifierContent type is used.
- The STRING implementation just returns the original qualifier object
- The ANNOTATION implementation parses the qualifier object into an annotation
The parse() methods take reference to a ClassLoader, although I am not using that yet, e.g.;
Object parseWanted(ClassLoader cl, Object rawQualifier);
Next when the matching is done by ClassAndQualifierKey, it iterates over each wanted qualifiers and calls QualifierMatchers:
public boolean matches(ControllerContext context, Set<Object> suppliedQualifiers, Object qualifier)
qualifier is the wanted qualifier, then we iterate over each context passing in the context and its suppliedQualifiers. Internally this checks the class of the wanted qualifier and uses the corresponding matcher. If no matcher exists for that type, it uses a default implementation which returns true if qualifier exists in suppliedQualifiers.
To do the OSGi property matching I imagine you would do something like:
Create and add a QualifierParser for a PROPERTY content type, which
- parses supplied qualifiers into a Dictionary
- parses wanted qualifiers (e.g. "(!(cn=Tim Howes))") into some LdapMatcher
Create and add a QualifierMatcher for LdapMatcher, with a matches() method that iterates over each supplied qualifier and if that is of type Dictionary, check that Dictionary for entries that were specified in the data used to create the LdapMatcher.