2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.engine.event;
23 import java.io.Serializable;
24 import org.onap.policy.apex.context.ContextRuntimeException;
25 import org.onap.policy.apex.context.SchemaHelper;
26 import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
28 import org.onap.policy.apex.model.eventmodel.concepts.AxField;
29 import org.slf4j.ext.XLogger;
30 import org.slf4j.ext.XLoggerFactory;
33 * Instances of the Class EnField are event fields being passed through the Apex system.
35 * @author Liam Fallon (liam.fallon@ericsson.com)
37 public class EnField implements Serializable {
38 private static final long serialVersionUID = -5713525780081840333L;
40 // Logger for this class
41 private static final XLogger LOGGER = XLoggerFactory.getXLogger(EnField.class);
43 // The definition of this field in the Apex model
44 private final AxField axField;
46 // The schema helper for this field
47 private transient SchemaHelper schemaHelper;
49 // The value of this field
50 private final transient Object value;
53 * Instantiates a new EnField, an Engine Field.
55 * @param axField the field definition from the Apex model
56 * @param value the value
58 public EnField(final AxField axField, final Object value) {
59 // Save the field definition from the Apex model
60 this.axField = axField;
63 // Get a schema helper to handle translations of fields to and from the schema
65 schemaHelper = new SchemaHelperFactory().createSchemaHelper(axField.getKey(), axField.getSchema());
66 } catch (final ContextRuntimeException e) {
67 final String message = "schema helper cannot be created for parameter with key \"" + axField.getId()
68 + "\" with schema \"" + axField.getSchema() + "\"";
69 LOGGER.warn(message, e);
70 throw new EnException(message, e);
75 * Gets the field definition of this field.
77 * @return the field definition
79 public AxField getAxField() {
84 * Gets the schema helper of this field.
86 * @return the schema helper for this field
88 public SchemaHelper getSchemaHelper() {
93 * Get the name of the field.
95 * @return the field name
97 public String getName() {
98 return axField.getKey().getLocalName();
102 * Get the key of the field.
104 * @return the field key
106 public AxReferenceKey getKey() {
107 return axField.getKey();
111 * Get the value of the field.
115 public Object getValue() {
123 public String toString() {
124 return "EnField [axField=" + axField + ", value=" + value + "]";
128 * Get an assignable object that will work with the field.
130 * @return the assignable value
132 public Object getAssignableValue() {
133 // Use the schema helper to get the translated value of the object
134 return schemaHelper.unmarshal(value);
138 * Is the value object assignable to this field.
140 * @return true if the value is assignable
142 public boolean isAssignableValue() {
144 schemaHelper.unmarshal(value);
146 } catch (final Exception e) {
147 if (LOGGER.isTraceEnabled()) {
148 LOGGER.trace("value {} is not assignable to this field", value, e);