diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-07-06 11:00:24 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-07-06 11:00:24 +0200 |
| commit | 24314dc1699c7e73048fa24e33729f1aa1ec0e86 (patch) | |
| tree | c97af82997783b860c36f4410973b23caff0d42e /src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java | |
| parent | cc79e98c4763affba4fa2e17dfe5a412f9de66c3 (diff) | |
Modules serialize with Castor. Just about to remove the parsing.
CastorXMLUtility is now a static member of gateway. Domain specific
instances can be used by domain applications, but the maps do not
interfere with the kernel.
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java index 540a6fc..07d2250 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java @@ -3,6 +3,10 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectCannotBeUpdated;
@@ -11,40 +15,54 @@ import com.c2kernel.entity.agent.ActiveEntity; import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.Module;
+import com.c2kernel.process.module.ModuleImport;
+import com.c2kernel.property.Property;
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 class NewAgent extends ModuleImport implements java.io.Serializable {
public String password;
- public ArrayList<String> roles;
+ public ArrayList<String> roles = new ArrayList<String>();
+ public ArrayList<Property> properties = new ArrayList<Property>();
public NewAgent() {
- super();
- roles = new ArrayList<String>();
+ super(null);
}
public NewAgent(String name, String password) {
+ super(null);
this.name = name;
this.password = password;
}
- protected void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException {
+ public NewAgent(Element imp) {
+ super(imp);
+ password = imp.getAttribute("password");
+ NodeList rolenl = imp.getElementsByTagName("Role");
+ for (int j=0; j<rolenl.getLength(); j++) {
+ roles.add(((Text)rolenl.item(j).getFirstChild()).getData());
+ }
+ NodeList pnl = imp.getElementsByTagName("Property");
+ for (int j=0; j<pnl.getLength(); j++) {
+ Element p = (Element)pnl.item(j);
+ properties.add(Module.newProperty(p));
+ }
+ }
+
+ public 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"));
+ properties.add(new com.c2kernel.property.Property("Name", name));
+ properties.add(new com.c2kernel.property.Property("Type", "Agent"));
try {
- newAgentEnt.initialise(CastorXMLUtility.marshall(propList));
+ newAgentEnt.initialise(Gateway.getMarshaller().marshall(new PropertyArrayList(properties)));
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent");
|
