public void processMultiplicity(ReferenceDefinition definition, boolean required, Type type, TypeMapping typeMapping) { MultiplicityType multiplicityType = introspectMultiplicity(type, typeMapping); if (MultiplicityType.COLLECTION == multiplicityType) { Multiplicity multiplicity = required ? Multiplicity.ONE_N : Multiplicity.ZERO_N; definition.setMultiplicity(multiplicity); } else if (MultiplicityType.DICTIONARY == multiplicityType) { Multiplicity multiplicity = required ? Multiplicity.ONE_N : Multiplicity.ZERO_N; definition.setMultiplicity(multiplicity); DataType<?> keyType = getKeyType(type, typeMapping); definition.setKeyed(true); definition.setKeyDataType(keyType); } else { Multiplicity multiplicity = required ? Multiplicity.ONE_ONE : Multiplicity.ZERO_ONE; definition.setMultiplicity(multiplicity); } }
private void addReference(InjectingComponentType componentType, TypeMapping typeMapping, String name, Type parameterType, InjectionSite site, Annotation[] annotations, IntrospectionContext context) { Class<?> type = helper.getBaseType(parameterType, typeMapping); ServiceContract contract = contractProcessor.introspect(type, context, componentType); ReferenceDefinition reference = new ReferenceDefinition(name, contract); helper.processMultiplicity(reference, false, parameterType, typeMapping); if (policyProcessor != null) { for (Annotation annotation : annotations) { policyProcessor.process(annotation, reference, context); } } componentType.add(reference, site); } }
/** * Merges the POJO component type into the web component type. * * @param webType the web component type to merge into * @param componentType the component type to merge * @param context the introspection context */ private void mergeComponentTypes(WebComponentType webType, InjectingComponentType componentType, IntrospectionContext context) { for (Map.Entry<String, ReferenceDefinition> entry : componentType.getReferences().entrySet()) { String name = entry.getKey(); AbstractReference reference = webType.getReferences().get(name); if (reference != null) { ServiceContract source = reference.getServiceContract(); ServiceContract target = entry.getValue().getServiceContract(); MatchResult result = matcher.isAssignableFrom(source, target, false); if (!result.isAssignable()) { // TODO display areas where it was not matching IncompatibleReferenceDefinitions failure = new IncompatibleReferenceDefinitions(name); context.addError(failure); } } else { webType.add(entry.getValue()); } } // apply all injection sites for (Map.Entry<InjectionSite, Injectable> entry : componentType.getInjectionSites().entrySet()) { webType.addMapping(componentType.getImplClass(), entry.getKey(), entry.getValue()); } }
@SuppressWarnings({"unchecked"}) private ReferenceDefinition createDefinition(String name, boolean required, Type type, Class<?> implClass, Annotation[] annotations, InjectingComponentType componentType, IntrospectionContext context) { TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> baseType = helper.getBaseType(type, typeMapping); ServiceContract contract = contractProcessor.introspect(baseType, implClass, context, componentType); ReferenceDefinition definition = new ReferenceDefinition(name, contract); helper.processMultiplicity(definition, required, type, typeMapping); if (policyProcessor != null) { for (Annotation annotation : annotations) { policyProcessor.process(annotation, definition, context); } } return definition; }