use of javassist.bytecode.annotation.Annotation in project BroadleafCommerce by BroadleafCommerce.
the class DirectCopyClassTransformer method getEntityListeners.
protected Annotation getEntityListeners(ConstPool constantPool, Annotation existingEntityListeners, Annotation templateEntityListeners) {
Annotation listeners = new Annotation(EntityListeners.class.getName(), constantPool);
ArrayMemberValue listenerArray = new ArrayMemberValue(constantPool);
Set<MemberValue> listenerMemberValues = new HashSet<>();
{
ArrayMemberValue templateListenerValues = (ArrayMemberValue) templateEntityListeners.getMemberValue("value");
listenerMemberValues.addAll(Arrays.asList(templateListenerValues.getValue()));
logger.debug("Adding template values to new EntityListeners");
}
if (existingEntityListeners != null) {
ArrayMemberValue oldListenerValues = (ArrayMemberValue) existingEntityListeners.getMemberValue("value");
listenerMemberValues.addAll(Arrays.asList(oldListenerValues.getValue()));
logger.debug("Adding previous values to new EntityListeners");
}
listenerArray.setValue(listenerMemberValues.toArray(new MemberValue[listenerMemberValues.size()]));
listeners.addMemberValue("value", listenerArray);
return listeners;
}
use of javassist.bytecode.annotation.Annotation in project BroadleafCommerce by BroadleafCommerce.
the class QueryConfigurationClassTransformer method processClassLevelAnnotations.
/**
* Look for any existing {@link NamedQueries} or {@link NamedNativeQueries} and embellish those declarations, if applicable.
* Otherwise, create new declarations of these annotations as needed.
*
* @param constantPool
* @param pool
* @param object
* @throws NotFoundException
*/
protected void processClassLevelAnnotations(ConstPool constantPool, ClassPool pool, Object object) throws NotFoundException {
if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) {
AnnotationsAttribute attr = (AnnotationsAttribute) object;
Annotation[] items = attr.getAnnotations();
List<Annotation> newItems = new ArrayList<Annotation>();
ArrayMemberValue namedQueryArray = new ArrayMemberValue(constantPool);
ArrayMemberValue nativeQueryArray = new ArrayMemberValue(constantPool);
for (Annotation annotation : items) {
String typeName = annotation.getTypeName();
if (typeName.equals(NamedQueries.class.getName())) {
namedQueryArray = (ArrayMemberValue) annotation.getMemberValue("value");
} else if (typeName.equals(NamedNativeQueries.class.getName())) {
nativeQueryArray = (ArrayMemberValue) annotation.getMemberValue("value");
} else {
newItems.add(annotation);
}
}
if (!namedQueries.isEmpty()) {
prepareNamedQueries(constantPool, pool, namedQueryArray);
Annotation namedQueriesAnnotation = new Annotation(NamedQueries.class.getName(), constantPool);
namedQueriesAnnotation.addMemberValue("value", namedQueryArray);
newItems.add(namedQueriesAnnotation);
}
if (!nativeQueries.isEmpty()) {
prepareNativeQueries(constantPool, pool, nativeQueryArray);
Annotation nativeQueriesAnnotation = new Annotation(NamedQueries.class.getName(), constantPool);
nativeQueriesAnnotation.addMemberValue("value", nativeQueryArray);
newItems.add(nativeQueriesAnnotation);
}
attr.setAnnotations(newItems.toArray(new Annotation[newItems.size()]));
}
}
use of javassist.bytecode.annotation.Annotation in project BroadleafCommerce by BroadleafCommerce.
the class QueryConfigurationClassTransformer method prepareQueryHints.
/**
* Prepare any {@link QueryHint} declarations
*
* @param constantPool
* @param queryHints
* @param hint
*/
protected void prepareQueryHints(ConstPool constantPool, List<AnnotationMemberValue> queryHints, QueryHint hint) {
Annotation queryHint = new Annotation(QueryHint.class.getName(), constantPool);
StringMemberValue hintName = new StringMemberValue(constantPool);
hintName.setValue(hint.name());
queryHint.addMemberValue("name", hintName);
StringMemberValue hintValue = new StringMemberValue(constantPool);
hintValue.setValue(hint.value());
queryHint.addMemberValue("value", hintValue);
AnnotationMemberValue hintAnnotation = new AnnotationMemberValue(queryHint, constantPool);
queryHints.add(hintAnnotation);
}
use of javassist.bytecode.annotation.Annotation in project BroadleafCommerce by BroadleafCommerce.
the class QueryConfigurationClassTransformer method prepareNamedQueries.
/**
* Prepare the {@link NamedQueries} declaration
*
* @param constantPool
* @param pool
* @param queryArray
* @throws NotFoundException
*/
protected void prepareNamedQueries(ConstPool constantPool, ClassPool pool, ArrayMemberValue queryArray) throws NotFoundException {
List<MemberValue> values;
if (queryArray.getValue() != null) {
values = new ArrayList<MemberValue>(Arrays.asList(queryArray.getValue()));
} else {
values = new ArrayList<MemberValue>();
}
for (NamedQuery query : namedQueries) {
Annotation namedQuery = new Annotation(NamedQuery.class.getName(), constantPool);
StringMemberValue name = new StringMemberValue(constantPool);
name.setValue(query.name());
namedQuery.addMemberValue("name", name);
StringMemberValue queryString = new StringMemberValue(constantPool);
queryString.setValue(query.query());
namedQuery.addMemberValue("query", queryString);
EnumMemberValue lockMode = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("LockModeType"));
lockMode.setType(LockModeType.class.getName());
lockMode.setValue(query.lockMode().toString());
namedQuery.addMemberValue("lockMode", lockMode);
List<AnnotationMemberValue> queryHints = new ArrayList<AnnotationMemberValue>();
for (QueryHint hint : query.hints()) {
prepareQueryHints(constantPool, queryHints, hint);
}
ArrayMemberValue hintArray = new ArrayMemberValue(constantPool);
hintArray.setValue(queryHints.toArray(new AnnotationMemberValue[queryHints.size()]));
namedQuery.addMemberValue("hints", hintArray);
AnnotationMemberValue queryAnnotation = new AnnotationMemberValue(namedQuery, constantPool);
values.add(queryAnnotation);
}
queryArray.setValue(values.toArray(new MemberValue[values.size()]));
}
use of javassist.bytecode.annotation.Annotation in project BroadleafCommerce by BroadleafCommerce.
the class RemoveAnnotationClassTransformer method stripAnnotation.
protected AnnotationsAttribute stripAnnotation(ConstPool constantPool, List<?> attributes) {
Iterator<?> itr = attributes.iterator();
AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag);
while (itr.hasNext()) {
Object object = itr.next();
if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) {
AnnotationsAttribute attr = (AnnotationsAttribute) object;
Annotation[] items = attr.getAnnotations();
for (Annotation annotation : items) {
String typeName = annotation.getTypeName();
if (typeName.equals(annotationClass)) {
logger.debug(String.format("Stripping out %s annotation", annotationClass));
continue;
}
annotationsAttribute.addAnnotation(annotation);
}
itr.remove();
}
}
return annotationsAttribute;
}
Aggregations