001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.metaschema.databind.model.info; 007 008import gov.nist.secauto.metaschema.core.model.IBoundObject; 009import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; 010import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModel; 011import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelNamed; 012 013import edu.umd.cs.findbugs.annotations.NonNull; 014 015public abstract class AbstractModelInstanceReadHandler<ITEM> implements IModelInstanceReadHandler<ITEM> { 016 @NonNull 017 private final IBoundInstanceModel<ITEM> instance; 018 @NonNull 019 private final IBoundObject parentObject; 020 021 protected AbstractModelInstanceReadHandler( 022 @NonNull IBoundInstanceModel<ITEM> instance, 023 @NonNull IBoundObject parentObject) { 024 this.instance = instance; 025 this.parentObject = parentObject; 026 } 027 028 /** 029 * Get the model instance associated with this handler. 030 * 031 * @return the collection information 032 */ 033 @NonNull 034 public IBoundInstanceModel<ITEM> getInstance() { 035 return instance; 036 } 037 038 /** 039 * Get the collection Java type information associated with this handler. 040 * 041 * @return the collection information 042 */ 043 @NonNull 044 public IModelInstanceCollectionInfo<ITEM> getCollectionInfo() { 045 return getInstance().getCollectionInfo(); 046 } 047 048 /** 049 * Get the object onto which parsed data will be stored. 050 * 051 * @return the parentObject 052 */ 053 @NonNull 054 public IBoundObject getParentObject() { 055 return parentObject; 056 } 057 058 @Override 059 public String getJsonKeyFlagName() { 060 IBoundInstanceModel<?> instance = getInstance(); 061 String retval = null; 062 if (instance instanceof IBoundInstanceModelNamed) { 063 IBoundInstanceFlag jsonKey = ((IBoundInstanceModelNamed<?>) instance).getEffectiveJsonKey(); 064 if (jsonKey != null) { 065 retval = jsonKey.getEffectiveName(); 066 } 067 } 068 return retval; 069 } 070}