use of org.ops4j.util.property.PropertyResolver in project fabric8 by jboss-fuse.
the class Activator method updated.
public void updated(Dictionary<String, ?> config) {
PropertyResolver propertyResolver;
if (config == null) {
propertyResolver = new PropertyResolver() {
@Override
public String get(String propertyName) {
return m_bundleContext.getProperty(propertyName);
}
};
} else {
propertyResolver = new DictionaryPropertyResolver(config);
}
MavenConfiguration mavenConfig = new MavenConfigurationImpl(propertyResolver, PID);
MavenResolver resolver = new AetherBasedResolver(mavenConfig);
MavenResolver oldResolver = m_resolver.getAndSet(resolver);
ServiceRegistration<MavenResolver> registration = m_bundleContext.registerService(MavenResolver.class, resolver, null);
registration = m_resolverReg.getAndSet(registration);
if (registration != null) {
registration.unregister();
}
if (oldResolver != null) {
try {
oldResolver.close();
} catch (IOException e) {
// Ignore
}
}
}
use of org.ops4j.util.property.PropertyResolver in project karaf by apache.
the class FeaturesProcessingSerializer method read.
/**
* Reads {@link FeaturesProcessing features processing model} from input stream
* @param stream
* @param versions additional properties to resolve placeholders in features processing XML
* @return
*/
public FeaturesProcessing read(InputStream stream, Properties versions) throws Exception {
Unmarshaller unmarshaller = FEATURES_PROCESSING_CONTEXT.createUnmarshaller();
UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
// BundleContextPropertyResolver gives access to e.g., ${karaf.base}
final PropertyResolver resolver = bundleContext == null ? new DictionaryPropertyResolver(versions) : new DictionaryPropertyResolver(versions, new BundleContextPropertyResolver(bundleContext));
// indirect unmarshaling with property resolution inside XML attribute values and CDATA
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader xmlReader = spf.newSAXParser().getXMLReader();
xmlReader.setContentHandler(new ResolvingContentHandler(new Properties() {
@Override
public String getProperty(String key) {
return resolver.get(key);
}
@Override
public String getProperty(String key, String defaultValue) {
String value = resolver.get(key);
return value == null ? defaultValue : value;
}
}, handler));
xmlReader.parse(new InputSource(stream));
return (FeaturesProcessing) handler.getResult();
}
Aggregations