use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class ArchivistFactory method getExtensionsArchivists.
/**
* Gets all the classes for processing parts of a specified archive
* @param sniffers
* @param moduleType
* @return
* @see org.glassfish.webservices.archivist.WebServicesArchivist
* @see org.glassfish.ejb.deployment.archivist.EjbInWarArchivist
* @see com.sun.enterprise.deployment.archivist.PersistenceArchivist
*/
@SuppressWarnings("unchecked")
public List<ExtensionsArchivist> getExtensionsArchivists(Collection<Sniffer> sniffers, ArchiveType moduleType) {
Set<String> containerTypes = new HashSet<String>();
for (Sniffer sniffer : sniffers) {
containerTypes.add(sniffer.getModuleType());
}
List<ExtensionsArchivist> archivists = new ArrayList<ExtensionsArchivist>();
for (String containerType : containerTypes) {
List<ActiveDescriptor<?>> descriptors = habitat.getDescriptors(new ArchivistFilter(containerType, EXTENSION_ARCHIVE_TYPE, ExtensionsArchivist.class));
for (ActiveDescriptor<?> item : descriptors) {
ActiveDescriptor<ExtensionsArchivist> descriptor = (ActiveDescriptor<ExtensionsArchivist>) item;
ServiceHandle<ExtensionsArchivist> handle = habitat.getServiceHandle(descriptor);
ExtensionsArchivist ea = handle.getService();
if (ea.supportsModuleType(moduleType)) {
archivists.add(ea);
}
}
}
return archivists;
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class CDIExtension method beforeBeanDiscovery.
/**
* This method will ensure that the file which indicates that the
* application has shut down properly has been removed and then
* adds the HK2 service to the system
*
* @param beforeBeanDiscovery
*/
@SuppressWarnings("unused")
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery) {
File destructoFile = createDestructionFileObject();
if (destructoFile == null)
return;
if (destructoFile.exists()) {
if (destructoFile.delete() == false)
return;
}
ServiceLocator locator = getServiceLocator();
if (locator == null)
return;
Descriptor d = BuilderHelper.link(HK2ExtensionVerifier.class).in(Singleton.class.getName()).andLoadWith(new HK2LoaderImpl()).build();
// Just having the service present is enough for the first callback
ServiceLocatorUtilities.addOneDescriptor(locator, d);
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class ConfigModularityUtils method getAnnotatedConfigBeans.
public List<Class> getAnnotatedConfigBeans(Class annotationType) {
List<Class> prox = new ArrayList<Class>();
List<ActiveDescriptor<?>> descriptor = serviceLocator.getDescriptors(BuilderHelper.createContractFilter(ConfigInjector.class.getName()));
Class<?> clz = null;
for (ActiveDescriptor desc : descriptor) {
if (desc.getName() == null) {
continue;
}
ConfigInjector injector = serviceLocator.getService(ConfigInjector.class, desc.getName());
if (injector != null) {
String clzName = injector.getClass().getName().substring(0, injector.getClass().getName().length() - 8);
if (clzName == null) {
continue;
}
try {
clz = injector.getClass().getClassLoader().loadClass(clzName);
if (clz == null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Cannot find the class mapping to: " + clzName);
}
continue;
}
} catch (Throwable e) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Cannot load the class", e);
}
continue;
}
}
if (clz != null) {
if (clz.isAnnotationPresent(annotationType)) {
prox.add(clz);
}
}
}
return prox;
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class CreateResourceRef method chooseRefContainer.
private RefContainer chooseRefContainer(final AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Class<?>[] allInterfaces = resourceOfInterest.getClass().getInterfaces();
for (Class<?> resourceInterface : allInterfaces) {
ResourceConfigCreator resourceConfigCreator = (ResourceConfigCreator) resourceInterface.getAnnotation(ResourceConfigCreator.class);
if (resourceConfigCreator != null) {
commandName = resourceConfigCreator.commandName();
}
}
if (commandName != null) {
List<ServiceHandle<?>> serviceHandles = locator.getAllServiceHandles(new Filter() {
@Override
public boolean matches(Descriptor arg0) {
String name = arg0.getName();
if (name != null && name.equals(commandName)) {
return true;
}
return false;
}
});
for (ServiceHandle<?> handle : serviceHandles) {
ActiveDescriptor<?> descriptor = handle.getActiveDescriptor();
if (descriptor.getName().equals(commandName)) {
if (!descriptor.isReified()) {
locator.reifyDescriptor(descriptor);
}
AdminCommand service = locator.<AdminCommand>getService(descriptor.getImplementationClass());
if (service != null) {
TargetType targetType = descriptor.getImplementationClass().getAnnotation(TargetType.class);
targets = targetType.value();
break;
}
}
}
if (!(isTargetValid = validateTarget(target, targets))) {
return null;
}
Config config = domain.getConfigs().getConfigByName(target);
if (config != null) {
return config;
}
Server server = configBeansUtilities.getServerNamed(target);
if (server != null) {
return server;
}
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
return dg;
}
Cluster cluster = domain.getClusterNamed(target);
return cluster;
} else {
report.setMessage(localStrings.getLocalString("create.resource.ref.failed", "Resource ref {0} creation failed", refName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return null;
}
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class ConfigModule method bindInjector.
private void bindInjector(DynamicConfiguration configurator, String elementName, Class contract, final Class clz) {
DescriptorBuilder db = BuilderHelper.link(clz).to(ConfigInjector.class).to(InjectionTarget.class).to(contract).in(Singleton.class.getName()).qualifiedBy(clz.getAnnotation(InjectionTarget.class)).named(elementName).andLoadWith(new MyHk2Loader(clz.getClassLoader()));
String metaData = ((Service) clz.getAnnotation(Service.class)).metadata();
Map<String, List<String>> metaMap = new HashMap<String, List<String>>();
for (StringTokenizer st = new StringTokenizer(metaData, ","); st.hasMoreTokens(); ) {
String tok = st.nextToken();
int index = tok.indexOf('=');
if (index > 0) {
String key = tok.substring(0, index);
String value = tok.substring(index + 1);
List<String> lst = metaMap.get(key);
if (lst == null) {
lst = new LinkedList<String>();
metaMap.put(key, lst);
}
lst.add(value);
// System.out.println("** Added Metadata: " + tok.substring(0, index) + " : " + tok.substring(index+1));
}
// db.andLoadWith(new MyHk2Loader(clz.getClassLoader()));
}
for (String key : metaMap.keySet()) {
db.has(key, metaMap.get(key));
}
ActiveDescriptor desc = configurator.bind(db.build());
configurator.bind(new AliasDescriptor(serviceLocator, desc, InjectionTarget.class.getName(), contract.getName()));
System.out.println("**Successfully bound an alias descriptor for: " + elementName);
}
Aggregations