public EntityParser(Class<?> table) { if (!table.isAnnotationPresent(Entity.class) || !table.isAnnotationPresent(javax.persistence.Table.class)) { throw new AnnotationFormatError("The class hasn't got Entity or Table annotation!"); } entity = table; }
@Override public void loadValueIntoField(Object fixtureObject) { field.setAccessible(true); try { Object value = scopedObject.getObject(); field.set(fixtureObject, value); } catch (InstantiationException e) { throw new AnnotationFormatError("Could not create object on field " + field.getName()); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not set object on field " + field.getName()); } }
@Override public void loadValueIntoField(Object fixtureObject) { field.setAccessible(true); try { Object value = scopedObject.getObject(); field.set(fixtureObject, value); } catch (InstantiationException e) { throw new AnnotationFormatError("Could not create object on field " + field.getName()); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not set object on field " + field.getName()); } }
@Override public Object getValueForParameter(Method method, Class<?> parameterClass, Annotation[] annotations) { if (annotations.length != 1) { throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } Annotation annotation = annotations[0]; if (parameterAnnotation.equals(annotation.annotationType())) { if (!(parameterClass.equals(parameterValue.getClass()))) { throw new AnnotationFormatError("Error invoking '" + method + "'. Parameter with annotation '" + parameterAnnotation + "' is expected to be of type '" + parameterValue.getClass().getName() + "'"); } return parameterValue; } throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } }
@Override public Object getValueForParameter(Method method, Class<?> parameterClass, Annotation[] annotations) { if (annotations.length != 1) { throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } Annotation annotation = annotations[0]; if (parameterAnnotation.equals(annotation.annotationType())) { if (!(parameterClass.equals(parameterValue.getClass()))) { throw new AnnotationFormatError("Error invoking '" + method + "'. Parameter with annotation '" + parameterAnnotation + "' is expected to be of type '" + parameterValue.getClass().getName() + "'"); } return parameterValue; } throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } }
@Override public void saveValueFromField(Object fixtureObject) { field.setAccessible(true); Object currentValue = null; try { currentValue = field.get(fixtureObject); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not get object on field " + field.getName()); } scopedObject.setObject(currentValue); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processOutputAnnotation() { final Outputs annotation = getClass().getAnnotation(Outputs.class); if (null == annotation) { throw new AnnotationFormatError("All consumer producer function classes must have outputs defined using the 'Outputs' annotation on the class." + " Class: " + getClass()); } outputs = annotation.value(); }
@Override public void saveValueFromField(Object fixtureObject) { field.setAccessible(true); Object currentValue = null; try { currentValue = field.get(fixtureObject); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not get object on field " + field.getName()); } scopedObject.setObject(currentValue); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processInputAnnotation() { final Inputs annotation = getClass().getAnnotation(Inputs.class); if (null == annotation) { throw new AnnotationFormatError("All consumer function classes must have inputs defined using the 'Inputs' annotation on the class." + " Class: " + getClass()); } inputs = annotation.value(); }
private void createScopedObjectField(FixtureType fixtureType, Field field) { if (!field.getType().equals(ScopedObjectHolder.class)) { throw new AnnotationFormatError(SimpleFormatter.format("The '%s' annotation can only be applied to fields of type '%s'", ConcordionScoped.class.getSimpleName(), ScopedObjectHolder.class.getSimpleName())); } ConcordionScoped annotation = field.getAnnotation(ConcordionScoped.class); Scope fieldScope = annotation.value(); String name = field.getName(); ScopedObject scopedObject = createScopedObject(fixtureType, name, fieldScope); scopedFields.get(fieldScope).add(new ScopedFieldImpl(scopedObject, field)); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processOutputAnnotation() { final Outputs annotation = getClass().getAnnotation(Outputs.class); if (null == annotation || null == annotation.value()) { throw new AnnotationFormatError("All producer function classes must have outputs defined using the 'Outputs' annotation on the class."); } outputs = annotation.value(); }
private void createScopedObjectField(FixtureType fixtureType, Field field) { if (!field.getType().equals(ScopedObjectHolder.class)) { throw new AnnotationFormatError(SimpleFormatter.format("The '%s' annotation can only be applied to fields of type '%s'", ConcordionScoped.class.getSimpleName(), ScopedObjectHolder.class.getSimpleName())); } ConcordionScoped annotation = field.getAnnotation(ConcordionScoped.class); Scope fieldScope = annotation.value(); String name = field.getName(); ScopedObject scopedObject = createScopedObject(fixtureType, name, fieldScope); scopedFields.get(fieldScope).add(new ScopedFieldImpl(scopedObject, field)); }
if (parameters.length > 0) { if (parameterSupplier == null) { throw new AnnotationFormatError("Error invoking " + method + ". Methods annotated with '" + methodAnnotation + "' are not allowed parameters"); throw new AnnotationFormatError("Invalid permissions to invoke method: " + method.getName()); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) {
if (parameters.length > 0) { if (parameterSupplier == null) { throw new AnnotationFormatError("Error invoking " + method + ". Methods annotated with '" + methodAnnotation + "' are not allowed parameters"); throw new AnnotationFormatError("Invalid permissions to invoke method: " + method.getName()); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) {
throw new AnnotationFormatError("cacheName must be specified in either CacheDefaults or CacheRemove or CacheRemoveAll for: " + method);
protected CacheKey createCacheKey(ProceedingJoinPoint pjp, RequestCache requestCache) { final Signature signature = pjp.getSignature(); final Class<?> declaringType = signature.getDeclaringType(); final String signatureLongString = signature.toLongString(); final boolean[] keyMask = requestCache.keyMask(); final Object[] args = pjp.getArgs(); final Object[] keyArgs; if (keyMask.length == 0) { keyArgs = args; } else if (keyMask.length != args.length) { throw new AnnotationFormatError( "RequestCache.keyMask has an invalid length on: " + signature.toLongString()); } else { keyArgs = new Object[args.length]; for (int i = 0; i < args.length; i++) { if (keyMask[i]) { keyArgs[i] = args[i]; } } } return CacheKey.build(signatureLongString, declaringType, keyArgs); }
protected CacheKey createCacheKey(ProceedingJoinPoint pjp, RequestCache requestCache) { final Signature signature = pjp.getSignature(); final Class<?> declaringType = signature.getDeclaringType(); final String signatureLongString = signature.toLongString(); final boolean[] keyMask = requestCache.keyMask(); final Object[] args = pjp.getArgs(); final Object[] keyArgs; if (keyMask.length == 0) { keyArgs = args; } else if (keyMask.length != args.length) { throw new AnnotationFormatError( "RequestCache.keyMask has an invalid length on: " + signature.toLongString()); } else { keyArgs = new Object[args.length]; for (int i = 0; i < args.length; i++) { if (keyMask[i]) { keyArgs[i] = args[i]; } } } return CacheKey.build(signatureLongString, declaringType, keyArgs); }
/** * Get the {@link AbstractInternalCacheInvocationContext} for the invocation * * @param invocation The CDI invocation context * @return The cache invocation context */ @Override public InternalCacheInvocationContext<? extends Annotation> getCacheInvocationContext(I invocation) { final Method method = this.getMethod(invocation); final Class<?> targetClass = this.getTargetClass(invocation); final StaticCacheInvocationContext<? extends Annotation> staticCacheInvocationContext = this.getMethodDetails(method, targetClass); if (staticCacheInvocationContext == null) { throw new AnnotationFormatError("At least one cache related annotation must be specified on " + method + " for intercepted invocation to be valid: " + invocation); } return createCacheInvocationContextImpl(staticCacheInvocationContext, invocation); }
/** * Get the {@link InternalCacheKeyInvocationContext} for the CDI invocation. * * @param invocation The CDI invocation context * @return The keyed cache invocation context * @throws UnsupportedOperationException if the invocation context is available for the invocation */ @Override public InternalCacheKeyInvocationContext<? extends Annotation> getCacheKeyInvocationContext(I invocation) { final Method method = this.getMethod(invocation); final Class<?> targetClass = this.getTargetClass(invocation); final StaticCacheInvocationContext<? extends Annotation> staticCacheInvocationContext = this.getMethodDetails(method, targetClass); if (staticCacheInvocationContext == null) { throw new AnnotationFormatError("At least one cache related annotation must be specified on " + method + " for intercepted invocation to be valid: " + invocation); } switch (staticCacheInvocationContext.getInterceptorType()) { case CACHE_RESULT: case CACHE_PUT: case CACHE_REMOVE_ENTRY: { return createCacheKeyInvocationContextImpl( (StaticCacheKeyInvocationContext<? extends Annotation>) staticCacheInvocationContext, invocation); } default: { throw new UnsupportedOperationException( "Cannot get InternalCacheKeyInvocationContext for interceptor type: " + staticCacheInvocationContext.getInterceptorType()); } } }
cacheRemoveAnnotation != null ^ cacheRemoveAllAnnotation != null)) { throw new AnnotationFormatError( "Multiple cache annotations were found on " + method + " only one cache annotation per method is allowed"); } else if (cacheResultAnnotation != null) {