use of org.glassfish.hk2.api.Descriptor in project jersey by jersey.
the class Hk2Helper method bindBinding.
/**
* Binds the single descriptor using an external {@link DynamicConfiguration}.
*
* @param locator HK2 injection manager.
* @param dc HK2 Dynamic configuration to bind the object.
* @param binding Jersey descriptor as a holder of information about an injection point.
*/
private static void bindBinding(ServiceLocator locator, DynamicConfiguration dc, Binding<?, ?> binding) {
if (ClassBinding.class.isAssignableFrom(binding.getClass())) {
ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((ClassBinding<?>) binding);
bindBinding(locator, dc, activeDescriptor, binding.getAliases());
} else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) {
ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((InstanceBinding<?>) binding);
bindBinding(locator, dc, activeDescriptor, binding.getAliases());
} else if (InjectionResolverBinding.class.isAssignableFrom(binding.getClass())) {
InjectionResolverBinding resolverDescriptor = (InjectionResolverBinding) binding;
bindBinding(locator, dc, wrapInjectionResolver(resolverDescriptor), binding.getAliases());
bindBinding(locator, dc, translateToActiveDescriptor(resolverDescriptor), binding.getAliases());
} else if (SupplierClassBinding.class.isAssignableFrom(binding.getClass())) {
bindSupplierClassBinding(locator, (SupplierClassBinding<?>) binding);
} else if (SupplierInstanceBinding.class.isAssignableFrom(binding.getClass())) {
bindSupplierInstanceBinding(locator, (SupplierInstanceBinding<?>) binding);
} else {
throw new RuntimeException(LocalizationMessages.UNKNOWN_DESCRIPTOR_TYPE(binding.getClass().getSimpleName()));
}
}
use of org.glassfish.hk2.api.Descriptor in project jersey by jersey.
the class Hk2Helper method bindBinding.
/**
* Binds the single descriptor using a single {@link DynamicConfiguration}.
*
* @param locator HK2 injection manager.
* @param binding Jersey descriptor as a holder of information about an injection point.
*/
private static void bindBinding(ServiceLocator locator, Binding<?, ?> binding) {
DynamicConfiguration dc = getDynamicConfiguration(locator);
bindBinding(locator, dc, binding);
dc.commit();
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class WeldUtils method getCDIEnablingAnnotations.
/**
* Get the names of any annotation types that are applied to beans, which should enable CDI
* processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
*
* @return An array of annotation type names; The array could be empty if none are found.
*/
public static String[] getCDIEnablingAnnotations(DeploymentContext context) {
List<String> result = new ArrayList<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at)) {
if (!result.contains(at.getName())) {
result.add(at.getName());
}
}
}
}
}
}
return result.toArray(new String[result.size()]);
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class DOLUtils method getComponentEnvId.
/**
* Generate a unique id name for each J2EE component.
* @param env
* @return
*/
public static String getComponentEnvId(JndiNameEnvironment env) {
String id = null;
if (env instanceof EjbDescriptor) {
// EJB component
EjbDescriptor ejbEnv = (EjbDescriptor) env;
// Make jndi name flat so it won't result in the creation of
// a bunch of sub-contexts.
String flattedJndiName = ejbEnv.getJndiName().replace('/', '.');
EjbBundleDescriptor ejbBundle = ejbEnv.getEjbBundleDescriptor();
Descriptor d = ejbBundle.getModuleDescriptor().getDescriptor();
// as the web bundle, because they share the same JNDI namespace
if (d instanceof WebBundleDescriptor) {
// copy of code below
WebBundleDescriptor webEnv = (WebBundleDescriptor) d;
id = webEnv.getApplication().getName() + ID_SEPARATOR + webEnv.getContextRoot();
if (deplLogger.isLoggable(Level.FINER)) {
deplLogger.log(Level.FINER, CONVERT_EJB_TO_WEB_ID, id);
}
} else {
id = ejbEnv.getApplication().getName() + ID_SEPARATOR + ejbBundle.getModuleDescriptor().getArchiveUri() + ID_SEPARATOR + ejbEnv.getName() + ID_SEPARATOR + flattedJndiName + ejbEnv.getUniqueId();
}
} else if (env instanceof WebBundleDescriptor) {
WebBundleDescriptor webEnv = (WebBundleDescriptor) env;
id = webEnv.getApplication().getName() + ID_SEPARATOR + webEnv.getContextRoot();
} else if (env instanceof ApplicationClientDescriptor) {
ApplicationClientDescriptor appEnv = (ApplicationClientDescriptor) env;
id = "client" + ID_SEPARATOR + appEnv.getName() + ID_SEPARATOR + appEnv.getMainClassName();
} else if (env instanceof ManagedBeanDescriptor) {
id = ((ManagedBeanDescriptor) env).getGlobalJndiName();
} else if (env instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) env;
id = "__ejbBundle__" + ID_SEPARATOR + ejbBundle.getApplication().getName() + ID_SEPARATOR + ejbBundle.getModuleName();
}
return id;
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class Archivist method processAnnotations.
/**
* Process annotations in a bundle descriptor, the annoation processing
* is dependent on the type of descriptor being passed.
*/
protected ProcessingResult processAnnotations(RootDeploymentDescriptor bundleDesc, ModuleScanner scanner, ReadableArchive archive) throws AnnotationProcessorException, IOException {
if (scanner == null) {
return null;
}
AnnotatedElementHandler aeHandler = AnnotatedElementHandlerFactory.createAnnotatedElementHandler(bundleDesc);
if (aeHandler == null) {
return null;
}
Parser parser = null;
if (archive.getParentArchive() != null) {
parser = archive.getParentArchive().getExtraData(Parser.class);
} else {
parser = archive.getExtraData(Parser.class);
}
scanner.process(archive, bundleDesc, classLoader, parser);
if (!scanner.getElements().isEmpty()) {
if (((BundleDescriptor) bundleDesc).isDDWithNoAnnotationAllowed()) {
// if we come into this block, it means an old version
// of deployment descriptor has annotation which is not correct
// throw exception in this case
String ddName = getStandardDDFile().getDeploymentDescriptorPath();
String explodedArchiveName = new File(archive.getURI()).getName();
String archiveName = FileUtils.revertFriendlyFilenameExtension(explodedArchiveName);
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.oldDDwithAnnotation", "{0} in archive {1} is of version {2}, which cannot support annotations in an application. Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).", new Object[] { ddName, archiveName, bundleDesc.getSpecVersion() }));
}
boolean isFullAttribute = false;
if (bundleDesc instanceof BundleDescriptor) {
isFullAttribute = ((BundleDescriptor) bundleDesc).isFullAttribute();
}
AnnotationProcessor ap = annotationFactory.getAnnotationProcessor(isFullAttribute);
ProcessingContext ctx = ap.createContext();
ctx.setArchive(archive);
if (annotationErrorHandler != null) {
ctx.setErrorHandler(annotationErrorHandler);
}
ctx.setProcessingInput(scanner);
ctx.pushHandler(aeHandler);
// Make sure there is a classloader available on the descriptor
// during annotation processing.
ClassLoader originalBundleClassLoader = null;
try {
originalBundleClassLoader = bundleDesc.getClassLoader();
} catch (Exception e) {
// getClassLoader can throw exception if not available
}
// Only set classloader if it's not already set.
if (originalBundleClassLoader == null) {
bundleDesc.setClassLoader(classLoader);
}
try {
return ap.process(ctx);
} finally {
if (originalBundleClassLoader == null) {
bundleDesc.setClassLoader(null);
}
}
}
return null;
}
Aggregations