/************************************************************************** * CreateItemFromDescription * * $Workfile$ * $Revision: 1.47 $ * $Date: 2005/10/13 08:13:58 $ * * Copyright (C) 2001 CERN - European Organization for Nuclear Research * All rights reserved. **************************************************************************/ package com.c2kernel.lifecycle.instance.predefined.agent; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.entity.CorbaServer; import com.c2kernel.entity.agent.ActiveEntity; import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; /************************************************************************** * * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $ * @version $Revision: 1.47 $ **************************************************************************/ public class CreateAgentFromDescription extends CreateItemFromDescription { public CreateAgentFromDescription() { super(); } //requestdata is xmlstring @Override protected String runActivityLogic(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws InvalidDataException { String[] input = getDataList(requestData); String newName = input[0]; String domPath = input[1]; String wfDefName = null; int wfDefVer = -1; if (input.length > 2) // override wf wfDefName = input[2]; Logger.msg(1, "CreateAgentFromDescription::request() - Starting."); try { // check if the path is already taken DomainPath context = new DomainPath(new DomainPath(domPath), newName); Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString()); if (context.getSysKey()!=-1) throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", ""); // generate new entity key Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey"); AgentPath newAgentPath = Gateway.getNextKeyManager().generateNextAgentKey(); // resolve the item factory Logger.msg(6, "CreateItemFromDescription - Resolving item factory"); // create the Item object Logger.msg(3, "CreateItemFromDescription - Creating Item"); CorbaServer factory = Gateway.getCorbaServer(); if (factory == null) throw new AccessRightsException("This process cannot create new Items", ""); ActiveEntity newAgent = (ActiveEntity)factory.createEntity(newAgentPath); Gateway.getLookupManager().add(newAgentPath); // initialise it with its properties and workflow Logger.msg(3, "CreateItemFromDescription - Initializing Item"); newAgent.initialise( agent.getSysKey(), Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)), Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)), Gateway.getMarshaller().marshall(getNewCollections(itemSysKey)) ); // add its domain path Logger.msg(3, "CreateItemFromDescription - Creating "+context); context.setEntity(newAgentPath); Gateway.getLookupManager().add(context); return requestData; } catch (Exception e) { Logger.error(e); throw new InvalidDataException(e.getMessage(), ""); } } }