com.networknt.jsonoverlay.RefOverlay Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-overlay Show documentation
Show all versions of json-overlay Show documentation
A fork of RepreZen JsonOverlay with all dependencies and code generation removed
/*********************************************************************
* Copyright (c) 2017 ModelSolv, Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ModelSolv, Inc.
* - initial API and implementation and/or initial documentation
**********************************************************************/
package com.networknt.jsonoverlay;
import com.fasterxml.jackson.databind.JsonNode;
public class RefOverlay {
private Reference reference;
private JsonOverlay> parent;
private JsonOverlay target = null;
private OverlayFactory factory;
private ReferenceManager refMgr;
public RefOverlay(JsonNode json, JsonOverlay> parent, OverlayFactory factory, ReferenceManager refMgr) {
this.reference = refMgr.getReference(json);
this.parent = parent; // parent of reference, not parent of referent
this.factory = factory;
this.refMgr = refMgr;
}
public RefOverlay(Reference reference, JsonOverlay> parent, OverlayFactory factory, ReferenceManager refMgr) {
this.reference = reference;
this.parent = parent;
this.factory = factory;
this.refMgr = refMgr;
}
/* package */JsonOverlay getOverlay() {
if (!reference.isResolved()) {
reference.resolve();
}
if (target == null && reference.isValid()) {
ReferenceRegistry registry = refMgr.getRegistry();
{
@SuppressWarnings("unchecked")
JsonOverlay castTarget = (JsonOverlay) registry.getOverlay(reference.getNormalizedRef(),
factory.getSignature());
this.target = castTarget;
}
if (target == null) {
@SuppressWarnings("unchecked")
JsonOverlay castTarget = (JsonOverlay) registry.getOverlay(reference.getJson(),
factory.getSignature());
this.target = castTarget;
}
if (target == null) {
target = factory.create(reference.getJson(), null, reference.getManager());
target._setCreatingRef(reference);
refMgr.getRegistry().register(reference.getNormalizedRef(), factory.getSignature(), target);
}
}
return target;
}
public V _get(boolean elaborate) {
getOverlay();
return target != null ? target._get(elaborate) : null;
}
public Reference _getReference() {
return reference;
}
public JsonOverlay> _getParent() {
return parent;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy