* @return DynDataObject The generated object.
*/
private DynDataObject createDataObjectAndRegister(KeelResponse keelForm, String model, String keelObjectId,
boolean createNewObject)
{
DynDataObject dataObject = null;
boolean isObjectNotRegistered = false;
if (Engine.instance().getIObjectFactory().contains(model))
{
try
{
dataObject = (DynDataObject) Engine.instance().getIObjectFactory().newInstance(model);
}
catch (Exception x)
{
Log.log("system", "ConnectorServerManager.createDataObjectAndRegister",
"DynDataObject can not created: " + model + " Error: " + x, Log.FATAL);
}
}
else
{
dataObject = new DynDataObject(model);
isObjectNotRegistered = true;
}
if (createNewObject)
{
dataObject.setUniqueId(Engine.instance().getPersistentIDGenerator().createId());
}
else
{
dataObject.setUniqueId(new Long(keelObjectId));
}
ResponseElement groups = keelForm.get("groups");
for (Iterator i = groups.getAll().iterator(); i.hasNext();)
{
ResponseElement group = (ResponseElement) i.next();
for (Iterator j = group.getAll().iterator(); j.hasNext();)
{
Input attribute = (Input) j.next();
String attributeName = attribute.getName();
String attributeContent = (String) attribute.getDefaultValue().toString();
dataObject.setAttribute(attributeName, attributeContent);
if ("combo".equals(attribute.getAttribute("editor")))
{
StringBuffer validValues = new StringBuffer();
for (Iterator k = attribute.getValidValues().entrySet().iterator(); k.hasNext();)
{
Map.Entry value = (Map.Entry) k.next();
validValues.append(value.getKey() + "|" + value.getValue());
if (k.hasNext())
{
validValues.append("|");
}
}
dataObject.setAttribute(attributeName + "ValidValues", validValues.toString());
}
}
}
if (createNewObject)
{
dataObject.setAttribute("keelObjectId", "-1");
}
else
{
dataObject.setAttribute("keelObjectId", keelObjectId);
}
if (isObjectNotRegistered)
{
Engine.instance().getIObjectFactory().register((IObject) dataObject);
}
IObjectProxy proxy = (IObjectProxy) new FrameworkProxy();
proxy.setSampleRealObject((IObject) dataObject);
Engine.instance().getBaseRegistry().add((BaseObject) dataObject);
Engine.instance().getProxyRegistry().addProxy(proxy, dataObject.getTypeId());
return dataObject;
}