1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.schemagen.json.impl;
7   
8   import gov.nist.secauto.metaschema.core.util.ObjectUtils;
9   import gov.nist.secauto.metaschema.schemagen.json.IDefineableJsonSchema;
10  import gov.nist.secauto.metaschema.schemagen.json.IJsonGenerationState;
11  
12  import edu.umd.cs.findbugs.annotations.NonNull;
13  import edu.umd.cs.findbugs.annotations.Nullable;
14  
15  public abstract class AbstractDefineableJsonSchema implements IDefineableJsonSchema {
16    @Nullable
17    private String name;
18  
19    protected abstract String generateDefinitionName(@NonNull IJsonGenerationState state);
20  
21    @Override
22    public String getDefinitionName(IJsonGenerationState state) {
23      synchronized (this) {
24        if (this.name == null) {
25          this.name = generateDefinitionName(state);
26        }
27        assert this.name != null;
28        return this.name;
29      }
30    }
31  
32    @Override
33    public String getDefinitionRef(IJsonGenerationState state) {
34      return ObjectUtils.notNull(new StringBuilder()
35          .append("#/definitions/")
36          .append(getDefinitionName(state))
37          .toString());
38    }
39  }