From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- .../predefined/entitycreation/NewAgent.java | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java (limited to 'source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java') diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java new file mode 100755 index 0000000..fa575a3 --- /dev/null +++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java @@ -0,0 +1,65 @@ +package com.c2kernel.lifecycle.instance.predefined.entitycreation; + +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Iterator; + +import com.c2kernel.common.CannotManageException; +import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.entity.agent.ActiveEntity; +import com.c2kernel.lookup.AgentPath; +import com.c2kernel.lookup.RolePath; +import com.c2kernel.process.Gateway; +import com.c2kernel.property.PropertyArrayList; +import com.c2kernel.utils.CastorXMLUtility; +import com.c2kernel.utils.Logger; + +public class NewAgent implements java.io.Serializable { + + public String name; + + public String password; + + public ArrayList roles; + + public NewAgent() { + super(); + roles = new ArrayList(); + } + + public NewAgent(String name, String password) { + this.name = name; + this.password = password; + } + + protected void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException { + AgentPath newAgent = Gateway.getLDAPLookup().getNextKeyManager().generateNextAgentKey(); + newAgent.setAgentName(name); + newAgent.setPassword(password); + ActiveEntity newAgentEnt = (ActiveEntity)Gateway.getCorbaServer().createEntity(newAgent); + Gateway.getLDAPLookup().add(newAgent); + // assemble properties + PropertyArrayList propList = new PropertyArrayList(); + propList.list.add(new com.c2kernel.property.Property("Name", name)); + propList.list.add(new com.c2kernel.property.Property("Type", "Agent")); + try { + newAgentEnt.initialise(CastorXMLUtility.marshall(propList)); + } catch (Exception ex) { + Logger.error(ex); + throw new CannotManageException("Error initialising new agent"); + } + for (Iterator iter = roles.iterator(); iter.hasNext();) { + String role = (String) iter.next(); + RolePath thisRole; + try { + thisRole = Gateway.getLDAPLookup().getRoleManager().getRolePath(role); + } catch (ObjectNotFoundException ex) { + thisRole = Gateway.getLDAPLookup().getRoleManager().createRole(role, false); + } + thisRole.addAgent(newAgent); + } + + } +} -- cgit v1.2.3