/** * Returns an {@link EmptyAttributeValue} or {@link ScopedStringAttributeValue} as appropriate. This method should * be preferred over the constructor when the value may be null or empty. * * @param value to inspect * @param scope of the value * @return {@link EmptyAttributeValue} or {@link ScopedStringAttributeValue} */ public static IdPAttributeValue<?> valueOf(@Nullable final String value, @Nonnull @NotEmpty final String scope) { if (value == null) { return EmptyAttributeValue.NULL; } else if (value.length() == 0) { return EmptyAttributeValue.ZERO_LENGTH; } else { return new ScopedStringAttributeValue(value, scope); } } }
/** {@inheritDoc} */ @Override @Nonnull protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); final IdPAttribute resultantAttribute = new IdPAttribute(getId()); final List<IdPAttributeValue<?>> dependencyValues = PluginDependencySupport.getMergedAttributeValues(workContext, getDependencies(), getId()); final List<StringAttributeValue> valueList = new ArrayList<>(dependencyValues.size()); for (final IdPAttributeValue dependencyValue : dependencyValues) { if (dependencyValue instanceof EmptyAttributeValue) { final EmptyAttributeValue emptyVal = (EmptyAttributeValue) dependencyValue; log.debug("{} ignored empty value of type {}", getLogPrefix(), emptyVal.getDisplayValue()); continue; } if (!(dependencyValue instanceof StringAttributeValue)) { throw new ResolutionException(new UnsupportedAttributeTypeException(getLogPrefix() + "This attribute definition only supports attribute value types of " + StringAttributeValue.class.getName() + " not values of type " + dependencyValue.getClass().getName())); } valueList.add(new ScopedStringAttributeValue((String) dependencyValue.getValue(), scope)); } resultantAttribute.setValues(valueList); return resultantAttribute; }
final JsonValue value = object.get(SCOPED_VALUE_FIELD); if (value instanceof JsonArray && ((JsonArray) value).size() == 2) { return new ScopedStringAttributeValue(((JsonString) ((JsonArray) value).get(0)).getString(), ((JsonString) ((JsonArray) value).get(1)).getString());