@Override @SuppressWarnings("unchecked") public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers) { return getServiceLocator().getAllServiceHandles(contract, qualifiers).stream() .map(sh -> new ServiceHolderImpl<>( sh.getService(), (Class<T>) sh.getActiveDescriptor().getImplementationClass(), sh.getActiveDescriptor().getContractTypes(), sh.getActiveDescriptor().getRanking())) .collect(Collectors.toList()); }
@Override @SuppressWarnings("unchecked") public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers) { return getServiceLocator().getAllServiceHandles(contract, qualifiers).stream() .map(sh -> new ServiceHolderImpl<>( sh.getService(), (Class<T>) sh.getActiveDescriptor().getImplementationClass(), sh.getActiveDescriptor().getContractTypes(), sh.getActiveDescriptor().getRanking())) .collect(Collectors.toList()); }
@Override public Injectee apply(CacheKey cacheKey) { Injectee injectee = cacheKey.getInjectee(); if (injectee.getParent() != null) { if (Field.class.isAssignableFrom(injectee.getParent().getClass())) { Field f = (Field) injectee.getParent(); if (foreignRequestScopedComponents.get().contains(f.getDeclaringClass())) { final Class<?> clazz = f.getType(); if (serviceLocator.getServiceHandle(clazz).getActiveDescriptor().getScopeAnnotation() == RequestScoped.class) { final AbstractActiveDescriptor<Object> descriptor = BuilderHelper.activeLink(clazz) .to(clazz) .in(RequestScoped.class) .build(); return new DescriptorOverridingInjectee(injectee, descriptor); } } } } return injectee; } });
@Override public Injectee apply(CacheKey cacheKey) { Injectee injectee = cacheKey.getInjectee(); if (injectee.getParent() != null) { if (Field.class.isAssignableFrom(injectee.getParent().getClass())) { Field f = (Field) injectee.getParent(); if (foreignRequestScopedComponents.get().contains(f.getDeclaringClass())) { final Class<?> clazz = f.getType(); if (serviceLocator.getServiceHandle(clazz).getActiveDescriptor().getScopeAnnotation() == RequestScoped.class) { final AbstractActiveDescriptor<Object> descriptor = BuilderHelper.activeLink(clazz) .to(clazz) .in(RequestScoped.class) .build(); return new DescriptorOverridingInjectee(injectee, descriptor); } } } } return injectee; } });
/** * probably a bit slow, calculates all the @Configured interfaces subclassing, useful * to find all possible subclasses of a type. * * @throws ClassNotFoundException */ private void initXRef() throws ClassNotFoundException { // force initialization of all the config models. for (ServiceHandle<?> i : habitat.getAllServiceHandles(ConfigInjector.class)) { buildModel((ActiveDescriptor<? extends ConfigInjector>) i.getActiveDescriptor()); } for (ConfigModel cm : models.values()) { Class targetType = cm.classLoaderHolder.loadClass(cm.targetTypeName); do { Class[] intfs = targetType.getInterfaces(); for (Class intf : intfs) { if (intf.isAnnotationPresent(Configured.class)) { addXRef(intf, cm); } } targetType = targetType.getSuperclass(); } while (targetType!=null); } }
public void lookupAllInjectors() { String[] expected = { SimpleConnectorInjector.class.getName(), EjbContainerAvailabilityInjector.class.getName(), WebContainerAvailabilityInjector.class.getName(), GenericContainerInjector.class.getName(), GenericConfigInjector.class.getName() }; List<String> expectedInjectors = Arrays.asList(expected); List<ServiceHandle<ConfigInjector>> inhabitants = habitat.getAllServiceHandles(ConfigInjector.class); Set<String> inhabitantNames = new HashSet<String>(); for (ServiceHandle<?> inh : inhabitants) { inhabitantNames.add(inh.getActiveDescriptor().getImplementation()); } assert(inhabitants.size() == expected.length); assert(inhabitantNames.containsAll(expectedInjectors)); }
public void lookupInjectorByName() { ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); ServiceHandle inhabitant2 = habitat.getServiceHandle(ConfigInjector.class, "ejb-container-availability"); assert(inhabitant1 != null && inhabitant2 != null && inhabitant1.getActiveDescriptor().getImplementation().equals(SimpleConnectorInjector.class.getName()) && inhabitant2.getActiveDescriptor().getImplementation().equals(EjbContainerAvailabilityInjector.class.getName())); }
@Override public int compare(ServiceHandle<?> o1, ServiceHandle<?> o2) { return baseComparator.compare(o1.getActiveDescriptor(), o2.getActiveDescriptor()); }
private static String oneLineRoot(ServiceHandle<?> root) { if (root == null) return "null-root"; root.getActiveDescriptor(); return "root(" + oneLineDescriptor(root.getActiveDescriptor()) + "," + System.identityHashCode(root) + ")"; } }
private static boolean debugCommand(ServiceHandle<?> command) { ActiveDescriptor<?> ad = command.getActiveDescriptor(); Map<String, List<String>> metadata = ad.getMetadata(); List<String> modes = metadata.get(MODE); if (modes == null) return false; for (String mode : modes) { if (DEBUG.equals(mode)) return true; } return false; }
/** * Gets one value from a metadata field from the given service handle * * @param h The non-null service handle from which to get the first value in the given field * @param field The non-null field to get the first value of * @return The first value in the given field, or null if no such field exists in the descriptor */ public static String getOneMetadataField(ServiceHandle<?> h, String field) { return getOneMetadataField(h.getActiveDescriptor(), field); }
/** * Gets one value from a metadata field from the given service handle * * @param h The non-null service handle from which to get the first value in the given field * @param field The non-null field to get the first value of * @return The first value in the given field, or null if no such field exists in the descriptor */ public static String getOneMetadataField(ServiceHandle<?> h, String field) { return getOneMetadataField(h.getActiveDescriptor(), field); }
/** * Gets one value from a metadata field from the given service handle * * @param h The non-null service handle from which to get the first value in the given field * @param field The non-null field to get the first value of * @return The first value in the given field, or null if no such field exists in the descriptor */ public static String getOneMetadataField(ServiceHandle<?> h, String field) { return getOneMetadataField(h.getActiveDescriptor(), field); }
/** * Gets one value from a metadata field from the given service handle * * @param h The non-null service handle from which to get the first value in the given field * @param field The non-null field to get the first value of * @return The first value in the given field, or null if no such field exists in the descriptor */ public static String getOneMetadataField(ServiceHandle<?> h, String field) { return getOneMetadataField(h.getActiveDescriptor(), field); }
public static List<ConfigurationDeploymentDescriptorFile> getConfigurationDeploymentDescriptorFiles(ServiceLocator habitat, String containerType) { List<ConfigurationDeploymentDescriptorFile> confDDFiles = new ArrayList<ConfigurationDeploymentDescriptorFile>(); for (ServiceHandle<?> serviceHandle : habitat.getAllServiceHandles(ConfigurationDeploymentDescriptorFileFor.class)) { ActiveDescriptor<?> descriptor = serviceHandle.getActiveDescriptor(); String indexedType = descriptor.getMetadata().get(ConfigurationDeploymentDescriptorFileFor.DESCRIPTOR_FOR).get(0); if(indexedType.equals(containerType)) { ConfigurationDeploymentDescriptorFile confDD = (ConfigurationDeploymentDescriptorFile) serviceHandle.getService(); confDDFiles.add(confDD); } } return confDDFiles; }
@Override @SuppressWarnings("unchecked") public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers) { return getServiceLocator().getAllServiceHandles(contract, qualifiers).stream() .map(sh -> new ServiceHolderImpl<>( sh.getService(), (Class<T>) sh.getActiveDescriptor().getImplementationClass(), sh.getActiveDescriptor().getContractTypes(), sh.getActiveDescriptor().getRanking())) .collect(Collectors.toList()); }
@Override @SuppressWarnings("unchecked") public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers) { return getServiceLocator().getAllServiceHandles(contract, qualifiers).stream() .map(sh -> new ServiceHolderImpl<>( sh.getService(), (Class<T>) sh.getActiveDescriptor().getImplementationClass(), sh.getActiveDescriptor().getContractTypes(), sh.getActiveDescriptor().getRanking())) .collect(Collectors.toList()); }
private void callAllConfigurationListeners(List<ServiceHandle<?>> allListeners) { if (allListeners == null) return; for (ServiceHandle<?> listener : allListeners) { ActiveDescriptor<?> listenerDescriptor = listener.getActiveDescriptor(); if (listenerDescriptor.getLocatorId() != id) continue; try { ((DynamicConfigurationListener) listener.getService()).configurationChanged(); } catch (Throwable th) { // Intentionally ignore } } }
private void callAllConfigurationListeners(List<ServiceHandle<?>> allListeners) { if (allListeners == null) return; for (ServiceHandle<?> listener : allListeners) { ActiveDescriptor<?> listenerDescriptor = listener.getActiveDescriptor(); if (listenerDescriptor.getLocatorId() != id) continue; try { ((DynamicConfigurationListener) listener.getService()).configurationChanged(); } catch (Throwable th) { // Intentionally ignore } } }
public void lookupInjectorByName() { ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); ServiceHandle inhabitant2 = habitat.getServiceHandle(ConfigInjector.class, "ejb-container-availability"); assert(inhabitant1 != null && inhabitant2 != null && inhabitant1.getActiveDescriptor().getImplementation().equals(SimpleConnectorInjector.class.getName()) && inhabitant2.getActiveDescriptor().getImplementation().equals(EjbContainerAvailabilityInjector.class.getName())); }