Package javassist.bytecode

Examples of javassist.bytecode.AnnotationsAttribute


    sb.append("return f;");
    sb.append("}");
    mnew = CtNewMethod.make(sb.toString(), mainClass);

    ConstPool cp = mnew.getMethodInfo().getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(cp,
        AnnotationsAttribute.visibleTag);

    javassist.bytecode.annotation.Annotation producesAnnotation = new javassist.bytecode.annotation.Annotation(
        "javax.enterprise.inject.Produces", cp);
    javassist.bytecode.annotation.Annotation zkScopedAnnotation = new javassist.bytecode.annotation.Annotation(
        "org.zkoss.cdi.context.IdSpaceScoped", cp);
    javassist.bytecode.annotation.Annotation zkCompAnnotation = new javassist.bytecode.annotation.Annotation(
        "org.zkoss.cdi.inject.ComponentId", cp);
    zkCompAnnotation.addMemberValue("value", new StringMemberValue(field
        .getName(), cp));
   
    attr.addAnnotation(producesAnnotation);
    attr.addAnnotation(zkScopedAnnotation);
    attr.addAnnotation(zkCompAnnotation);
    mnew.getMethodInfo().addAttribute(attr);
   
    mainClass.addMethod(mnew);
  }
View Full Code Here


      final String typeName = SOAPMessage.class.getName().replace('.', '/') ;
      final String signature = 'L' + superClassName + ';' + 'L' + interfaceName + "<L" + typeName + ";>;" ;
      final SignatureAttribute signatureAttribute = new SignatureAttribute(constantPool, signature) ;
      seiClass.getClassFile().addAttribute(signatureAttribute) ;

      AnnotationsAttribute attribute = new AnnotationsAttribute(
          constantPool, AnnotationsAttribute.visibleTag);
      Annotation annotation = new Annotation(
          "javax.xml.ws.WebServiceProvider", constantPool);
      StringMemberValue strValue1 = new StringMemberValue(constantPool);
      strValue1.setValue(epInfo.getWSDLFileName());
      annotation.addMemberValue("wsdlLocation", strValue1);
      StringMemberValue strValue2 = new StringMemberValue(constantPool);
      strValue2.setValue(epInfo.getServiceName());
      annotation.addMemberValue("serviceName", strValue2);
      StringMemberValue strValue3 = new StringMemberValue(constantPool);
      strValue3.setValue(epInfo.getPortName());
      annotation.addMemberValue("portName", strValue3);

      StringMemberValue strValue4 = new StringMemberValue(constantPool);
      strValue4.setValue(epInfo.getNamespace());
      annotation.addMemberValue("targetNamespace", strValue4);

      attribute.addAnnotation(annotation);

      Annotation annotation2 = new Annotation("javax.xml.ws.ServiceMode",
          constantPool);
      EnumMemberValue enumValue = new EnumMemberValue(constantPool);
      enumValue.setType("javax.xml.ws.Service$Mode");
      enumValue.setValue("MESSAGE");
      annotation2.addMemberValue("value", enumValue);
      attribute.addAnnotation(annotation2);

      if (epInfo.isAddressing() && JBossDeployerUtil.getWSImpl().equals(JBossDeployerUtil.WSIMPL_CXF))
      {
        Annotation annotation3 = new Annotation("javax.xml.ws.soap.Addressing", constantPool);
        BooleanMemberValue boolEnabled = new BooleanMemberValue(constantPool);
        boolEnabled.setValue(true);
        BooleanMemberValue boolRequired = new BooleanMemberValue(constantPool);
        boolRequired.setValue(true);
        annotation3.addMemberValue("enabled", boolEnabled);
        annotation3.addMemberValue("required", boolEnabled);
        attribute.addAnnotation(annotation3);
      }

      if (includeHandlers)
      {
        final Annotation handlerChainAnnotation = new Annotation("javax.jws.HandlerChain", constantPool) ;
        final StringMemberValue handlerValue = new StringMemberValue(constantPool) ;
        handlerValue.setValue("esb-jaxws-handlers.xml") ;
        handlerChainAnnotation.addMemberValue("file", handlerValue) ;
        attribute.addAnnotation(handlerChainAnnotation) ;
      }
     
      seiClass.getClassFile().addAttribute(attribute);
     
      final String siClassName = ServiceInvoker.class.getName() ;
View Full Code Here

            //we'll be adding new constants to the class file (for generics and annotations)
            ConstPool constPool = newClassFile.getConstPool();

            //copy the annotations on the class
            AnnotationsAttribute annotations = (AnnotationsAttribute) originalClassFile
                .getAttribute(AnnotationsAttribute.visibleTag);
            AnnotationsAttribute newAnnotations = copyAnnotations(annotations, constPool);

            //add our @Simplified annotation to the new class
            newAnnotations = addSimplifiedClassAnnotation(originalClass.getName(), newAnnotations, constPool);
            newClassFile.addAttribute(newAnnotations);
View Full Code Here

            Annotation[] newClassAnnotations = new Annotation[origAnnotations.length];
            for (int i = 0; i < newClassAnnotations.length; ++i) {
                newClassAnnotations[i] = cloneAnnotation(origAnnotations[i], constPool);
            }

            AnnotationsAttribute newAnnotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
            newAnnotations.setAnnotations(newClassAnnotations);

            return newAnnotations;
        }

        return null;
View Full Code Here

    private static AnnotationsAttribute addSimplifiedClassAnnotation(String originalClassName,
        AnnotationsAttribute annotations, ConstPool constPool) {

        if (annotations == null) {
            annotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
        }

        Annotation simplified = new Annotation(SimplifiedClass.class.getName(), constPool);
        simplified.addMemberValue("originalClass", new ClassMemberValue(originalClassName, constPool));
View Full Code Here

    private static AnnotationsAttribute addSimplifiedMethodAnnotation(AnnotationsAttribute annotations,
        ConstPool constPool) {

        if (annotations == null) {
            annotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
        }

        annotations.addAnnotation(new Annotation(SimplifiedMethod.class.getName(), constPool));

        return annotations;
View Full Code Here

   */
  private void markAsEnhanced(CtClass aCtClazz) {
    ClassFile classFile = aCtClazz.getClassFile();
    ConstPool constPool = classFile.getConstPool();

    AnnotationsAttribute annoAttr = (AnnotationsAttribute) classFile
            .getAttribute(AnnotationsAttribute.visibleTag);

    // Create annotation attribute if it does not exist
    if (annoAttr == null) {
      annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    }

    // Create annotation if it does not exist
    Annotation a = new Annotation(EnhancedClassFile.class.getName(), constPool);

    // Replace annotation
    annoAttr.addAnnotation(a);

    // Replace annotation attribute
    classFile.addAttribute(annoAttr);
  }
View Full Code Here

  private void enhanceResourceMetaData(JavaSource aAST, Class<?> aClazz, CtClass aCtClazz,
          Multimap<String, String> aReportData) {
    ClassFile classFile = aCtClazz.getClassFile();
    ConstPool constPool = classFile.getConstPool();

    AnnotationsAttribute annoAttr = (AnnotationsAttribute) classFile
            .getAttribute(AnnotationsAttribute.visibleTag);

    // Create annotation attribute if it does not exist
    if (annoAttr == null) {
      annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    }

    // Create annotation if it does not exist
    Annotation a = annoAttr.getAnnotation(ResourceMetaData.class.getName());
    if (a == null) {
      a = new Annotation(ResourceMetaData.class.getName(), constPool);
      // Add a name, otherwise there will be none in the generated descriptor.
      a.addMemberValue("name", new StringMemberValue(
              ResourceMetaDataFactory.getDefaultName(aClazz), constPool));
    }

    // Update description from JavaDoc
    String doc = Util.getComponentDocumentation(aAST, aClazz.getName());
    enhanceMemberValue(a, "description", doc, overrideComponentDescription,
            ResourceMetaDataFactory.getDefaultDescription(aClazz), constPool, aReportData, aClazz);

    // Update version
    enhanceMemberValue(a, "version", componentVersion, overrideComponentVersion,
            ResourceMetaDataFactory.getDefaultVersion(aClazz), constPool, aReportData, aClazz);

    // Update vendor
    enhanceMemberValue(a, "vendor", componentVendor, overrideComponentVendor,
            ResourceMetaDataFactory.getDefaultVendor(aClazz), constPool, aReportData, aClazz);

    // Update copyright
    enhanceMemberValue(a, "copyright", componentCopyright, overrideComponentCopyright,
            ResourceMetaDataFactory.getDefaultCopyright(aClazz), constPool, aReportData, aClazz);

    // Replace annotation
    annoAttr.addAnnotation(a);

    // Replace annotation attribute
    classFile.addAttribute(annoAttr);
  }
View Full Code Here

      }

      // Update the "description" field of the annotation
      try {
        CtField ctField = aCtClazz.getField(field.getName());
        AnnotationsAttribute annoAttr = (AnnotationsAttribute) ctField.getFieldInfo().getAttribute(
                AnnotationsAttribute.visibleTag);

        // Locate and update annotation
        if (annoAttr != null) {
          Annotation[] annotations = annoAttr.getAnnotations();

          // Update existing annotation
          for (Annotation a : annotations) {
            if (a.getTypeName().equals(
                    org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName())
                    || a.getTypeName().equals(
                            org.apache.uima.fit.descriptor.ExternalResource.class.getName())
                    || a.getTypeName().equals("org.uimafit.descriptor.ConfigurationParameter")
                    || a.getTypeName().equals("org.uimafit.descriptor.ExternalResource")) {
              if (a.getMemberValue("description") == null) {
                a.addMemberValue("description", new StringMemberValue(pdesc, aCtClazz
                        .getClassFile().getConstPool()));
                getLog().info("Enhanced description of " + type + " [" + pname + "]");
                // Replace updated annotation
                annoAttr.addAnnotation(a);
              } else {
                // Extract configuration parameter information from the uimaFIT annotation
                // We only want to override if the description is not set yet.
                getLog().info("Not overwriting description of " + type + " [" + pname + "] ");
              }
View Full Code Here

        }
       
        for (CtField cf: ctClass.getDeclaredFields()) {
            if (hasAnnotation(cf, siena.Max.class.getName())) {
              // retrieves @siena.Max value
              AnnotationsAttribute attr = getAnnotations(cf);
              Annotation orig = attr.getAnnotation(Max.class.getName());
              int val = ((IntegerMemberValue)orig.getMemberValue("value")).getValue();

              // adds @play.data.validation.MaxSize value
              Map<String, MemberValue> map = new HashMap<String, MemberValue>();
              map.put("value", new IntegerMemberValue(attr.getConstPool(), val));

                createAnnotation(
                attr,
                play.data.validation.MaxSize.class, map);
            }
            if (hasAnnotation(cf, siena.NotNull.class.getName())) {
              // retrieves @siena.NotNull value
              AnnotationsAttribute attr = getAnnotations(cf);
              // adds @play.data.validation.Required value
              createAnnotation(
                attr,
                play.data.validation.Required.class);
            }
            if (hasAnnotation(cf, siena.DateTime.class.getName())) {
              // retrieves @siena.DateTime value
              AnnotationsAttribute attr = getAnnotations(cf);
             
              // adds @play.data.binding.As(lang={"*"}, value={"yyyy-MM-dd HH:mm:ss"})
              Map<String, MemberValue> map = new HashMap<String, MemberValue>();
              ConstPool cp = attr.getConstPool();
              // creates lang array
              MemberValue[] langArray = new MemberValue[1];
              langArray[0] = new StringMemberValue("*", cp);
              ArrayMemberValue langMember = new ArrayMemberValue(cp);
              langMember.setValue(langArray);             
View Full Code Here

TOP

Related Classes of javassist.bytecode.AnnotationsAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.