Search in sources :

Example 1 with Types

use of org.glassfish.hk2.classmodel.reflect.Types 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()]);
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 2 with Types

use of org.glassfish.hk2.classmodel.reflect.Types in project Payara by payara.

the class DOLUtils method getSniffersForModule.

/**
 * get sniffer list for sub modules of an ear application
 */
private static Collection<Sniffer> getSniffersForModule(ServiceLocator habitat, ReadableArchive archive, ModuleDescriptor md, Application app) throws Exception {
    ArchiveHandler handler = habitat.getService(ArchiveHandler.class, md.getModuleType().toString());
    SnifferManager snifferManager = habitat.getService(SnifferManager.class);
    List<URI> classPathURIs = handler.getClassPathURIs(archive);
    classPathURIs.addAll(getLibraryJarURIs(app, archive));
    Types types = archive.getParentArchive().getExtraData(Types.class);
    DeployCommandParameters parameters = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, DeployCommandParameters.class);
    Properties appProps = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.APP_PROPS, Properties.class);
    ExtendedDeploymentContext context = new DeploymentContextImpl(null, archive, parameters, habitat.<ServerEnvironment>getService(ServerEnvironment.class));
    if (appProps != null) {
        context.getAppProps().putAll(appProps);
    }
    context.setArchiveHandler(handler);
    context.addTransientAppMetaData(Types.class.getName(), types);
    Collection<Sniffer> sniffers = snifferManager.getSniffers(context, classPathURIs, types);
    context.postDeployClean(true);
    String type = getTypeFromModuleType(md.getModuleType());
    Sniffer mainSniffer = null;
    for (Sniffer sniffer : sniffers) {
        if (sniffer.getModuleType().equals(type)) {
            mainSniffer = sniffer;
        }
    }
    // to add the appropriate sniffer
    if (mainSniffer == null) {
        mainSniffer = snifferManager.getSniffer(type);
        sniffers.add(mainSniffer);
    }
    String[] incompatibleTypes = mainSniffer.getIncompatibleSnifferTypes();
    List<String> allIncompatTypes = addAdditionalIncompatTypes(mainSniffer, incompatibleTypes);
    List<Sniffer> sniffersToRemove = new ArrayList<Sniffer>();
    for (Sniffer sniffer : sniffers) {
        for (String incompatType : allIncompatTypes) {
            if (sniffer.getModuleType().equals(incompatType)) {
                deplLogger.log(Level.WARNING, INCOMPATIBLE_TYPE, new Object[] { type, md.getArchiveUri(), incompatType });
                sniffersToRemove.add(sniffer);
            }
        }
    }
    sniffers.removeAll(sniffersToRemove);
    // store the module sniffer information so we don't need to
    // recalculate them later
    Hashtable sniffersTable = archive.getParentArchive().getExtraData(Hashtable.class);
    if (sniffersTable == null) {
        sniffersTable = new Hashtable<String, Collection<Sniffer>>();
        archive.getParentArchive().setExtraData(Hashtable.class, sniffersTable);
    }
    sniffersTable.put(md.getArchiveUri(), sniffers);
    return sniffers;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Types(org.glassfish.hk2.classmodel.reflect.Types) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SnifferManager(org.glassfish.internal.deployment.SnifferManager) Sniffer(org.glassfish.api.container.Sniffer) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Collection(java.util.Collection)

Example 3 with Types

use of org.glassfish.hk2.classmodel.reflect.Types in project Payara by payara.

the class GetHabitatInfo method dumpTypes.

private void dumpTypes(StringBuilder sb) {
    sb.append("\n\n*********** Sorted List of all Types in the Habitat **************\n\n");
    List<ActiveDescriptor<?>> allDescriptors = serviceLocator.getDescriptors(BuilderHelper.allFilter());
    HashSet<String> allTypes = new HashSet<String>();
    for (ActiveDescriptor<?> aDescriptor : allDescriptors) {
        allTypes.add(aDescriptor.getImplementation());
    }
    Iterator<String> it = allTypes.iterator();
    if (// PP (paranoid programmer)
    it == null)
        return;
    SortedSet<String> types = new TreeSet<String>();
    while (it.hasNext()) {
        types.add(it.next());
    }
    // now the types are sorted...
    it = types.iterator();
    for (int i = 1; it.hasNext(); i++) {
        sb.append("Type-" + i + ": " + it.next() + "\n");
    }
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) TreeSet(java.util.TreeSet) RestEndpoint(org.glassfish.api.admin.RestEndpoint) HashSet(java.util.HashSet)

Example 4 with Types

use of org.glassfish.hk2.classmodel.reflect.Types in project Payara by payara.

the class JavaEEScanner method initTypes.

protected void initTypes(File file) throws IOException {
    ParsingContext context = new ParsingContext.Builder().build();
    Parser cp = new Parser(context);
    cp.parse(file, null);
    try {
        cp.awaitTermination();
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    types = cp.getContext().getTypes();
}
Also used : ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 5 with Types

use of org.glassfish.hk2.classmodel.reflect.Types in project Payara by payara.

the class WeldUtils method getTypes.

private static Types getTypes(DeploymentContext context) {
    String metadataKey = Types.class.getName();
    Types types = (Types) context.getTransientAppMetadata().get(metadataKey);
    while (types == null) {
        context = ((ExtendedDeploymentContext) context).getParentContext();
        if (context != null) {
            types = (Types) context.getTransientAppMetadata().get(metadataKey);
        } else {
            break;
        }
    }
    return types;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types)

Aggregations

Types (org.glassfish.hk2.classmodel.reflect.Types)6 ArrayList (java.util.ArrayList)3 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)3 AnnotationType (org.glassfish.hk2.classmodel.reflect.AnnotationType)3 Type (org.glassfish.hk2.classmodel.reflect.Type)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 MultiException (org.glassfish.hk2.api.MultiException)2 Parser (org.glassfish.hk2.classmodel.reflect.Parser)2 ParsingContext (org.glassfish.hk2.classmodel.reflect.ParsingContext)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Collection (java.util.Collection)1 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1