All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.memority.citadel.shared.api.context.AttributeContext Maven / Gradle / Ivy

Go to download

This artifact provides the API classes that are necessary to implement general configuration Rules on the Memority IM platform.

There is a newer version: 3.43.1
Show newest version
/*
 * Copyright (c) 2016-2023 Memority. All Rights Reserved.
 *
 * This file is part of Memority Citadel API , a Memority project.
 *
 * This file is released under the Memority Public Artifacts End-User License Agreement,
 * see 
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 */
package com.memority.citadel.shared.api.context;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.memority.toolkit.rule.api.context.ContextSupport;
import com.memority.citadel.shared.api.im.AttributeValue;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * The context of an individual attribute, when running while processing a single attribute. Note that
 * this attribute may be processed in the context of an IM object, in which case a accompanying {@link OperationContext}
 * is also available.
 *
 * 

Note: this context is immutable.

* * @see CitadelContext */ public class AttributeContext extends ContextSupport implements Map { public final static String KEY_ATTRIBUTE_VALUE= "ATTRIBUTE_VALUE"; public final static String KEY_ID = "ID"; public final static String KEY_VALUES = "VALUES"; public AttributeContext(AttributeValue attributeValue) { super(false); this.mutableMap.put(KEY_ATTRIBUTE_VALUE, attributeValue); this.mutableMap.put(KEY_ID, attributeValue.getId()); this.mutableMap.put(KEY_VALUES, attributeValue.getValues()); } /** * Returns the context attribute as an {@link AttributeValue}. * @return the AttributeValue */ @JsonIgnore @SuppressWarnings("unchecked") public AttributeValue getAttributeValue() { return (AttributeValue)this.get(KEY_ATTRIBUTE_VALUE); } /** * Return the Managed Object's values for the attribute. Returns an empty list if there is no such * attribute or it is empty. *

This convenience method automatically performs a cast to the requested value type after the * actual value has been checked.

* * @param valueType the expected class type for the attribute * @return the list of values, empty if no value is set for the given identifier, never null * @param the value type */ @JsonIgnore @SuppressWarnings("unchecked") public List getValues(Class valueType) { List values = getValues(); List result = new ArrayList(); for (Object value:values) { if (value == null) { result.add(null); continue; } if (! valueType.isAssignableFrom(value.getClass())) { throw new ClassCastException(String.format("Actual value type of attribute '%s' is '%s' (incompatible with '%s')", getId(), value.getClass(), valueType)); } @SuppressWarnings("unchecked") T val = (T)value; result.add(val); } return result; } /** * Return the Managed Object's values for the attribute. Returns an empty list if there is no such * attribute or it is empty. * * @return the list of values, empty if no value is set for the given identifier, never null */ @JsonIgnore public List getValues() { return (List) this.get(KEY_VALUES); } /** * Returns the context attribute identifier. Equivalent to * getAttributeValue().getId(). * * @return the attribute identifier */ @JsonIgnore @SuppressWarnings("unchecked") public String getId() { return (String) this.get(KEY_ID); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy