com.networknt.jsonoverlay.OverlayFactory 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 abstract class OverlayFactory {
private final Class extends IJsonOverlay super V>> overlayClass = getOverlayClass();
public JsonOverlay create(V value, JsonOverlay> parent, ReferenceManager refMgr) {
JsonOverlay overlay = _create(value, parent, refMgr);
overlay._elaborate(true);
return overlay;
}
@SuppressWarnings("unchecked")
public JsonOverlay create(JsonNode json, JsonOverlay> parent, ReferenceManager refMgr) {
JsonOverlay overlay;
if (Reference.isReferenceNode(json)) {
Reference reference = refMgr.getReference(json);
RefOverlay refOverlay = new RefOverlay(reference, null, this, refMgr);
overlay = refOverlay.getOverlay();
if (overlay == null) {
overlay = _create((V) null, parent, refMgr);
}
if (overlay != null) {
overlay = ((OverlayFactory) overlay._getFactory())._create((V) null, parent, refMgr);
overlay._setReference(refOverlay);
}
} else {
JsonOverlay> existing = refMgr.getRegistry().getOverlay(json, getSignature());
if (existing != null) {
overlay = (JsonOverlay) existing;
if (parent != null) {
overlay._setParent(parent);
}
} else {
overlay = _create(json, parent, refMgr);
overlay._setParent(parent);
refMgr.getRegistry().register(json, getSignature(), overlay);
if (!overlay._isElaborated()) {
overlay._elaborate(true);
}
}
}
return overlay;
}
public boolean isCompatible(JsonOverlay> overlay) {
return overlayClass.isAssignableFrom(overlay.getClass());
}
public String getSignature() {
return getOverlayClass().getSimpleName();
}
protected boolean isExtendedType() {
return false;
}
protected abstract Class extends JsonOverlay super V>> getOverlayClass();
protected abstract JsonOverlay _create(V value, JsonOverlay> parent, ReferenceManager refMgr);
protected abstract JsonOverlay _create(JsonNode json, JsonOverlay> parent, ReferenceManager refMgr);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy