From 8e8185210f5bd87cb5dcda3a458fe059f811aafc Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 15 May 2014 15:10:13 +0200 Subject: Introduced 'Layer' attribute to allow overriding of descriptions. Desc with the same name in the same description tree will be ranked by LocalObjectLoader according to this number, and the highest one chosen for instantiation. Fixes #188 --- .../java/com/c2kernel/utils/LocalObjectLoader.java | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/c2kernel/utils') diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index 05f8aba..307cd97 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -1,11 +1,14 @@ package com.c2kernel.utils; +import java.util.Enumeration; + import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.lifecycle.ActivityDef; import com.c2kernel.lifecycle.instance.stateMachine.StateMachine; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.Path; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Schema; @@ -20,8 +23,29 @@ public class LocalObjectLoader { throws ObjectNotFoundException { DomainPath defRoot = new DomainPath(root); - DomainPath defPath = (DomainPath)defRoot.find(name); - return Gateway.getProxyManager().getProxy(defPath); + Enumeration e = Gateway.getLDAPLookup().search(defRoot, name); + ItemProxy defProxy = null; int currentLayer = -1; + while (e.hasMoreElements()) { + DomainPath defPath = (DomainPath)e.nextElement(); + ItemProxy thisProxy = Gateway.getProxyManager().getProxy(defPath); + int thisLayer; + try { + String thisLayerProp = thisProxy.getProperty("Layer"); + thisLayer = Integer.parseInt(thisLayerProp); + } catch (Exception ex) { + thisLayer = 0; + } + if (thisLayer > currentLayer) { + currentLayer = thisLayer; + defProxy = thisProxy; + } + else if (thisLayer == currentLayer) { + throw new ObjectNotFoundException("Duplicate definition for "+name+" in "+root+" found in Layer "+thisLayer, ""); + } + } + if (defProxy == null) + throw new ObjectNotFoundException("No match for "+name+" in "+root, ""); + return defProxy; } static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException { -- cgit v1.2.3