private URI parseUri(WebServiceBinding annotation, Class<?> implClass, IntrospectionContext context) { String uriString = getNullableValue(annotation.uri()); try { return new URI(uriString); } catch (URISyntaxException e) { InvalidAnnotation error = new InvalidAnnotation("Invalid web service binding uri", implClass, annotation, implClass, e); context.addError(error); } return URI.create("errorUri"); }
public String getMessage() { if (e == null) { return message + " : " + getCodeLocation(); } return message + ".\n" + e; }
String metadataName = metadataAnnotClass.getName(); String annotationName = annotClass.getName(); InvalidAnnotation error = new InvalidAnnotation("Value for " + metadataName + " must be String or String[] on " + annotationName, annotClass, annotation,
private void parseAddresses(ZeroMQ annotation, ZeroMQMetadata metadata, Class<?> implClass, IntrospectionContext context) { String addresses = annotation.addresses(); if (addresses.length() == 0) { return; } List<SocketAddressDefinition> addressDefinitions = new ArrayList<>(); String[] addressStrings = addresses.split("\\s+"); for (String entry : addressStrings) { String[] tokens = entry.split(":"); if (tokens.length != 2) { context.addError(new InvalidAnnotation("Invalid address specified on ZeroMQ binding: " + entry, null, annotation, implClass)); } else { try { String host = tokens[0]; int port = Integer.parseInt(tokens[1]); addressDefinitions.add(new SocketAddressDefinition(host, port)); } catch (NumberFormatException e) { context.addError(new InvalidAnnotation("Invalid port specified on ZeroMQ binding: " + e.getMessage(), null, annotation, implClass)); } } } metadata.setSocketAddresses(addressDefinitions); }
private void parseHandlerUri(String value, AnnotatedElement element, Binding binding, Class<?> implClass, IntrospectionContext context, org.fabric3.api.annotation.model.BindingHandler annotation) { try { BindingHandler definition = new BindingHandler(new URI(value)); binding.addHandler(definition); } catch (URISyntaxException e) { InvalidAnnotation error = new InvalidAnnotation("Invalid binding handler URI", element, annotation, implClass, e); context.addError(error); } }
private void parseTarget(ZeroMQ annotation, ZeroMQBinding binding, Class<?> implClass, IntrospectionContext context) { String target = annotation.target(); try { URI targetUri = new URI(target); binding.setTargetUri(targetUri); } catch (URISyntaxException e) { InvalidAnnotation error = new InvalidAnnotation("Invalid target URI specified on ZeroMQ annotation: " + target, null, annotation, implClass, e); context.addError(error); } }
private void processSource(Class<?> type, Class<?> clazz, Property property, IntrospectionContext context) { Source source = type.getAnnotation(Source.class); if (source != null) { if (!source.value().startsWith("$")) { InvalidAnnotation error = new InvalidAnnotation("Source attribute must specify an expression starting with '$' on:" + type, type, source, clazz); context.addError(error); } else { property.setSource(source.value()); } } }
public void visitType(Key annotation, Class<?> type, InjectingComponentType componentType, IntrospectionContext context) { if (annotation.value().length() == 0) { context.addError(new InvalidAnnotation("A value must be specified for @Key", type, annotation, type)); return; } componentType.setKey(annotation.value()); } }
private org.fabric3.api.model.type.component.Target parseTarget(String target, Annotation annotation, AccessibleObject accessibleObject, Member member, IntrospectionContext context) { String[] tokens = target.split("/"); if (tokens.length == 1) { return new org.fabric3.api.model.type.component.Target(tokens[0]); } else if (tokens.length == 2) { return new org.fabric3.api.model.type.component.Target(tokens[0], tokens[1]); } else if (tokens.length == 3) { return new org.fabric3.api.model.type.component.Target(tokens[0], tokens[1], tokens[2]); } else { Class<?> clazz = member.getDeclaringClass(); String name = member.getName(); InvalidAnnotation error = new InvalidAnnotation("Invalid target format: " + target + " on " + name, accessibleObject, annotation, clazz); context.addError(error); return null; } } }
context.addError(new InvalidAnnotation("Error reading annotation value ", annotClass, annotation, annotClass, e)); } catch (IllegalAccessException e) { context.addError(new InvalidAnnotation("Error reading annotation value " + annotClass.getName(), annotClass, annotation, annotClass, e)); } catch (InvocationTargetException e) { context.addError(new InvalidAnnotation("Error reading annotation value" + annotClass.getName(), annotClass, annotation, annotClass, e));
private void processSources(org.fabric3.api.annotation.Consumer annotation, Consumer consumer, AccessibleObject member, Class<?> clazz, IntrospectionContext context) { try { if (annotation.sources().length > 0) { for (String target : annotation.sources()) { consumer.addSource(new URI(target)); } } else if (annotation.source().length() > 0) { consumer.addSource(new URI(annotation.source())); } } catch (URISyntaxException e) { InvalidAnnotation error = new InvalidAnnotation("Invalid consumer source on : " + clazz.getName(), member, annotation, clazz, e); context.addError(error); } }
private void processTargets(org.fabric3.api.annotation.Producer annotation, Producer producer, AnnotatedElement element, Class<?> clazz, IntrospectionContext context) { try { if (annotation.targets().length > 0) { for (String target : annotation.targets()) { producer.addTarget(new URI(target)); } } else if (annotation.target().length() > 0) { producer.addTarget(new URI(annotation.target())); } } catch (URISyntaxException e) { InvalidAnnotation error = new InvalidAnnotation("Invalid producer target on : " + clazz.getName(), element, annotation, clazz, e); context.addError(error); } }
public void visitMethod(ManagementOperation annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ManagementInfo info = componentType.getManagementInfo(); if (info == null) { // there was no management annotation on the type - record an error Class<?> clazz = method.getDeclaringClass(); String name = Management.class.getSimpleName(); context.addError(new InvalidAnnotation("Implementation is missing @" + name, method, annotation, clazz)); return; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Set<Role> roles = new HashSet<>(); for (String roleName : annotation.rolesAllowed()) { roles.add(new Role(roleName)); } String path = annotation.path(); org.fabric3.api.annotation.management.OperationType operationType = annotation.type(); OperationType type = OperationType.valueOf(operationType.toString()); ManagementOperationInfo operationInfo = new ManagementOperationInfo(method, path, type, description, roles); info.addOperation(operationInfo); }
if (serviceInterface == null) { if (componentType.getServices().size() != 1) { InvalidAnnotation error = new InvalidAnnotation("Binding annotation must specify a service interface", implClass, annotation, implClass); context.addError(error); return; InvalidAnnotation error = new InvalidAnnotation("Service specified in binding annotation not found: " + name, implClass, annotation, implClass); context.addError(error); return;
private void processSource(AccessibleObject accessible, Class<?> clazz, Property property, IntrospectionContext context) { Source source = accessible.getAnnotation(Source.class); if (source != null) { if (!source.value().startsWith("$")) { InvalidAnnotation error = new InvalidAnnotation("Source attribute must specify an expression starting with '$' on:" + accessible, accessible, source, clazz); context.addError(error); } else { property.setSource(source.value()); // handle defined namespaces Component componentAnnotation = clazz.getAnnotation(Component.class); if (componentAnnotation != null) { Namespace[] namespaces = componentAnnotation.namespaces(); for (Namespace namespace : namespaces) { String prefix = namespace.prefix(); String uri = namespace.uri(); property.addNamespace(prefix, uri); } } } } }
private FileBinding createBinding(org.fabric3.api.binding.file.annotation.FileBinding annotation, Class<?> implClass, IntrospectionContext context) { if(!isActiveForEnvironment(annotation.environments())) { return null; } String name = annotation.name(); if (name.isEmpty()) { name = "FileBinding"; } String location = annotation.location(); if (location.isEmpty()) { InvalidAnnotation error = new InvalidAnnotation("File binding annotation must specify a location", implClass, annotation, implClass); context.addError(error); } Strategy strategy = annotation.strategy(); String archiveLocation = getNullableValue(annotation.archiveLocation()); if (strategy == Strategy.ARCHIVE && archiveLocation == null) { InvalidAnnotation error = new InvalidAnnotation("File binding annotation must specify an archive location", implClass, annotation, implClass); context.addError(error); } String errorLocation = getNullableValue(annotation.errorLocation()); String adapterUri = getNullableValue(annotation.adaptor()); String pattern = getNullableValue(annotation.pattern()); long delay = annotation.delay(); if (delay < -1) { InvalidAnnotation error = new InvalidAnnotation("Invalid delay value specified on file binding", implClass, annotation, implClass); context.addError(error); } return new FileBinding(name, pattern, location, strategy, archiveLocation, errorLocation, null, adapterUri, delay); }
private void parseResponse(JMSConfiguration configuration, JmsBindingMetadata metadata, AnnotatedElement element, Class<?> implClass, IntrospectionContext context) { if (configuration.responseConnectionFactory().isEmpty() && configuration.responseDestination().isEmpty()) { return; } if (!configuration.responseConnectionFactory().isEmpty() && configuration.responseDestination().isEmpty()) { InvalidAnnotation error = new InvalidAnnotation("A response destination was not specified", element, configuration, implClass); context.addError(error); } ResponseDefinition response = new ResponseDefinition(); Destination responseDestination = new Destination(); responseDestination.setName(configuration.responseDestination()); response.setDestination(responseDestination); ConnectionFactoryDefinition responseFactory = new ConnectionFactoryDefinition(); responseFactory.setName(configuration.responseConnectionFactory()); response.setConnectionFactory(responseFactory); metadata.setResponse(response); }
private void addTargets(AccessibleObject accessibleObject, Member member, IntrospectionContext context, Reference definition) { Targets targetsAnnotation = accessibleObject.getAnnotation(Targets.class); if (targetsAnnotation != null) { Multiplicity multiplicity = definition.getMultiplicity(); if (multiplicity != Multiplicity.ONE_N && multiplicity != Multiplicity.ZERO_N) { Class<?> clazz = member.getDeclaringClass(); String name = member.getName(); InvalidAnnotation error = new InvalidAnnotation("Reference is not a multiplicity: " + name, accessibleObject, targetsAnnotation, clazz); context.addError(error); return; } for (String value : targetsAnnotation.value()) { org.fabric3.api.model.type.component.Target target = parseTarget(value, targetsAnnotation, accessibleObject, member, context); if (target != null) { definition.addTarget(target); } } } else { Target targetAnnotation = accessibleObject.getAnnotation(Target.class); if (targetAnnotation != null) { org.fabric3.api.model.type.component.Target target = parseTarget(targetAnnotation.value(), targetAnnotation, accessibleObject, member, context); if (target != null) { definition.addTarget(target); } } } }