use of org.osgi.framework.ServiceReference in project opennms by OpenNMS.
the class OperationListShellCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
final List<Operation> operations = Lists.newArrayList();
final Map<Operation, Map<String, Object>> properties = new HashMap<>();
final Collection<ServiceReference<Operation>> services = this.bundleContext.getServiceReferences(Operation.class, null);
if (services == null)
return null;
for (final ServiceReference<Operation> sr : services) {
final Operation operation = this.bundleContext.getService(sr);
if (operation == null)
continue;
operations.add(operation);
final Map<String, Object> props = new TreeMap<>();
for (final String key : sr.getPropertyKeys()) {
props.put(key, sr.getProperty(key));
}
properties.put(operation, props);
}
// Output
for (final Operation operation : operations) {
final String operationClass = operation.getClass().getName();
System.out.println(" " + makeLine(operationClass));
System.out.println(" Class: " + operationClass);
System.out.println(" ID: " + operation.getId());
final Map<String, Object> props = properties.get(operation);
if (!props.isEmpty()) {
System.out.println(" Service Properties:");
for (final String key : props.keySet()) {
final Object object = props.get(key);
final String value = (object instanceof Object[]) ? Arrays.toString((Object[]) object) : object.toString();
System.out.println(" " + key + "=" + value);
}
}
}
return null;
}
use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.
the class TestVoltCSVFormatter method testBlankError.
@Test
public void testBlankError() throws Exception {
ServiceReference[] refs = m_bundle.getRegisteredServices();
ServiceReference<AbstractFormatterFactory> reference = refs[0];
AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
Properties prop = new Properties();
prop.setProperty("separator", ",");
prop.setProperty("blank", "error");
FormatterBuilder builder = new FormatterBuilder("csv", prop);
builder.setFormatterFactory(o);
Formatter formatter = builder.create();
try {
Object[] results = formatter.transform(ByteBuffer.wrap("12,,test".getBytes(StandardCharsets.UTF_8)));
fail();
} catch (RuntimeException e) {
}
}
use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.
the class TestVoltCSVFormatter method testQuoteChar.
//char separator, char quotechar, char escape, boolean strictQuotes, boolean ignoreLeadingWhiteSpace
@Test
public void testQuoteChar() throws Exception {
ServiceReference[] refs = m_bundle.getRegisteredServices();
ServiceReference<AbstractFormatterFactory> reference = refs[0];
AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
Properties prop = new Properties();
prop.setProperty("quotechar", "'");
FormatterBuilder builder = new FormatterBuilder("csv", prop);
builder.setFormatterFactory(o);
Formatter formatter = builder.create();
Object[] results = formatter.transform(ByteBuffer.wrap("12,'10.05,test'".getBytes(StandardCharsets.UTF_8)));
assertEquals(results.length, 2);
assertEquals(results[0], "12");
assertEquals(results[1], "10.05,test");
}
use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.
the class TestVoltCSVFormatter method testBadFormat.
@Test
public void testBadFormat() throws Exception {
ServiceReference[] refs = m_bundle.getRegisteredServices();
ServiceReference<AbstractFormatterFactory> reference = refs[0];
AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
Properties prop = new Properties();
FormatterBuilder builder = new FormatterBuilder("badformat", prop);
builder.setFormatterFactory(o);
try {
builder.create();
fail();
} catch (RuntimeException e) {
}
}
use of org.osgi.framework.ServiceReference in project voltdb by VoltDB.
the class TestVoltCSVFormatter method testTrimunquoted.
@Test
public void testTrimunquoted() throws Exception {
ServiceReference[] refs = m_bundle.getRegisteredServices();
ServiceReference<AbstractFormatterFactory> reference = refs[0];
AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
Properties prop = new Properties();
prop.setProperty("trimunquoted", "false");
FormatterBuilder builder = new FormatterBuilder("csv", prop);
builder.setFormatterFactory(o);
Formatter formatter = builder.create();
Object[] results = formatter.transform(ByteBuffer.wrap("12,10.05, test".getBytes(StandardCharsets.UTF_8)));
assertEquals(results.length, 3);
assertEquals(results[0], "12");
assertEquals(results[1], "10.05");
assertEquals(results[2], " test");
}
Aggregations