use of org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor in project Payara by payara.
the class CompositeUtil method createConstructor.
/**
* This method creates the default constructor for the class. Default values are set for any @Attribute defined with
* a defaultValue.
*/
private void createConstructor(ClassWriter cw, String className, Map<String, Map<String, Object>> properties) {
MethodVisitor method = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
method.visitCode();
method.visitVarInsn(ALOAD, 0);
method.visitMethodInsn(INVOKESPECIAL, "org/glassfish/admin/rest/composite/RestModelImpl", "<init>", "()V");
for (Map.Entry<String, Map<String, Object>> property : properties.entrySet()) {
String fieldName = property.getKey();
String defaultValue = (String) property.getValue().get("defaultValue");
if (defaultValue != null && !defaultValue.isEmpty()) {
setDefaultValue(method, className, fieldName, (Class<?>) property.getValue().get("type"), defaultValue);
}
}
method.visitInsn(RETURN);
method.visitMaxs(1, 1);
method.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor in project Payara by payara.
the class ASMClassWriter method createGetPostCommandForCollectionLeafResource.
@Override
public void createGetPostCommandForCollectionLeafResource(String postCommandName) {
MethodVisitor mv = cw.visitMethod(ACC_PROTECTED, "getPostCommand", "()Ljava/lang/String;", null, null);
mv.visitCode();
mv.visitLdcInsn(postCommandName);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor in project Payara by payara.
the class ASMClassWriter method createCommandResourceConstructor.
@Override
public void createCommandResourceConstructor(String commandResourceClassName, String commandName, String httpMethod, boolean linkedToParent, CommandResourceMetaData.ParameterMetaData[] commandParams, String commandDisplayName, String commandAction) {
String baseClassName = "";
if (httpMethod.equals("GET")) {
baseClassName = "org/glassfish/admin/rest/resources/TemplateCommandGetResource";
} else if (httpMethod.equals("DELETE")) {
baseClassName = "org/glassfish/admin/rest/resources/TemplateCommandDeleteResource";
} else if (httpMethod.equals("POST")) {
baseClassName = "org/glassfish/admin/rest/resources/TemplateCommandPostResource";
} else {
throw new GeneratorException("Invalid httpMethod specified: " + httpMethod);
}
boolean isget = (httpMethod.equals("GET"));
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, generatedPath + commandResourceClassName, null, baseClassName, null);
// cw.visitInnerClass(generatedPath + commandResourceClassName +"$1", null, null, 0);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(commandResourceClassName);
mv.visitLdcInsn(commandName);
mv.visitLdcInsn(httpMethod);
if (!isget) {
mv.visitLdcInsn(commandAction);
mv.visitLdcInsn(commandDisplayName);
}
if (linkedToParent == true) {
mv.visitInsn(ICONST_1);
} else {
mv.visitInsn(ICONST_0);
}
// next is different based on parent
if (!isget) {
mv.visitMethodInsn(INVOKESPECIAL, baseClassName, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
} else {
mv.visitMethodInsn(INVOKESPECIAL, baseClassName, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
}
mv.visitInsn(RETURN);
if (!isget) {
// GET is 5!!!
mv.visitMaxs(7, 1);
} else {
mv.visitMaxs(5, 1);
}
mv.visitEnd();
if (commandParams != null) {
mv = cw.visitMethod(ACC_PROTECTED, "getCommandParams", "()Ljava/util/HashMap;", "()Ljava/util/HashMap<Ljava/lang/String;Ljava/lang/String;>;", null);
mv.visitCode();
mv.visitTypeInsn(NEW, "java/util/HashMap");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V");
mv.visitVarInsn(ASTORE, 1);
for (CommandResourceMetaData.ParameterMetaData commandParam : commandParams) {
mv.visitVarInsn(ALOAD, 1);
mv.visitLdcInsn(commandParam.name);
mv.visitLdcInsn(commandParam.value);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitInsn(POP);
}
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(ARETURN);
mv.visitMaxs(3, 2);
mv.visitEnd();
}
}
use of org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor in project Payara by payara.
the class ASMClassWriter method createGetDeleteCommand.
@Override
public void createGetDeleteCommand(String commandName) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getDeleteCommand", "()Ljava/lang/String;", null, null);
mv.visitCode();
mv.visitLdcInsn(commandName);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor in project Payara by payara.
the class ASMClassWriter method createGetChildResourceForListResources.
@Override
public void createGetChildResourceForListResources(String keyAttributeName, String childResourceClassName) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get" + childResourceClassName, "(Ljava/lang/String;)L" + generatedPath + childResourceClassName + ";", null, null);
RestLogging.restLogger.log(Level.FINE, "Creating resource with path {0} (5)", keyAttributeName);
AnnotationVisitor av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true);
av0.visit("value", "{" + keyAttributeName + "}/");
av0.visitEnd();
av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/PathParam;", true);
av0.visit("value", keyAttributeName);
av0.visitEnd();
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, generatedPath + "List" + childResourceClassName, INJECTOR_FIELD, FORNAME_INJECTOR_TYPE);
mv.visitLdcInsn(Type.getType("L" + generatedPath + childResourceClassName + ";"));
mv.visitMethodInsn(INVOKEINTERFACE, INTERFACE_INJECTOR_TYPE, CREATE_AND_INITIALIZE, CREATE_AND_INITIALIZE_SIG);
mv.visitTypeInsn(CHECKCAST, generatedPath + childResourceClassName);
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, generatedPath + "List" + childResourceClassName, "entity", "Ljava/util/List;");
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, generatedPath + "List" + childResourceClassName, "tagName", "Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, generatedPath + childResourceClassName, "setBeanByKey", "(Ljava/util/List;Ljava/lang/String;Ljava/lang/String;)V");
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
mv.visitMaxs(4, 3);
mv.visitEnd();
}
Aggregations