use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class BundleComponentActivator method loadDescriptor.
private void loadDescriptor(final URL descriptorURL) {
// simple path for log messages
final String descriptorLocation = descriptorURL.getPath();
InputStream stream = null;
try {
stream = descriptorURL.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
XmlHandler handler = new XmlHandler(m_bundle, this, getConfiguration().isFactoryEnabled(), getConfiguration().keepInstances());
KXml2SAXParser parser;
parser = new KXml2SAXParser(in);
parser.parseXML(handler);
// or one or more component elements embedded in a larger document
for (Object o : handler.getComponentMetadataList()) {
ComponentMetadata metadata = (ComponentMetadata) o;
ComponentRegistryKey key = null;
try {
// check and reserve the component name (if not null)
if (metadata.getName() != null) {
key = m_componentRegistry.checkComponentName(m_bundle, metadata.getName());
}
// validate the component metadata
metadata.validate(this);
// Request creation of the component manager
ComponentHolder<?> holder = m_componentRegistry.createComponentHolder(this, metadata);
// register the component after validation
m_componentRegistry.registerComponentHolder(key, holder);
m_holders.add(holder);
log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] ComponentHolder created for {1}", new Object[] { m_bundle.getBundleId(), metadata.getName() }, null, null, null);
} catch (Throwable t) {
// There is a problem with this particular component, we'll log the error
// and proceed to the next one
log(LogService.LOG_ERROR, "Cannot register Component", metadata, null, t);
// make sure the name is not reserved any more
if (key != null) {
m_componentRegistry.unregisterComponentHolder(key);
}
}
}
} catch (IOException ex) {
// 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
// fragments, SCR must log an error message with the Log Service, if present, and continue.
log(LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[] { descriptorLocation }, null, null, ex);
} catch (Exception ex) {
log(LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''", new Object[] { descriptorLocation }, null, null, ex);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class SCRCheck method check.
@Override
public void check(final CheckContext ctx) throws IOException, MojoExecutionException {
ctx.getLog().info("Checking for SCR descriptor...");
final String val = ctx.getManifest().getMainAttributes().getValue("Service-Component");
if (val != null) {
final String[] components = val.split(",");
for (final String cmp : components) {
final File xmlFile = new File(ctx.getRootDir(), cmp.trim().replace('/', File.separatorChar));
if (!xmlFile.exists()) {
throw new MojoExecutionException("SCR descriptor file '" + cmp + "' not found in bundle");
}
final List<ComponentMetadata> mList = loadDescriptor(ctx, xmlFile);
for (final ComponentMetadata md : mList) {
check(ctx, md);
}
}
}
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class BindMethodTest method newMetadata.
private ComponentMetadata newMetadata() {
ComponentMetadata metadata = new ComponentMetadata(DSVersion.DS11);
metadata.setName("foo");
metadata.setImplementationClassName(Object.class.getName());
metadata.validate(null);
return metadata;
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class ConfiguredComponentHolderTest method test_singleton.
public void test_singleton() {
// setup a holder
final String name = "test.singleton";
final ComponentMetadata cm = createComponentMetadata(name);
final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder(cm);
holder.enableComponents(false);
// assert single component and no map
final SingleComponentManager cmgr = getSingleManager(holder);
assertNotNull("Expect single component manager", cmgr);
assertEquals("Expect no other component manager list", 1, getComponentManagers(holder).size());
// configure with the singleton configuration
final Dictionary config = new Hashtable();
config.put("value", name);
TargetedPID targetedPid = new TargetedPID(name);
holder.configurationUpdated(targetedPid, null, config, 0);
// assert single component and no map
final SingleComponentManager cmgrAfterConfig = getSingleManager(holder);
assertNotNull("Expect single component manager", cmgrAfterConfig);
assertEquals("Expect no other component manager list", 1, getComponentManagers(holder).size());
// // assert configuration of single component
final Map componentConfig = ((MockImmediateComponentManager) cmgrAfterConfig).getConfiguration();
assertEquals("Expect exact configuration set", config, componentConfig);
// unconfigure singleton
holder.configurationDeleted(targetedPid, null);
// assert single component and no map
final SingleComponentManager cmgrAfterUnconfig = getSingleManager(holder);
assertNotNull("Expect single component manager", cmgrAfterUnconfig);
assertEquals("Expect no other component manager list", 1, getComponentManagers(holder).size());
// assert no configuration of single component
// TODO multipids fix, correct assertion assertFalse( "Expect no configuration", cmgrAfterUnconfig.hasConfiguration() );
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class ConfiguredComponentHolderTest method test_none.
public void test_none() {
// setup a holder
final String name = "test.none";
final ComponentMetadata cm = createComponentMetadata(name);
final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder(cm);
holder.enableComponents(false);
// assert single component and no map
final SingleComponentManager cmgr = getSingleManager(holder);
assertNotNull("Expect single component manager", cmgr);
assertEquals("Expect no other component manager list", 1, getComponentManagers(holder).size());
}
Aggregations