Search in sources :

Example 31 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class EjbOptionalIntfGenerator method generateBeanMethod.

private static void generateBeanMethod(ClassVisitor cv, String subClassName, java.lang.reflect.Method m, Class delegateClass) throws Exception {
    String methodName = m.getName();
    Type returnType = Type.getReturnType(m);
    Type[] argTypes = Type.getArgumentTypes(m);
    Method asmMethod = new Method(methodName, returnType, argTypes);
    GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, asmMethod, null, getExceptionTypes(m), cv);
    mg.loadThis();
    mg.visitFieldInsn(GETFIELD, subClassName.replace('.', '/'), DELEGATE_FIELD_NAME, Type.getType(delegateClass).getDescriptor());
    mg.loadArgs();
    mg.invokeInterface(Type.getType(delegateClass), asmMethod);
    mg.returnValue();
    mg.endMethod();
}
Also used : GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method)

Example 32 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class DolProvider method processDeploymentMetaData.

/**
 * This method populates the Application object from a ReadableArchive
 * @param archive the archive for the application
 */
public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
    FileArchive expandedArchive = null;
    File tmpFile = null;
    ExtendedDeploymentContext context = null;
    Logger logger = Logger.getAnonymousLogger();
    ClassLoader cl = null;
    try {
        String archiveName = Util.getURIName(archive.getURI());
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        if (archiveHandler == null) {
            throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", archiveName));
        }
        DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
        ActionReport report = new HTMLActionReporter();
        context = new DeploymentContextImpl(report, archive, parameters, env);
        context.setArchiveHandler(archiveHandler);
        String appName = archiveHandler.getDefaultApplicationName(archive, context);
        parameters.name = appName;
        if (archive instanceof InputJarArchive) {
            // we need to expand the archive first in this case
            tmpFile = File.createTempFile(archiveName, "");
            String path = tmpFile.getAbsolutePath();
            if (!tmpFile.delete()) {
                logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] { path });
            }
            File tmpDir = new File(path);
            tmpDir.deleteOnExit();
            if (!tmpDir.exists() && !tmpDir.mkdirs()) {
                throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
            }
            expandedArchive = (FileArchive) archiveFactory.createArchive(tmpDir);
            archiveHandler.expand(archive, expandedArchive, context);
            context.setSource(expandedArchive);
        }
        context.setPhase(DeploymentContextImpl.Phase.PREPARE);
        ClassLoaderHierarchy clh = clhProvider.get();
        context.createDeploymentClassLoader(clh, archiveHandler);
        cl = context.getClassLoader();
        deployment.getDeployableTypes(context);
        deployment.getSniffers(archiveHandler, null, context);
        return processDOL(context);
    } finally {
        if (cl != null && cl instanceof PreDestroy) {
            try {
                PreDestroy.class.cast(cl).preDestroy();
            } catch (Exception e) {
            // ignore
            }
        }
        if (context != null) {
            context.postDeployClean(true);
        }
        if (expandedArchive != null) {
            try {
                expandedArchive.close();
            } catch (Exception e) {
            // ignore
            }
        }
        if (tmpFile != null && tmpFile.exists()) {
            try {
                FileUtils.whack(tmpFile);
            } catch (Exception e) {
            // ignore
            }
        }
    }
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Logger(java.util.logging.Logger) ActionReport(org.glassfish.api.ActionReport) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) PreDestroy(org.glassfish.hk2.api.PreDestroy) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) File(java.io.File)

Example 33 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class BtraceClientGenerator method generateConstructor.

private static void generateConstructor(ClassWriter cw) {
    Method m = Method.getMethod("void <init> ()");
    GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw);
    gen.loadThis();
    gen.invokeConstructor(Type.getType(Object.class), m);
    // return the value from constructor
    gen.returnValue();
    gen.endMethod();
}
Also used : GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method)

Example 34 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class ProviderImplGenerator method generateConstructor.

private void generateConstructor(ClassWriter cw, String generatedClassName, FlashlightProbeProvider provider) {
    Method m = Method.getMethod("void <init> ()");
    GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw);
    gen.loadThis();
    gen.invokeConstructor(Type.getType(Object.class), m);
    Type probeRegType = Type.getType(ProbeRegistry.class);
    Type probeType = Type.getType(FlashlightProbe.class);
    gen.loadThis();
    for (FlashlightProbe probe : provider.getProbes()) {
        gen.dup();
        String fieldName = "_flashlight_" + probe.getProbeName();
        gen.push(probe.getId());
        gen.invokeStatic(probeRegType, Method.getMethod("org.glassfish.flashlight.provider.FlashlightProbe getProbeById(int)"));
        gen.visitFieldInsn(Opcodes.PUTFIELD, generatedClassName, fieldName, probeType.getDescriptor());
    }
    gen.pop();
    // return the value from constructor
    gen.returnValue();
    gen.endMethod();
}
Also used : Type(org.glassfish.hk2.external.org.objectweb.asm.Type) FlashlightProbe(org.glassfish.flashlight.provider.FlashlightProbe) GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method)

Example 35 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class ConfigApiTest method prepareAdminSubject.

private Subject prepareAdminSubject() {
    final ServiceLocator locator = getBaseServiceLocator();
    if (locator != null) {
        final List<ServiceHandle<? extends Object>> adminIdentities = /*                
                    (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(
                    new Filter() {

                @Override
                public boolean matches(Descriptor d) {
                    if (d == null) {
                        return false;
                    }
                    final Set<String> contracts = d.getAdvertisedContracts();
                    return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                }
            });
*/
        AccessController.doPrivileged(new PrivilegedAction<List<ServiceHandle<? extends Object>>>() {

            public List<ServiceHandle<? extends Object>> run() {
                List<ServiceHandle<? extends Object>> identities = (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(new Filter() {

                    @Override
                    public boolean matches(Descriptor d) {
                        if (d == null) {
                            return false;
                        }
                        final Set<String> contracts = d.getAdvertisedContracts();
                        return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                    }
                });
                return identities;
            }
        });
        if (!adminIdentities.isEmpty()) {
            final Object adminIdentity = adminIdentities.get(0);
            try {
                final Method getSubjectMethod = adminIdentity.getClass().getDeclaredMethod("getSubject", Subject.class);
                return (Subject) getSubjectMethod.invoke(adminIdentity);
            } catch (Exception ex) {
            // ignore - fallback to creating a subject explicitly that
            // should match the GlassFish admin identity
            }
        }
    }
    final Subject s = new Subject();
    s.getPrincipals().add(new PrincipalImpl("asadmin"));
    s.getPrincipals().add(new PrincipalImpl("_InternalSystemAdministrator_"));
    return s;
}
Also used : Set(java.util.Set) Method(java.lang.reflect.Method) Subject(javax.security.auth.Subject) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Filter(org.glassfish.hk2.api.Filter) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) Descriptor(org.glassfish.hk2.api.Descriptor) List(java.util.List)

Aggregations

MultiException (org.glassfish.hk2.api.MultiException)18 Method (java.lang.reflect.Method)16 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)8 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)8 PrivilegedActionException (java.security.PrivilegedActionException)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)6 File (java.io.File)5 HashMap (java.util.HashMap)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Attribute (org.jvnet.hk2.config.Attribute)4 PropertyVetoException (java.beans.PropertyVetoException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashSet (java.util.HashSet)3