View Javadoc
1   /*
2    * Prometheus: Application Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.prometheus.data;
18  
19  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
20  import io.github.tonywasher.joceanus.metis.data.MetisDataType;
21  import io.github.tonywasher.joceanus.metis.field.MetisFieldVersioned;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusEncrypted.PrometheusEncryptedDataItemCtl;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusEncrypted.PrometheusEncryptedFieldSetCtl;
24  
25  /**
26   * Prometheus Data fields.
27   *
28   * @param <T> the data type
29   */
30  public class PrometheusEncryptedField<T extends PrometheusEncryptedDataItemCtl>
31          extends MetisFieldVersioned<T> {
32      /**
33       * Constructor.
34       *
35       * @param pAnchor    the anchor
36       * @param pId        the fieldId
37       * @param pDataType  the dataType of the field
38       * @param pMaxLength the maximum length of the field
39       */
40      PrometheusEncryptedField(final PrometheusEncryptedFieldSetCtl<T> pAnchor,
41                               final MetisDataFieldId pId,
42                               final MetisDataType pDataType,
43                               final Integer pMaxLength) {
44          /* Initialise underlying class */
45          super(pAnchor, pId, pDataType, pMaxLength, true);
46      }
47  
48      @Override
49      protected void checkValidity() {
50          /* Check underlying options */
51          super.checkValidity();
52  
53          /* Object/ByteArray/Links are not valid for Encryption */
54          switch (getDataType()) {
55              case OBJECT, BYTEARRAY, LINK, LINKSET:
56                  throw new IllegalArgumentException("Invalid encrypted object");
57              default:
58                  break;
59          }
60      }
61  }