use of org.apache.openejb.config.sys.ServiceProvider in project tomee by apache.
the class ProviderManager method register.
private void register(final ID id, final ServiceProvider provider, final Set<ID> seen) {
if (providers.containsKey(id)) {
return;
}
if (provider.getParent() != null) {
final ID parentId = ID.parse(provider.getParent(), id);
// Pass in a stack on this call to prevent circular reference
final ServiceProvider parent = getProvider(parentId, seen);
if (parent == null) {
throw new NoSuchParentProviderException(provider, parentId);
}
inherit(provider, parent);
}
validate(id, provider);
providers.put(id, provider);
}
use of org.apache.openejb.config.sys.ServiceProvider in project tomee by apache.
the class ProviderManagerTest method testCircularDependency.
public void testCircularDependency() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.setParent("Orange");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
return null;
}
});
assertEquals(0, manager.getAll().size());
try {
manager.get("dEFAUlT", "orAngE");
fail("ProviderCircularReferenceException should have been thrown");
} catch (final ProviderCircularReferenceException e) {
// pass
}
}
use of org.apache.openejb.config.sys.ServiceProvider in project tomee by apache.
the class ProviderManagerTest method testLoaderLoadNamespace.
public void testLoaderLoadNamespace() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
final List<ServiceProvider> list = new ArrayList<>();
list.add(load(new ID(namespace, "color")));
list.add(load(new ID(namespace, "red")));
list.add(load(new ID(namespace, "orange")));
return list;
}
});
assertEquals(0, manager.getAll().size());
manager.get("default", "Color");
assertEquals(1, manager.getAll().size());
manager.load("default");
assertEquals(3, manager.getAll().size());
{
// Assert Orange
// Should have inherited from Red
final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("reD"));
assertEquals("200", provider.getProperties().get("grEeN"));
assertEquals("0", provider.getProperties().get("bLue"));
}
{
// Assert Red
// Should have inherited green and blue values from Color
final ServiceProvider provider = manager.get("dEFaulT", "REd");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("rED"));
assertEquals("0", provider.getProperties().get("grEEN"));
assertEquals("0", provider.getProperties().get("bLUe"));
}
{
// Assert Color
// Must be able to retrieve provider and properties in a case-insensitive manner
final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("0", provider.getProperties().getProperty("rEd"));
assertEquals("0", provider.getProperties().get("grEEn"));
assertEquals("0", provider.getProperties().get("blUE"));
}
assertEquals(3, manager.getAll().size());
}
use of org.apache.openejb.config.sys.ServiceProvider in project tomee by apache.
the class ConfigurationFactory method getServiceProvider.
private <T extends ServiceInfo> ServiceProvider getServiceProvider(final org.apache.openejb.config.Service service, final Class<? extends T> infoType) throws OpenEJBException {
final String providerType = getProviderType(service);
final ServiceProvider provider = resolveServiceProvider(service, infoType);
if (provider == null) {
final List<ServiceProvider> providers = ServiceUtils.getServiceProvidersByServiceType(providerType);
final StringBuilder sb = new StringBuilder();
final List<String> types = new ArrayList<>();
for (final ServiceProvider p : providers) {
for (final String type : p.getTypes()) {
if (types.contains(type)) {
continue;
}
types.add(type);
sb.append(JavaSecurityManagers.getSystemProperty("line.separator"));
sb.append(" <").append(p.getService());
sb.append(" id=\"").append(service.getId()).append('"');
sb.append(" type=\"").append(type).append("\"/>");
}
}
final String noProviderMessage = messages.format("configureService.noProviderForService", providerType, service.getId(), service.getType(), service.getProvider(), sb.toString());
throw new NoSuchProviderException(noProviderMessage);
}
if (!provider.getService().equals(providerType)) {
throw new OpenEJBException(messages.format("configureService.wrongProviderType", service.getId(), providerType));
}
return provider;
}
Aggregations