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;
25 import org.onap.policy.apex.context.ContextRuntimeException;
26 import org.onap.policy.apex.context.SchemaHelper;
27 import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
29 import org.onap.policy.apex.model.eventmodel.concepts.AxField;
30 import org.slf4j.ext.XLogger;
31 import org.slf4j.ext.XLoggerFactory;
34 * Instances of the Class EnField are event fields being passed through the Apex system.
36 * @author Liam Fallon (liam.fallon@ericsson.com)
38 public class EnField implements Serializable {
39 private static final long serialVersionUID = -5713525780081840333L;
41 // Logger for this class
42 private static final XLogger LOGGER = XLoggerFactory.getXLogger(EnField.class);
44 // The definition of this field in the Apex model
45 private final AxField axField;
47 // The schema helper for this field
48 private transient SchemaHelper schemaHelper;
50 // The value of this field
51 private final transient Object value;
54 * Instantiates a new EnField, an Engine Field.
56 * @param axField the field definition from the Apex model
57 * @param value the value
59 public EnField(final AxField axField, final Object value) {
60 // Save the field definition from the Apex model
61 this.axField = axField;
64 // Get a schema helper to handle translations of fields to and from the schema
66 schemaHelper = new SchemaHelperFactory().createSchemaHelper(axField.getKey(), axField.getSchema());
67 } catch (final ContextRuntimeException e) {
68 final String message = "schema helper cannot be created for parameter with key \"" + axField.getId()
69 + "\" with schema \"" + axField.getSchema() + "\"";
70 LOGGER.warn(message, e);
71 throw new EnException(message, e);
76 * Gets the field definition of this field.
78 * @return the field definition
80 public AxField getAxField() {
85 * Gets the schema helper of this field.
87 * @return the schema helper for this field
89 public SchemaHelper getSchemaHelper() {
94 * Get the name of the field.
96 * @return the field name
98 public String getName() {
99 return axField.getKey().getLocalName();
103 * Get the key of the field.
105 * @return the field key
107 public AxReferenceKey getKey() {
108 return axField.getKey();
112 * Get the value of the field.
116 public Object getValue() {
124 public String toString() {
125 return "EnField [axField=" + axField + ", value=" + value + "]";
129 * Get an assignable object that will work with the field.
131 * @return the assignable value
133 public Object getAssignableValue() {
134 // Use the schema helper to get the translated value of the object
135 return schemaHelper.unmarshal(value);
139 * Is the value object assignable to this field.
141 * @return true if the value is assignable
143 public boolean isAssignableValue() {
145 schemaHelper.unmarshal(value);
147 } catch (final Exception e) {
148 if (LOGGER.isTraceEnabled()) {
149 LOGGER.trace("value {} is not assignable to this field", value, e);