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();
}
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
}
}
}
}
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();
}
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();
}
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;
}
Aggregations