[Javassist user questions] - Re: adding annotations
by cat4hire
I've made another experiment: using an AnnotationsWriter as follows does not work too:
|
| ByteArrayOutputStream aos = new ByteArrayOutputStream();
| AnnotationsWriter aw = new AnnotationsWriter(aos, constantPool);
| aw.numAnnotations(1);
| aw.annotation(this.annotationClassName, 0);
| aw.close();
| byte ab[] = aos.toByteArray();
| attribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag, ab);
|
| System.out.println("Annotation attribute " + attribute.getName() + " " + attribute.getAnnotations().length);
| classFile.addAttribute( attribute );
|
The class can be loaded and instantiated, but I cannot access its annotations.
In both cases, if I print the classfile content with a ClassFileWriter I got a message that lets me think I've got the annotations:
| attribute: SourceFile (2 byte): javassist.bytecode.SourceFileAttribute
| attribute: RuntimeVisibleAnnotations (6 byte): javassist.bytecode.AnnotationsAttribute
|
Moreover, in the case in which I use an AnnotationsWriter I got the following run-time exception when I try to access the annotations thru the Class.getAnnotations() method:
| Exception in thread "Thread-Example-Main" java.lang.reflect.GenericSignatureFormatError
| at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:103)
| at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:233)
| at sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:359)
| at sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java:157)
| at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:367)
| at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:181)
| at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
| at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
| at java.lang.Class.initAnnotationsIfNecessary(Class.java:3072)
| at java.lang.Class.getAnnotations(Class.java:3052)
|
I cannot find whre I'm doing something wrong.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133207#4133207
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133207
18 years, 1 month
[JBoss jBPM] - Re: Less coding by custom nodes/jrules/etc...
by pojomonkey
"kukeltje" wrote : See http://docs.jboss.com/jbpm/v3/userguide/jpdl.html#configurationofdelegations
|
| How you parse the content of what is in there is completely up to the developer
I had another look at that and came up with the following:
<process-definition xmlns="" name="TestProcess">
|
| <start-state name="startstate">
|
| <transition to="node1" name="ok">
| <action name="Test1" class="TestHandler" config-type="constructor">
| <blob>This is some constructor config data</blob>
| </action>
| <action name="Test2" class="TestHandler" config-type="field">
| <blob>This is some field config data</blob>
| </action>
| <action name="Test3" class="TestHandler" config-type="bean">
| <blob>This is some bean config data</blob>
| </action>
| </transition>
| </start-state>
|
| <node name="node1">
| <transition to="end"></transition>
| </node>
| <end-state name="end"></end-state>
| </process-definition>
and
import org.apache.commons.logging.Log;
| import org.apache.commons.logging.LogFactory;
| import org.jbpm.graph.def.ActionHandler;
| import org.jbpm.graph.exe.ExecutionContext;
|
| public class TestHandler implements ActionHandler
| {
| private static Log log = LogFactory.getLog(TestHandler.class);
|
| public String blob;
|
| public TestHandler()
| {
| log.debug("Default constructor");
| blob = "default";
| }
|
| public TestHandler(String xml)
| {
| this();
|
| log.debug("Config constructor");
|
| configure(xml);
| }
|
| public void configure(String xml)
| {
| log.debug("Parse: " + xml.trim());
| }
|
| public void setBlob(String blob)
| {
| log.debug("Setter");
| this.blob = blob;
| }
|
| public void execute(ExecutionContext executionContext) throws Exception
| {
| log.debug("Execute: " + blob);
| }
|
| }
|
Hope that helps :)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133178#4133178
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133178
18 years, 1 month