use of org.glassfish.hk2.classmodel.reflect.Type 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.classmodel.reflect.Type 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.classmodel.reflect.Type 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.classmodel.reflect.Type in project Payara by payara.
the class ConfigSupport method sortAndDispatch.
/**
* sort events and dispatch the changes. There will be only one notification of event
* per event type, per object, meaning that if an object has had 3 attributes changes, the
* Changed interface implementation will get notified only once.
*
* @param events of events that resulted of a successful configuration transaction
* @param target the intended receiver of the changes notification
* @param logger to log any issues.
*/
public static UnprocessedChangeEvents sortAndDispatch(PropertyChangeEvent[] events, Changed target, Logger logger) {
if (logger == null)
throw new IllegalArgumentException();
List<UnprocessedChangeEvent> unprocessed = new ArrayList<UnprocessedChangeEvent>();
List<Dom> added = new ArrayList<Dom>();
List<Dom> changed = new ArrayList<Dom>();
for (PropertyChangeEvent event : events) {
if (event.getOldValue() == null && event.getNewValue() instanceof ConfigBeanProxy) {
// something was added
try {
final ConfigBeanProxy proxy = ConfigBeanProxy.class.cast(event.getNewValue());
added.add(Dom.unwrap(proxy));
final NotProcessed nc = target.changed(Changed.TYPE.ADD, proxyType(proxy), proxy);
if (nc != null) {
unprocessed.add(new UnprocessedChangeEvent(event, nc.getReason()));
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception while processing config bean changes : ", e);
}
}
}
for (PropertyChangeEvent event : events) {
try {
Dom eventSource = Dom.unwrap((ConfigBeanProxy) event.getSource());
if (added.contains(eventSource)) {
// we don't really send the changed events for new comers.
continue;
}
ConfigBeanProxy proxy = null;
if (event.getNewValue() == null) {
try {
// getOldValue() can be null, we will notify a CHANGE event
proxy = ConfigBeanProxy.class.cast(event.getOldValue());
} catch (ClassCastException e) {
// this is ok, the old value was probably a string or something like this...
// we will notify the event.getSource() that it changed.
}
// new value is null, but not old value, we removed something
if (proxy != null) {
final NotProcessed nc = target.changed(Changed.TYPE.REMOVE, proxyType(proxy), proxy);
if (nc != null) {
unprocessed.add(new UnprocessedChangeEvent(event, nc.getReason()));
}
continue;
}
}
// and added config bean.
if (!changed.contains(eventSource)) {
proxy = ConfigBeanProxy.class.cast(event.getSource());
changed.add(eventSource);
final NotProcessed nc = target.changed(Changed.TYPE.CHANGE, proxyType(proxy), proxy);
if (nc != null) {
unprocessed.add(new UnprocessedChangeEvent(event, nc.getReason()));
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception while processing config bean changes : ", e);
}
}
return new UnprocessedChangeEvents(unprocessed);
}
use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.
the class TemplateListOfResource method getPostCommand.
/**
* allows for remote files to be put in a tmp area and we pass the
* local location of this file to the corresponding command instead of the content of the file
* * Yu need to add enctype="multipart/form-data" in the form
* for ex: <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
* then any param of type="file" will be uploaded, stored locally and the param will use the local location
* on the server side (ie. just the path)
*/
public String getPostCommand() {
ConfigModel.Property p = parent.model.getElement(tagName);
if (p == null) {
// "*"
ConfigModel.Property childElement = parent.model.getElement("*");
if (childElement != null) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (subChildConfigModel.getTagName().equals(tagName)) {
return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
}
}
}
} else {
ConfigModel.Node n = (ConfigModel.Node) p;
String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
if (command != null) {
return command;
}
// last possible case...the @Create annotation on a parent method
Class<? extends ConfigBeanProxy> cbp = null;
try {
cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
} catch (MultiException e) {
//
return null;
}
Create create = null;
for (Method m : cbp.getMethods()) {
ConfigModel.Property pp = parent.model.toProperty(m);
if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
create = m.getAnnotation(Create.class);
break;
}
}
if (create != null) {
return create.value();
}
}
return null;
}
Aggregations