Java Code Examples for javassist.bytecode.annotation.StringMemberValue

The following examples show how to use javassist.bytecode.annotation.StringMemberValue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 6 votes vote down vote up
@Override
public DynamicField href(boolean click, String... value) {
	Annotation annot = new Annotation(Href.class.getName(), cpool);
       annot.addMemberValue("click", new BooleanMemberValue(click, cpool));
       
       ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
       MemberValue[] memberValues = new StringMemberValue[value.length];
       for(int i = 0; i < value.length; i++) {
       	memberValues[i] = new StringMemberValue(value[i], cpool);
       }
       arrayMemberValue.setValue(memberValues);
       annot.addMemberValue("value", arrayMemberValue);
       
       attr.addAnnotation(annot);
	return this;
}
 
Example 2
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 6 votes vote down vote up
@Override
public DynamicField image(String download, String... value) {
	Annotation annot = new Annotation(Image.class.getName(), cpool);
       annot.addMemberValue("download", new StringMemberValue(download, cpool));
       
       ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
       MemberValue[] memberValues = new StringMemberValue[value.length];
       for(int i = 0; i < value.length; i++) {
       	memberValues[i] = new StringMemberValue(value[i], cpool);
       }
       arrayMemberValue.setValue(memberValues);
       annot.addMemberValue("value", arrayMemberValue);
       
       attr.addAnnotation(annot);
	return this;
}
 
Example 3
static
private void removeValue(ArrayMemberValue memberValue, String value){
	List<MemberValue> values = new ArrayList<>(Arrays.asList(memberValue.getValue()));

	boolean removed = false;

	Iterator<MemberValue> it = values.iterator();
	while(it.hasNext()){
		StringMemberValue stringValue = (StringMemberValue)it.next();

		if((value).equals(stringValue.getValue())){
			it.remove();

			removed = true;
		}
	}

	if(!removed){
		throw new RuntimeException(value + " not in " + values);
	}

	memberValue.setValue(values.toArray(new MemberValue[values.size()]));
}
 
Example 4
Source Project: statefulj   Source File: SpringMVCBinder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void addEndpointMapping(CtMethod ctMethod, String method, String request) {
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	Annotation requestMapping = new Annotation(RequestMapping.class.getName(), constPool);

	ArrayMemberValue valueVals = new ArrayMemberValue(constPool);
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(request);
	valueVals.setValue(new MemberValue[]{valueVal});

	requestMapping.addMemberValue("value", valueVals);

	ArrayMemberValue methodVals = new ArrayMemberValue(constPool);
	EnumMemberValue methodVal = new EnumMemberValue(constPool);
	methodVal.setType(RequestMethod.class.getName());
	methodVal.setValue(method);
	methodVals.setValue(new MemberValue[]{methodVal});

	requestMapping.addMemberValue("method", methodVals);
	attr.addAnnotation(requestMapping);
	methodInfo.addAttribute(attr);
}
 
Example 5
Source Project: statefulj   Source File: AbstractRestfulBinder.java    License: Apache License 2.0 6 votes vote down vote up
protected Annotation[] addIdParameter(
		CtMethod ctMethod, 
		Class<?> idType,
		ClassPool cp) throws NotFoundException, CannotCompileException {
	// Clone the parameter Class
	//
	CtClass ctParm = cp.get(idType.getName());
	
	// Add the parameter to the method
	//
	ctMethod.addParameter(ctParm);
	
	// Add the Parameter Annotations to the Method
	//
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();
	Annotation annot = new Annotation(getPathAnnotationClass().getName(), constPool);
	
	StringMemberValue valueVal = new StringMemberValue("id", constPool); 
	annot.addMemberValue("value", valueVal);
	
	return new Annotation[]{ annot };
}
 
Example 6
Source Project: minnal   Source File: CreateMethodCreator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void addParamAnnotations(CtMethod ctMethod) {
	Annotation[][] annotations = new Annotation[4][1];
	Annotation headersParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
	annotations[0][0] = headersParam;
	Annotation uriInfoParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
	annotations[1][0] = uriInfoParam;
	Annotation providersParam = new Annotation(Context.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
	annotations[2][0] = providersParam;
	Annotation apiParam = new Annotation(ApiParam.class.getCanonicalName(), ctMethod.getMethodInfo().getConstPool());
	apiParam.addMemberValue("name", new StringMemberValue("body", ctMethod.getMethodInfo().getConstPool()));
	apiParam.addMemberValue("access", new StringMemberValue("internal", ctMethod.getMethodInfo().getConstPool()));
	apiParam.addMemberValue("paramType", new StringMemberValue("body", ctMethod.getMethodInfo().getConstPool()));
	annotations[3][0] = apiParam;
	JavassistUtils.addParameterAnnotation(ctMethod, annotations);
}
 
Example 7
Source Project: minnal   Source File: AbstractMethodCreator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the api path parameter annotations
 * 
 * @return
 */
protected List<Annotation> getApiPathParamAnnotations() {
	List<Annotation> annotations = new ArrayList<Annotation>();
	List<String> parameters = getRoutePattern().getParameterNames();
	for (int i = 0; i < parameters.size(); i++) {
		Annotation annotation = new Annotation(ApiImplicitParam.class.getCanonicalName(), ctClass.getClassFile().getConstPool());
		annotation.addMemberValue("name", new StringMemberValue(parameters.get(i), ctClass.getClassFile().getConstPool()));
		annotation.addMemberValue("paramType", new StringMemberValue("path", ctClass.getClassFile().getConstPool()));
		annotation.addMemberValue("dataType", new StringMemberValue(String.class.getCanonicalName(), ctClass.getClassFile().getConstPool()));
		annotation.addMemberValue("value", new StringMemberValue("The " + getResourcePath().getNodePath().get(i).getEntityMetaData().getName() + " identifier", ctClass.getClassFile().getConstPool()));
		annotation.addMemberValue("required", new BooleanMemberValue(true, ctClass.getClassFile().getConstPool()));
		if (i == parameters.size() - 1) {
			annotation.addMemberValue("allowMultiple", new BooleanMemberValue(true, ctClass.getClassFile().getConstPool()));
		}
		annotations.add(annotation);
	}
	return annotations;
}
 
Example 8
Source Project: minnal   Source File: AbstractMethodCreator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the security annotation
 * 
 * @return
 */
protected Annotation getSecurityAnnotation() {
	Set<String> permissions = getPermissions();
	if (permissions == null || permissions.isEmpty()) {
		return null;
	}
	
	Annotation rolesAllowed = new Annotation(RolesAllowed.class.getCanonicalName(), ctClass.getClassFile().getConstPool());
	ArrayMemberValue values = new ArrayMemberValue(ctClass.getClassFile().getConstPool());
	List<StringMemberValue> memberValues = new ArrayList<StringMemberValue>();
	for (String permission : permissions) {
		memberValues.add(new StringMemberValue(permission, ctClass.getClassFile().getConstPool()));
	}
	values.setValue(memberValues.toArray(new StringMemberValue[0]));
	rolesAllowed.addMemberValue("value", values);
	return rolesAllowed;
}
 
Example 9
Source Project: uima-uimafit   Source File: EnhanceMojo.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set a annotation member value if no value is present, if the present value is the default
 * generated by uimaFIT or if a override is active.
 * 
 * @param aAnnotation
 *          an annotation
 * @param aName
 *          the name of the member value
 * @param aNewValue
 *          the value to set
 * @param aOverride
 *          set value even if it is already set
 * @param aDefault
 *          default value set by uimaFIT - if the member has this value, it is considered unset
 */
private void enhanceMemberValue(Annotation aAnnotation, String aName, String aNewValue,
        boolean aOverride, String aDefault, ConstPool aConstPool,
        Multimap<String, String> aReportData, Class<?> aClazz) {
  String value = getStringMemberValue(aAnnotation, aName);
  boolean isEmpty = value.length() == 0;
  boolean isDefault = value.equals(aDefault);

  if (isEmpty || isDefault || aOverride) {
    if (aNewValue != null) {
      aAnnotation.addMemberValue(aName, new StringMemberValue(aNewValue, aConstPool));
      getLog().debug("Enhanced component meta data [" + aName + "]");
    } else {
      getLog().debug("No meta data [" + aName + "] found");
      aReportData.put(aClazz.getName(), "No meta data [" + aName + "] found");
    }
  } else {
    getLog().debug("Not overwriting component meta data [" + aName + "]");
  }
}
 
Example 10
Source Project: dubbo-2.6.5   Source File: JValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
    MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
    if (memberValue instanceof BooleanMemberValue)
        ((BooleanMemberValue) memberValue).setValue((Boolean) value);
    else if (memberValue instanceof ByteMemberValue)
        ((ByteMemberValue) memberValue).setValue((Byte) value);
    else if (memberValue instanceof CharMemberValue)
        ((CharMemberValue) memberValue).setValue((Character) value);
    else if (memberValue instanceof ShortMemberValue)
        ((ShortMemberValue) memberValue).setValue((Short) value);
    else if (memberValue instanceof IntegerMemberValue)
        ((IntegerMemberValue) memberValue).setValue((Integer) value);
    else if (memberValue instanceof LongMemberValue)
        ((LongMemberValue) memberValue).setValue((Long) value);
    else if (memberValue instanceof FloatMemberValue)
        ((FloatMemberValue) memberValue).setValue((Float) value);
    else if (memberValue instanceof DoubleMemberValue)
        ((DoubleMemberValue) memberValue).setValue((Double) value);
    else if (memberValue instanceof ClassMemberValue)
        ((ClassMemberValue) memberValue).setValue(((Class<?>) value).getName());
    else if (memberValue instanceof StringMemberValue)
        ((StringMemberValue) memberValue).setValue((String) value);
    else if (memberValue instanceof EnumMemberValue)
        ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
    /* else if (memberValue instanceof AnnotationMemberValue) */
    else if (memberValue instanceof ArrayMemberValue) {
        CtClass arrayType = type.getComponentType();
        int len = Array.getLength(value);
        MemberValue[] members = new MemberValue[len];
        for (int i = 0; i < len; i++) {
            members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
        }
        ((ArrayMemberValue) memberValue).setValue(members);
    }
    return memberValue;
}
 
Example 11
Source Project: swagger-more   Source File: ClassUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static CtField createField(Class aClass, String name, String value, CtClass ctClass) throws NotFoundException, CannotCompileException {
    ClassPool.getDefault().insertClassPath(new ClassClassPath(aClass));
    CtField field = new CtField(ClassPool.getDefault().get(aClass.getName()), name, ctClass);
    field.setModifiers(javassist.Modifier.PUBLIC);
    ConstPool constPool = ctClass.getClassFile().getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    Annotation ann = new Annotation(ApiModelProperty.class.getName(), constPool);
    ann.addMemberValue("value", new StringMemberValue(value, constPool));
    ann.addMemberValue("name", new StringMemberValue(name, constPool));
    ann.addMemberValue("required", new BooleanMemberValue(true, constPool));
    attr.addAnnotation(ann);
    field.getFieldInfo().addAttribute(attr);
    return field;
}
 
Example 12
Source Project: flower   Source File: ClassGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private MemberValue getMemberValue(Object obj, ConstPool cp) {
  if (obj == null) {
    return null;
  }
  if (obj instanceof Integer) {
    return new IntegerMemberValue(cp, (Integer) obj);
  } else if (obj instanceof Boolean) {
    return new BooleanMemberValue((Boolean) obj, cp);
  } else if (obj instanceof Double) {
    return new DoubleMemberValue((Double) obj, cp);
  } else if (obj instanceof Float) {
    return new FloatMemberValue((Float) obj, cp);
  } else if (obj instanceof Short) {
    return new ShortMemberValue((Short) obj, cp);
  } else if (obj instanceof String) {
    return new StringMemberValue((String) obj, cp);
  } else if (obj instanceof String[]) {
    String[] oo = (String[]) obj;
    MemberValue[] memberValues = new MemberValue[oo.length];
    ArrayMemberValue value = new ArrayMemberValue(cp);
    for (int i = 0; i < oo.length; i++) {
      memberValues[i] = getMemberValue(oo[i], cp);
    }
    value.setValue(memberValues);
    return value;
  } else if (obj instanceof Byte) {
    return new ByteMemberValue((Byte) obj, cp);
  } else if (obj instanceof Annotation) {
    return new AnnotationMemberValue((Annotation) obj, cp);
  } else if (obj instanceof ArrayMemberValue) {
    return new ArrayMemberValue((MemberValue) obj, cp);
  } else if (obj instanceof Character) {
    return new CharMemberValue((char) obj, cp);
  } else if (obj instanceof Long) {
    return new LongMemberValue((Long) obj, cp);
  }
  return null;
}
 
Example 13
Source Project: dubbox   Source File: JValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
    MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
    if (memberValue instanceof BooleanMemberValue)
        ((BooleanMemberValue) memberValue).setValue((Boolean) value);
    else if (memberValue instanceof ByteMemberValue)
        ((ByteMemberValue) memberValue).setValue((Byte) value);
    else if (memberValue instanceof CharMemberValue)
        ((CharMemberValue) memberValue).setValue((Character) value);
    else if (memberValue instanceof ShortMemberValue)
        ((ShortMemberValue) memberValue).setValue((Short) value);
    else if (memberValue instanceof IntegerMemberValue)
        ((IntegerMemberValue) memberValue).setValue((Integer) value);
    else if (memberValue instanceof LongMemberValue)
        ((LongMemberValue) memberValue).setValue((Long) value);
    else if (memberValue instanceof FloatMemberValue)
        ((FloatMemberValue) memberValue).setValue((Float) value);
    else if (memberValue instanceof DoubleMemberValue)
        ((DoubleMemberValue) memberValue).setValue((Double) value);
    else if (memberValue instanceof ClassMemberValue)
        ((ClassMemberValue) memberValue).setValue(((Class<?>)value).getName());
    else if (memberValue instanceof StringMemberValue)
        ((StringMemberValue) memberValue).setValue((String) value);
    else if (memberValue instanceof EnumMemberValue) 
        ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
    /* else if (memberValue instanceof AnnotationMemberValue) */
    else if (memberValue instanceof ArrayMemberValue) {
        CtClass arrayType = type.getComponentType();
        int len = Array.getLength(value);
        MemberValue[] members = new MemberValue[len];
        for (int i = 0; i < len; i ++) {
            members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
        }
        ((ArrayMemberValue) memberValue).setValue(members);
    }
    return memberValue;
}
 
Example 14
Source Project: dubbox-hystrix   Source File: JValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
    MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
    if (memberValue instanceof BooleanMemberValue)
        ((BooleanMemberValue) memberValue).setValue((Boolean) value);
    else if (memberValue instanceof ByteMemberValue)
        ((ByteMemberValue) memberValue).setValue((Byte) value);
    else if (memberValue instanceof CharMemberValue)
        ((CharMemberValue) memberValue).setValue((Character) value);
    else if (memberValue instanceof ShortMemberValue)
        ((ShortMemberValue) memberValue).setValue((Short) value);
    else if (memberValue instanceof IntegerMemberValue)
        ((IntegerMemberValue) memberValue).setValue((Integer) value);
    else if (memberValue instanceof LongMemberValue)
        ((LongMemberValue) memberValue).setValue((Long) value);
    else if (memberValue instanceof FloatMemberValue)
        ((FloatMemberValue) memberValue).setValue((Float) value);
    else if (memberValue instanceof DoubleMemberValue)
        ((DoubleMemberValue) memberValue).setValue((Double) value);
    else if (memberValue instanceof ClassMemberValue)
        ((ClassMemberValue) memberValue).setValue(((Class<?>)value).getName());
    else if (memberValue instanceof StringMemberValue)
        ((StringMemberValue) memberValue).setValue((String) value);
    else if (memberValue instanceof EnumMemberValue) 
        ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
    /* else if (memberValue instanceof AnnotationMemberValue) */
    else if (memberValue instanceof ArrayMemberValue) {
        CtClass arrayType = type.getComponentType();
        int len = Array.getLength(value);
        MemberValue[] members = new MemberValue[len];
        for (int i = 0; i < len; i ++) {
            members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
        }
        ((ArrayMemberValue) memberValue).setValue(members);
    }
    return memberValue;
}
 
Example 15
Source Project: dubbox   Source File: JValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
    MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
    if (memberValue instanceof BooleanMemberValue)
        ((BooleanMemberValue) memberValue).setValue((Boolean) value);
    else if (memberValue instanceof ByteMemberValue)
        ((ByteMemberValue) memberValue).setValue((Byte) value);
    else if (memberValue instanceof CharMemberValue)
        ((CharMemberValue) memberValue).setValue((Character) value);
    else if (memberValue instanceof ShortMemberValue)
        ((ShortMemberValue) memberValue).setValue((Short) value);
    else if (memberValue instanceof IntegerMemberValue)
        ((IntegerMemberValue) memberValue).setValue((Integer) value);
    else if (memberValue instanceof LongMemberValue)
        ((LongMemberValue) memberValue).setValue((Long) value);
    else if (memberValue instanceof FloatMemberValue)
        ((FloatMemberValue) memberValue).setValue((Float) value);
    else if (memberValue instanceof DoubleMemberValue)
        ((DoubleMemberValue) memberValue).setValue((Double) value);
    else if (memberValue instanceof ClassMemberValue)
        ((ClassMemberValue) memberValue).setValue(((Class<?>)value).getName());
    else if (memberValue instanceof StringMemberValue)
        ((StringMemberValue) memberValue).setValue((String) value);
    else if (memberValue instanceof EnumMemberValue) 
        ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
    /* else if (memberValue instanceof AnnotationMemberValue) */
    else if (memberValue instanceof ArrayMemberValue) {
        CtClass arrayType = type.getComponentType();
        int len = Array.getLength(value);
        MemberValue[] members = new MemberValue[len];
        for (int i = 0; i < len; i ++) {
            members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
        }
        ((ArrayMemberValue) memberValue).setValue(members);
    }
    return memberValue;
}
 
Example 16
Source Project: tsharding   Source File: MapperAnnotationEnhancer.java    License: MIT License 5 votes vote down vote up
private static MemberValue createMemberValue(Class<?> type, Object val, ConstPool cp) {
    if (type == String.class) {
        return new StringMemberValue((String) val, cp);
    } else {
        throw new RuntimeException("Only support string param value! Invalid param value type:" + type + " and value: " + val);
    }
}
 
Example 17
Source Project: dubbox   Source File: JValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
    MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
    if (memberValue instanceof BooleanMemberValue)
        ((BooleanMemberValue) memberValue).setValue((Boolean) value);
    else if (memberValue instanceof ByteMemberValue)
        ((ByteMemberValue) memberValue).setValue((Byte) value);
    else if (memberValue instanceof CharMemberValue)
        ((CharMemberValue) memberValue).setValue((Character) value);
    else if (memberValue instanceof ShortMemberValue)
        ((ShortMemberValue) memberValue).setValue((Short) value);
    else if (memberValue instanceof IntegerMemberValue)
        ((IntegerMemberValue) memberValue).setValue((Integer) value);
    else if (memberValue instanceof LongMemberValue)
        ((LongMemberValue) memberValue).setValue((Long) value);
    else if (memberValue instanceof FloatMemberValue)
        ((FloatMemberValue) memberValue).setValue((Float) value);
    else if (memberValue instanceof DoubleMemberValue)
        ((DoubleMemberValue) memberValue).setValue((Double) value);
    else if (memberValue instanceof ClassMemberValue)
        ((ClassMemberValue) memberValue).setValue(((Class<?>)value).getName());
    else if (memberValue instanceof StringMemberValue)
        ((StringMemberValue) memberValue).setValue((String) value);
    else if (memberValue instanceof EnumMemberValue) 
        ((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
    /* else if (memberValue instanceof AnnotationMemberValue) */
    else if (memberValue instanceof ArrayMemberValue) {
        CtClass arrayType = type.getComponentType();
        int len = Array.getLength(value);
        MemberValue[] members = new MemberValue[len];
        for (int i = 0; i < len; i ++) {
            members[i] = createMemberValue(cp, arrayType, Array.get(value, i));
        }
        ((ArrayMemberValue) memberValue).setValue(members);
    }
    return memberValue;
}
 
Example 18
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField csspath(String cssPath) {
	Annotation annot = new Annotation(HtmlField.class.getName(), cpool);
       annot.addMemberValue("cssPath", new StringMemberValue(cssPath, cpool));
	attr.addAnnotation(annot);
	return this;
}
 
Example 19
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField attr(String value) {
	Annotation annot = new Annotation(Attr.class.getName(), cpool);
       annot.addMemberValue("value", new StringMemberValue(value, cpool));
       attr.addAnnotation(annot);
	return this;
}
 
Example 20
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField ajax(String url) {
	Annotation annot = new Annotation(Ajax.class.getName(), cpool);
       annot.addMemberValue("url", new StringMemberValue(url, cpool));
       attr.addAnnotation(annot);
	return this;
}
 
Example 21
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField requestParameter(String param) {
	Annotation annot = new Annotation(RequestParameter.class.getName(), cpool);
       annot.addMemberValue("value", new StringMemberValue(param, cpool));
       attr.addAnnotation(annot);
	return this;
}
 
Example 22
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField jsvar(String var, String jsonpath) {
	Annotation annot = new Annotation(JSVar.class.getName(), cpool);
       annot.addMemberValue("var", new StringMemberValue(var, cpool));
       annot.addMemberValue("jsonpath", new StringMemberValue(jsonpath, cpool));
       attr.addAnnotation(annot);
	return this;
}
 
Example 23
Source Project: gecco   Source File: JavassistDynamicField.java    License: MIT License 5 votes vote down vote up
@Override
public DynamicField jsonpath(String value) {
	Annotation annot = new Annotation(JSONPath.class.getName(), cpool);
       annot.addMemberValue("value", new StringMemberValue(value, cpool));
       attr.addAnnotation(annot);
	return this;
}
 
Example 24
Source Project: gecco   Source File: JavassistDynamicBean.java    License: MIT License 5 votes vote down vote up
@Override
public JavassistDynamicBean gecco(String[] matchUrl, String downloader, int timeout, String... pipelines) {
	AnnotationsAttribute attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag);

	Annotation annot = new Annotation(Gecco.class.getName(), cpool);
	// matchUrl
	//annot.addMemberValue("matchUrl", new StringMemberValue(matchUrl, cpool));
	ArrayMemberValue arrayMemberValueMatchUrl = new ArrayMemberValue(cpool);
	MemberValue[] elementMatchUrls = new StringMemberValue[matchUrl.length];
	for (int i = 0; i < matchUrl.length; i++) {
		elementMatchUrls[i] = new StringMemberValue(matchUrl[i], cpool);
	}
	arrayMemberValueMatchUrl.setValue(elementMatchUrls);
	annot.addMemberValue("matchUrl", arrayMemberValueMatchUrl);
	
	
	// downloader
	annot.addMemberValue("downloader", new StringMemberValue(downloader, cpool));
	// timeout
	annot.addMemberValue("timeout", new IntegerMemberValue(cpool, timeout));
	// pipelines
	ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
	MemberValue[] elements = new StringMemberValue[pipelines.length];
	for (int i = 0; i < pipelines.length; i++) {
		elements[i] = new StringMemberValue(pipelines[i], cpool);
	}
	arrayMemberValue.setValue(elements);
	annot.addMemberValue("pipelines", arrayMemberValue);

	attr.addAnnotation(annot);
	cfile.addAttribute(attr);
	return this;
}
 
Example 25
Source Project: statefulj   Source File: CamelBinder.java    License: Apache License 2.0 5 votes vote down vote up
private void addConsumeAnnotation(CtMethod ctMethod, String uri) {
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	Annotation consume = new Annotation(Consume.class.getName(), constPool);
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(uri);
	consume.addMemberValue("uri", valueVal);

	AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	attr.addAnnotation(consume);
	methodInfo.addAttribute(attr);
}
 
Example 26
Source Project: statefulj   Source File: JavassistUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void addResourceAnnotation(CtField field, String beanName) {
	FieldInfo fi = field.getFieldInfo();
	
	AnnotationsAttribute attr = new AnnotationsAttribute(
			field.getFieldInfo().getConstPool(), 
			AnnotationsAttribute.visibleTag);
	Annotation annot = new Annotation(Resource.class.getName(), fi.getConstPool());
	
	StringMemberValue nameValue = new StringMemberValue(fi.getConstPool());
	nameValue.setValue(beanName);
	annot.addMemberValue("name", nameValue);
	
	attr.addAnnotation(annot);
	fi.addAttribute(attr);
}
 
Example 27
Source Project: statefulj   Source File: JerseyBinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void addEndpointMapping(
		CtMethod ctMethod, 
		String method,
		String request) {
	
	// Add Path Annotation
	//
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	AnnotationsAttribute annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	Annotation pathMapping = new Annotation(Path.class.getName(), constPool);
	
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(request);
	
	pathMapping.addMemberValue("value", valueVal);
	
	annoAttr.addAnnotation(pathMapping);

	// Add Verb Annotation (GET|POST|PUT|DELETE)
	//
	String verbClassName = "javax.ws.rs." + method;
	Annotation verb = new Annotation(verbClassName, constPool);
	annoAttr.addAnnotation(verb);
	
	methodInfo.addAttribute(annoAttr);
}
 
Example 28
Source Project: minnal   Source File: ReadMethodCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Annotation getApiOperationAnnotation() {
	ConstPool constPool = getCtClass().getClassFile().getConstPool();
	EntityNodePath path = getResourcePath().getNodePath();
	EntityMetaData metaData = path.get(path.size() - 1).getEntityMetaData();
	Annotation annotation = new Annotation(ApiOperation.class.getCanonicalName(), constPool);
	annotation.addMemberValue("value", new StringMemberValue("Find " + getResourcePath().getNodePath().getName() + " by id", constPool));
	annotation.addMemberValue("response", new ClassMemberValue(metaData.getEntityClass().getCanonicalName(), constPool));
	return annotation;
}
 
Example 29
Source Project: minnal   Source File: UpdateMethodCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Annotation getApiOperationAnnotation() {
	ConstPool constPool = getCtClass().getClassFile().getConstPool();
	Annotation annotation = new Annotation(ApiOperation.class.getCanonicalName(), constPool);
	annotation.addMemberValue("value", new StringMemberValue("Update " + getResourcePath().getNodePath().getName() + " by id", constPool));
	return annotation;
}
 
Example 30
Source Project: minnal   Source File: DeleteMethodCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Annotation getApiOperationAnnotation() {
	ConstPool constPool = getCtClass().getClassFile().getConstPool();
	Annotation annotation = new Annotation(ApiOperation.class.getCanonicalName(), constPool);
	annotation.addMemberValue("value", new StringMemberValue("Delete " + getResourcePath().getNodePath().getName() + " by id", constPool));
	return annotation;
}