// @@
// @@
/*
* Wi.Ser Framework
*
* Version: 1.8.1, 20-September-2007
* Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library located in LGPL.txt in the
* license directory; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* If this agreement does not cover your requirements, please contact us
* via email to get detailed information about the commercial license
* or our service offerings!
*
*/
// @@
package de.ug2t.model.values;
import java.util.*;
import de.ug2t.kernel.*;
import de.ug2t.model.*;
import de.ug2t.model.persistence.*;
import de.ug2t.unifiedGui.*;
import de.ug2t.unifiedGui.transformer.*;
import de.ug2t.unifiedGui.validator.*;
/**
*
* @author dvonderweiden
*
* Comment: Limitierte Funktion, braucht allerdings wesentich weniger Speicher
*/
public class MoLimitedValueTree extends KeTreeNode implements IMoValueContainer
{
protected UnComponent pdm_uiMap = null;
protected String pdm_myTemplate = null;
protected IMoValue pdm_myTemplateObj = null;
private TreeMap pem_desc = null;
public MoChildDescriptor pcmf_getDesc(String xName)
{
if (pem_desc == null || xName == null)
return (null);
return ((MoChildDescriptor) this.pem_desc.get(xName));
}
public MoChildDescriptor pcmf_addDesc(String xName, MoChildDescriptor xDesc)
{
if (this.pem_desc == null)
this.pem_desc = new TreeMap();
return ((MoChildDescriptor) this.pem_desc.put(xName, xDesc));
}
/**
* @param xName
* @param xParent
* @throws Exception
*/
public MoLimitedValueTree(String xName, KeTreeNode xParent, IUnValidator xVal, IUnTransformer xTr, Vector xObs, UnComponent xUiMap, IMoMappingErrorHandler xUiErr)
throws Exception
{
super(xName, xParent);
this.pcmf_setEarlyAutoDelete(true);
this.pdm_uiMap = xUiMap;
if (xParent == null)
{
this.pdm_myTemplate = null;
this.pdm_myTemplateObj = this;
}
else
{
this.pdm_myTemplate = xParent.pcmf_getName();
this.pdm_myTemplateObj = (IMoValueContainer) xParent;
}
return;
}
/**
* @param xName
* @param xParent
* @throws Exception
*/
public MoLimitedValueTree(String xName, KeTreeNode xParent) throws Exception
{
super(xName, xParent);
this.pcmf_setEarlyAutoDelete(true);
if (xParent == null)
{
this.pdm_myTemplate = null;
this.pdm_myTemplateObj = this;
}
else
{
this.pdm_myTemplate = xParent.pcmf_getName();
this.pdm_myTemplateObj = (IMoValueContainer) xParent;
}
return;
}
/**
*
* @param xName
* @param xParent
* @throws Exception
*/
public MoLimitedValueTree() throws Exception
{
super("", null);
this.pcmf_setEarlyAutoDelete(true);
this.pdm_myTemplate = null;
this.pdm_myTemplateObj = this;
return;
}
/**
* <p>
* ...
* </p>
* <p>
*
* </p>
*/
protected void pdmf_callObservers()
{
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IUnValidator pcmf_setValidator(IUnValidator xValidator)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public UnComponent pcmf_setUiMap(UnComponent xMap)
{
UnComponent l_ui = this.pdm_uiMap;
this.pdm_uiMap = xMap;
return (l_ui);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoObserver pcmf_addObserver(IMoObserver xObserv)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoObserver pcmf_removeObserver(IMoObserver xObs)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoMappingErrorHandler pcmf_setUiErrorGW(IMoMappingErrorHandler xGw)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoValue pcmf_addValue(String xName, IMoValue xValue)
{
KeTreeNode l_node = null;
try
{
if (xValue instanceof KeTreeNode)
l_node = (KeTreeNode) xValue;
else
{
if (xValue instanceof IMoSingleValue)
((IMoSingleValue) xValue).pcmf_setParent(this);
l_node = new KeTreeNode(xName, null);
l_node.pcmf_setEarlyAutoDelete(true);
l_node.pcmf_setValue(xValue);
}
}
catch (Exception e)
{
KeLog.pcmf_logException("ug2t", this, e);
};
l_node = this.pcmf_addNode(xName, l_node);
this.pdmf_callObservers();
if (l_node == null)
return (null);
else
return (l_node instanceof KeTreeNode ? (IMoValue) l_node : (IMoValue) l_node.pcmf_getValue());
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoValue pcmf_getModelValue(String xName)
{
KeTreeNode l_node = null;
l_node = (KeTreeNode) this.pcmf_getSubNode(xName);
if (l_node == null)
return (null);
if (l_node instanceof IMoValue)
return ((IMoValue) l_node);
else
return ((IMoValue) l_node.pcmf_getValue());
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoValue pcmf_removeValue(String xName)
{
KeTreeNode l_node = null;
l_node = (KeTreeNode) this.pcmf_removeNode(xName);
IMoValue l_ret = null;
if (l_node instanceof IMoValue)
l_ret = (IMoValue) l_node;
else
l_ret = (IMoValue) l_node.pcmf_getValue();
if (l_ret instanceof IMoSingleValue)
((IMoSingleValue) l_ret).pcmf_setParent(null);
this.pdmf_callObservers();
return (l_ret);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoValue pcmf_cloneModelValue(boolean xChilds, boolean xFull)
{
IMoValueContainer l_new = null;
String l_name = null;
try
{
l_new = new MoValueTree(this.pcmf_getName(), null, null, null, null, this.pdm_uiMap, null);
l_new.pcmf_setMyTemplate(this.pcmf_getMyTemplate());
l_new.pcmf_setMyTemplateObj(this.pcmf_getMyTemplateObj());
((MoValueTree) l_new).pcmf_setView(IKeViewable.ViewTools.pcmf_cloneViewToLocal(this, this.pcmf_getView()));
if (xChilds == true && xFull == false)
{
Iterator l_itk = this.pcmf_getSubNameIterator();
Iterator l_itv = this.pcmf_getSubIterator();
IMoValue l_val = null;
Object l_sub = null;
while (l_itk.hasNext())
{
l_name = (String) l_itk.next();
l_sub = l_itv.next();
MoChildDescriptor l_desc = this.pcmf_getDesc(l_name);
if (l_desc != null)
{
if (l_desc.pcmf_isManatory())
{
if (l_sub instanceof MoValueTree)
l_val = (IMoValue) l_sub;
else
l_val = (IMoValue) ((KeTreeNode) l_sub).pcmf_getValue();
l_new.pcmf_addValue(l_name, l_val.pcmf_cloneModelValue(xChilds, xFull));
}
}
}
}
else if (xChilds == true && xFull == true)
{
Iterator l_itk = this.pcmf_getSubNameIterator();
Iterator l_itv = this.pcmf_getSubIterator();
IMoValue l_val = null;
Object l_sub = null;
while (l_itk.hasNext())
{
l_name = (String) l_itk.next();
l_sub = l_itv.next();
if (l_sub instanceof MoValueTree)
l_val = (IMoValue) l_sub;
else
l_val = (IMoValue) ((KeTreeNode) l_sub).pcmf_getValue();
l_new.pcmf_addValue(l_name, l_val.pcmf_cloneModelValue(xChilds, xFull));
}
}
}
catch (Exception e)
{
KeLog.pcmf_logException("ug2t", this, e);
};
return (l_new);
}
public IMoValue pcmf_cloneModelValue(boolean xChilds)
{
return (pcmf_cloneModelValue(xChilds, true));
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
* @return a boolean with ...
* </p>
*/
public boolean pcmf_model2UI()
{
boolean l_ret = true;
Iterator l_it = this.pcmf_getSubValueIt();
MoChildDescriptor l_desc = null;
String l_name = null;
boolean l_doMap = true;
IMoValueContainer l_tpl = (IMoValueContainer) this.pcmf_getMyTemplateObj();
if (l_tpl == null)
l_tpl = this;
while (l_it.hasNext())
{
IMoValue l_val = (IMoValue)l_it.next();
l_name = l_val.pcmf_getMyTemplate();
l_desc = l_tpl.pcmf_getDesc(l_name);
if (l_desc != null)
l_doMap = l_desc.isPem_mapWithParent2Ui();
if (l_doMap)
l_ret = l_val.pcmf_model2UI();
else
l_doMap = true;
}
return (l_ret);
} // end pcmf_model2UI
/**
* <p>
* Does ...
* </p>
* <p>
*
*
* @return a boolean with ...
* </p>
*/
public boolean pcmf_UI2Model()
{
boolean l_ret = true;
Iterator l_it = this.pcmf_getSubValueIt();
MoChildDescriptor l_desc = null;
String l_name = null;
boolean l_doMap = true;
IMoValueContainer l_tpl = (IMoValueContainer) this.pcmf_getMyTemplateObj();
if (l_tpl == null)
l_tpl = this;
while (l_it.hasNext())
{
IMoValue l_val = (IMoValue)l_it.next();
l_name = l_val.pcmf_getMyTemplate();
l_desc = l_tpl.pcmf_getDesc(l_name);
if (l_desc != null)
l_doMap = l_desc.isPem_mapWithParent2Ui();
if (l_doMap)
l_ret = l_val.pcmf_UI2Model() ? l_ret : false;
else
l_doMap = true;
}
return (l_ret);
} // end pcmf_UI2Model
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public boolean pcmf_validate()
{
boolean l_ret = true;
Iterator l_it = this.pcmf_getSubValueIt();
while (l_it.hasNext())
{
IMoValue l_val = (IMoValue)l_it.next();
if (l_val.pcmf_validate() == false)
l_ret = false;
};
return (l_ret);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public boolean pcmf_read(IMoValue xTpl)
{
KeLog.pcmf_logNotSupportedFatal();
return (true);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public boolean pcmf_write()
{
KeLog.pcmf_logNotSupportedFatal();
return (true);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoReader pcmf_setReader(IMoReader xReader)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoWriter pcmf_setWriter(IMoWriter xWriter)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public Iterator pcmf_getSubValueNameIt()
{
return (this.pcmf_getSubNameIterator());
}
/**
* <p>
* Does ...
* </p>
* <p>
*
* @param ...
* </p>
* <p>
* @return ...
* </p>
*/
public Iterator pcmf_getSubValueIt()
{
if (this.pdm_allSubs == null)
return (new ArrayList().iterator());
Iterator l_it = this.pdm_allSubs.iterator();
ArrayList l_vect = new ArrayList(this.pdm_allSubs.size());
Object l_value = null;
while (l_it.hasNext())
{
l_value = l_it.next();
if (l_value instanceof MoValueTree)
l_vect.add(l_value);
else
l_vect.add(((KeTreeNode) l_value).pcmf_getValue());
}
return (l_vect.iterator());
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
*
* @return a IUnTransformer with ...
* </p>
* <p>
* @param xTr
* ...
* </p>
*/
public IUnTransformer pcmf_getTransformer()
{
return (null);
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
*
* @return a IUnTransformer with ...
* </p>
* <p>
* @param xTr
* ...
* </p>
*/
public IUnTransformer pcmf_setTransformer(IUnTransformer xTrans)
{
KeLog.pcmf_logNotSupportedFatal();
return (null);
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
*
* @return a Type with ...
* </p>
* <p>
* @param ...
* </p>
*/
public IMoMappingErrorHandler pcmf_getUiErrorGW()
{
return (null);
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
*
* @return a UnComponent with ...
* </p>
* <p>
* @param xMap
* ...
* </p>
*/
public UnComponent pcmf_getUiMap()
{
return (this.pdm_uiMap);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoReader pcmf_getReader()
{
return (null);
}
/**
* <p>
* Does ...
* </p>
* <p>
*
*
*
* @return a UnComponent with ...
* </p>
* <p>
* @param xMap
* ...
* </p>
*/
public Vector pcmf_getObservers()
{
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public IMoWriter pcmf_getWriter()
{
return (null);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public String pcmf_getMyTemplate()
{
return (this.pdm_myTemplate);
}
/**
* <p>
* Does...
* </p>
* <p>
*
* @return a Type with
* </p>
* <p>
* @param
* </p>
*/
public String pcmf_setMyTemplate(String xTpl)
{
String l_old = this.pdm_myTemplate;
this.pdm_myTemplate = xTpl;
return (l_old);
};
/**
* <p>
* Does ...
* </p>
* <p>
*
* @param ...
* </p>
* <p>
* @return ...
* </p>
*/
public IMoValue pcmf_getNewModelValue(String xName, boolean xChilds)
{
IMoValue l_mod = null;
try
{
IMoValue l_val = this.pcmf_getModelValue(xName);
if (l_val == null)
{
KeLog.pcmf_log("ug2t", "this model-value-type is not allowed: " + xName, this, KeLog.ERROR);
return (null);
}
l_mod = l_val.pcmf_cloneModelValue(xChilds, false);
l_mod.pcmf_setMyTemplate(xName);
l_mod.pcmf_setMyTemplateObj(l_val);
}
catch (Exception e)
{
KeLog.pcmf_logException("ug2t", this, e);
};
return (l_mod);
}
public IMoValue pcmf_getMyTemplateObj()
{
return (this.pdm_myTemplateObj);
}
public IMoValue pcmf_setMyTemplateObj(IMoValue xTpl)
{
IMoValue l_old = this.pdm_myTemplateObj;
this.pdm_myTemplateObj = xTpl;
return (l_old);
}
public IMoValueContainer pcmf_getValueContainer(String xName)
{
return ((IMoValueContainer) this.pcmf_getModelValue(xName));
}
public IMoSingleValue pcmf_getSingleValue(String xName)
{
return ((IMoSingleValue) this.pcmf_getModelValue(xName));
}
public IMoValueContainer pcmf_getParent()
{
return ((IMoValueContainer)this.pcmf_getParentNode());
}
}
|