summaryrefslogtreecommitdiff
path: root/src/main/java/org/cristalise/kernel/lookup
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/cristalise/kernel/lookup')
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/AgentPath.java159
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/DomainPath.java136
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/InvalidAgentPathException.java33
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/InvalidItemPathException.java33
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/InvalidPathException.java33
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/ItemPath.java120
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/Lookup.java175
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/LookupManager.java124
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/Path.java243
-rw-r--r--src/main/java/org/cristalise/kernel/lookup/RolePath.java116
10 files changed, 1172 insertions, 0 deletions
diff --git a/src/main/java/org/cristalise/kernel/lookup/AgentPath.java b/src/main/java/org/cristalise/kernel/lookup/AgentPath.java
new file mode 100644
index 0000000..cab9068
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/AgentPath.java
@@ -0,0 +1,159 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.UUID;
+
+import org.apache.xerces.impl.dv.util.Base64;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.SystemKey;
+import org.cristalise.kernel.process.Gateway;
+
+
+
+/**
+* Extends Path to enforce SystemKey structure and support int form
+*
+* @version $Revision: 1.12 $ $Date: 2005/10/13 08:15:00 $
+* @author $Author: abranson $
+**/
+public class AgentPath extends ItemPath
+{
+
+ private String mAgentName=null;
+ private String mPassword=null;
+
+ public AgentPath(SystemKey syskey) throws InvalidAgentPathException, InvalidItemPathException {
+ super(syskey);
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidAgentPathException();
+ }
+ }
+ protected AgentPath(UUID uuid) throws InvalidAgentPathException, InvalidItemPathException {
+ super(uuid);
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidAgentPathException();
+ }
+ }
+
+ public AgentPath(ItemPath itemPath) throws InvalidAgentPathException {
+ super(itemPath.mUUID);
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidAgentPathException();
+ }
+ }
+
+ public AgentPath(ItemPath itemPath, String agentName) {
+ super(itemPath.mUUID);
+ mAgentName = agentName;
+ }
+
+ public AgentPath(String path) throws InvalidItemPathException {
+ super(path);
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidAgentPathException();
+ }
+ }
+
+ public void setAgentName(String agentID)
+ {
+ mAgentName = agentID;
+ }
+
+ public String getAgentName()
+ {
+ if (mAgentName==null)
+ try {
+ findAgentName();
+ } catch (ObjectNotFoundException e) {
+ return null;
+ }
+ return mAgentName;
+ }
+
+ private void findAgentName() throws ObjectNotFoundException {
+ mAgentName = Gateway.getLookup().getAgentName(this);
+ }
+
+ public RolePath[] getRoles()
+ {
+ return Gateway.getLookup().getRoles(this);
+ }
+
+ public boolean hasRole(RolePath role) {
+ return Gateway.getLookup().hasRole(this, role);
+ }
+
+ public boolean hasRole(String role) {
+ try {
+ return hasRole(Gateway.getLookup().getRolePath(role));
+ } catch (ObjectNotFoundException ex) {
+ return false;
+ }
+ }
+
+ public void setPassword(String passwd)
+ {
+ mPassword = passwd;
+ }
+
+ public String getPassword()
+ {
+ return mPassword;
+ }
+
+ @Override
+ public String dump() {
+ return super.dump()+
+ "\n agentID="+
+ mAgentName;
+ }
+
+ public static String generateUserPassword(String pass, String algo) throws NoSuchAlgorithmException {
+ MessageDigest sha = MessageDigest.getInstance(algo);
+ sha.reset();
+ sha.update(pass.getBytes());
+ byte hash[] = sha.digest();
+ StringBuffer digest = new StringBuffer("{").append(algo).append("}");
+ digest.append(Base64.encode(hash));
+ return digest.toString();
+ }
+
+ public static AgentPath fromUUIDString(String uuid) throws InvalidAgentPathException {
+ try {
+ return new AgentPath(new ItemPath(uuid));
+ } catch (InvalidItemPathException ex) {
+ throw new InvalidAgentPathException(ex.getMessage());
+ }
+ }
+
+}
+
diff --git a/src/main/java/org/cristalise/kernel/lookup/DomainPath.java b/src/main/java/org/cristalise/kernel/lookup/DomainPath.java
new file mode 100644
index 0000000..a054da6
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/DomainPath.java
@@ -0,0 +1,136 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.process.Gateway;
+
+
+
+/**
+* @version $Revision: 1.22 $ $Date: 2005/10/13 08:15:00 $
+* @author $Author: abranson $
+**/
+public class DomainPath extends Path
+{
+ private ItemPath target = null;
+ protected static String mTypeRoot;
+
+/* Very simple extension to Path. Only copies constructors and defines root */
+
+ public DomainPath()
+ {
+ super(Path.UNKNOWN);
+ }
+
+ public DomainPath(short type)
+ {
+ super();
+ mType = type;
+ }
+
+ public DomainPath(String[] path)
+ {
+ super(path, Path.UNKNOWN);
+ }
+
+ public DomainPath(String path)
+ {
+ super(path, Path.UNKNOWN);
+ }
+
+ public DomainPath(String path, ItemPath entity)
+ {
+ super(path, Path.UNKNOWN);
+ setItemPath(entity);
+ }
+
+ public DomainPath(DomainPath parent, String child) {
+ super(parent, child);
+ }
+
+ /* the root of domain paths is /domain
+ * clearly
+ */
+ @Override
+ public String getRoot() {
+ return "domain";
+ }
+
+ public DomainPath getParent() {
+ if (mPath.length == 0)
+ return null;
+
+ String[] parentPath = new String[mPath.length-1];
+ System.arraycopy(mPath, 0, parentPath, 0, parentPath.length);
+ return new DomainPath(parentPath);
+ }
+
+ public void setItemPath(ItemPath newTarget) {
+ if (newTarget == null) { // clear
+ target = null;
+ mType = Path.CONTEXT;
+ return;
+ }
+
+ target = newTarget;
+ mType = Path.ENTITY;
+ }
+
+ @Override
+ public ItemPath getItemPath() throws ObjectNotFoundException {
+ if (mType == UNKNOWN) { // must decide
+ checkType();
+ }
+
+ if (target == null)
+ throw new ObjectNotFoundException("Path "+toString()+" does not resolve to an Item");
+ return target;
+ }
+
+ @Override
+ public short getType() {
+ if (mType == UNKNOWN) { // must decide
+ checkType();
+ }
+ return mType;
+ }
+
+ protected void checkType() {
+ try {
+ setItemPath(Gateway.getLookup().resolvePath(this));
+ } catch (InvalidItemPathException ex) {
+ mType = CONTEXT;
+ } catch (ObjectNotFoundException ex) {
+ mType = CONTEXT;
+ }
+
+ }
+
+ /**
+ * Retrieves the domkey of the path
+ * @return the last path component;
+ */
+ public String getName() {
+ return mPath[mPath.length-1];
+ }
+}
+
diff --git a/src/main/java/org/cristalise/kernel/lookup/InvalidAgentPathException.java b/src/main/java/org/cristalise/kernel/lookup/InvalidAgentPathException.java
new file mode 100644
index 0000000..60ac840
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/InvalidAgentPathException.java
@@ -0,0 +1,33 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+public class InvalidAgentPathException extends InvalidItemPathException {
+
+ public InvalidAgentPathException() {
+ super();
+ }
+
+ public InvalidAgentPathException(String msg) {
+ super(msg);
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/lookup/InvalidItemPathException.java b/src/main/java/org/cristalise/kernel/lookup/InvalidItemPathException.java
new file mode 100644
index 0000000..b6817af
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/InvalidItemPathException.java
@@ -0,0 +1,33 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+public class InvalidItemPathException extends InvalidPathException {
+
+ public InvalidItemPathException() {
+ super();
+ }
+
+ public InvalidItemPathException(String msg) {
+ super(msg);
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/lookup/InvalidPathException.java b/src/main/java/org/cristalise/kernel/lookup/InvalidPathException.java
new file mode 100644
index 0000000..9e75c11
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/InvalidPathException.java
@@ -0,0 +1,33 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+public class InvalidPathException extends Exception {
+
+ public InvalidPathException() {
+ super();
+ }
+
+ public InvalidPathException(String msg) {
+ super(msg);
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/lookup/ItemPath.java b/src/main/java/org/cristalise/kernel/lookup/ItemPath.java
new file mode 100644
index 0000000..9df4a0a
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/ItemPath.java
@@ -0,0 +1,120 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.UUID;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.SystemKey;
+
+
+
+/**
+* Extends Path to enforce SystemKey structure and support int form
+*
+* @version $Revision: 1.14 $ $Date: 2006/03/03 13:52:21 $
+* @author $Author: abranson $
+**/
+public class ItemPath extends Path
+{
+
+ public ItemPath() {
+ setSysKey(UUID.randomUUID());
+ }
+
+ protected ItemPath(UUID uuid) {
+ setSysKey(uuid);
+ }
+
+ public ItemPath(SystemKey syskey) {
+ setSysKey(syskey);
+ }
+
+ /*
+ */
+ public ItemPath(String[] path) throws InvalidItemPathException
+ {
+ super(path, Path.CONTEXT);
+ getSysKeyFromPath();
+ }
+
+ /*
+ */
+ public ItemPath(String path) throws InvalidItemPathException
+ {
+ super(path, Path.CONTEXT);
+ if (path == null) throw new InvalidItemPathException("Path cannot be null");
+ getSysKeyFromPath();
+ }
+
+ private void getSysKeyFromPath() throws InvalidItemPathException {
+ if (mPath.length == 1) {
+ try {
+ setSysKey(UUID.fromString(mPath[0]));
+ mType = Path.ENTITY;
+ } catch (IllegalArgumentException ex) {
+ throw new InvalidItemPathException(mPath[0]+" is not a valid UUID");
+ }
+ }
+ else
+ throw new InvalidItemPathException("Not a valid item path: "+Arrays.toString(mPath));
+ }
+
+ // EntityPaths root in /entity
+ @Override
+ public String getRoot() {
+ return "entity";
+ }
+
+ @Override
+ public ItemPath getItemPath() throws ObjectNotFoundException {
+ return this;
+ }
+
+ public byte[] getOID() {
+ if (mType == Path.CONTEXT) return null;
+ ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
+ bb.putLong(mSysKey.msb);
+ bb.putLong(mSysKey.lsb);
+ return bb.array();
+ }
+
+ protected void setSysKey(UUID uuid) {
+ mUUID = uuid;
+ mSysKey = new SystemKey(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
+ setPathFromUUID(mUUID.toString());
+ }
+
+ protected void setSysKey(SystemKey sysKey) {
+ mSysKey = sysKey;
+ mUUID = new UUID(sysKey.msb, sysKey.lsb);
+ setPathFromUUID(mUUID.toString());
+ }
+
+ private void setPathFromUUID(String uuid) {
+ mPath = new String[1];
+ mPath[0] = uuid;
+ mType = Path.ENTITY;
+ }
+}
+
diff --git a/src/main/java/org/cristalise/kernel/lookup/Lookup.java b/src/main/java/org/cristalise/kernel/lookup/Lookup.java
new file mode 100644
index 0000000..eb54775
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/Lookup.java
@@ -0,0 +1,175 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.util.Iterator;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.process.auth.Authenticator;
+import org.cristalise.kernel.property.Property;
+import org.cristalise.kernel.property.PropertyDescriptionList;
+
+
+/**
+ * @author abranson
+ *
+ */
+public interface Lookup {
+
+ /**
+ * Connect to the directory using the credentials supplied in the Authenticator.
+ *
+ * @param user The connected Authenticator. The Lookup implementation may use the AuthObject in this to communicate with the database.
+ */
+ public void open(Authenticator user);
+
+ /**
+ * Shutdown the lookup
+ */
+ public void close();
+
+ // Path resolution
+ /**
+ * Fetch the correct subclass class of ItemPath for a particular Item, derived from its lookup entry.
+ * This is used by the CORBA Server to make sure the correct Item subclass is used.
+ *
+ * @param sysKey The system key of the Item
+ * @return an ItemPath or AgentPath
+ * @throws InvalidItemPathException When the system key is invalid/out-of-range
+ * @throws ObjectNotFoundException When the Item does not exist in the directory.
+ */
+ public ItemPath getItemPath(String sysKey) throws InvalidItemPathException, ObjectNotFoundException;
+
+ /**
+ * Find the ItemPath for which a DomainPath is an alias.
+ *
+ * @param domainPath The path to resolve
+ * @return The ItemPath it points to (should be an AgentPath if the path references an Agent)
+ * @throws InvalidItemPathException
+ * @throws ObjectNotFoundException
+ */
+ public ItemPath resolvePath(DomainPath domainPath) throws InvalidItemPathException, ObjectNotFoundException;
+
+ /**
+ * Resolve a path to a CORBA Object Item or Agent
+ *
+ * @param path The path to be resolved
+ * @return The CORBA Object
+ * @throws ObjectNotFoundException When the Path doesn't exist, or doesn't have an IOR associated with it
+ */
+ public org.omg.CORBA.Object resolve(Path path) throws ObjectNotFoundException;
+
+ // Path finding and searching
+
+ /**
+ * Checks if a particular Path exists in the directory
+ * @param path The path to check
+ * @return boolean true if the path exists, false if it doesn't
+ */
+ public boolean exists(Path path);
+
+ /**
+ * List the next-level-deep children of a Path
+ *
+ * @param path The parent Path
+ * @return An Iterator of child Paths
+ */
+ public Iterator<Path> getChildren(Path path);
+
+ /**
+ * Find a path with a particular name (last component)
+ *
+ * @param start Search root
+ * @param name The name to search for
+ * @return An Iterator of matching Paths. Should be an empty Iterator if there are no matches.
+ */
+ public Iterator<Path> search(Path start, String name);
+
+ /**
+ * Search for Items in the specified path with the given property name and value
+ * @param start Search root
+ * @param propname Property name
+ * @param propvalue The property value to search for
+ * @return An Iterator of matching Paths
+ */
+ public Iterator<Path> search(Path start, Property... props);
+
+ /**
+ * Search for Items of a particular type, based on its PropertyDescription outcome
+ * @param start Search root
+ * @param props Properties unmarshalled from an ItemDescription's property description outcome.
+ * @return An Iterator of matching Paths
+ */
+ public Iterator<Path> search(Path start, PropertyDescriptionList props);
+
+ /**
+ * Find all DomainPaths that are aliases for a particular Item or Agent
+ * @param itemPath The ItemPath
+ * @return An Iterator of DomainPaths that are aliases for that Item
+ */
+ public Iterator<Path> searchAliases(ItemPath itemPath);
+
+ // Role and agent management
+
+ /**
+ * @param agentName
+ * @return
+ * @throws ObjectNotFoundException
+ */
+ public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException;
+
+ /**
+ * @param roleName
+ * @return
+ * @throws ObjectNotFoundException
+ */
+ public RolePath getRolePath(String roleName) throws ObjectNotFoundException;
+
+ /**
+ * @param rolePath
+ * @return
+ * @throws ObjectNotFoundException
+ */
+ public AgentPath[] getAgents(RolePath rolePath) throws ObjectNotFoundException;
+
+ /**
+ * @param agentPath
+ * @return
+ */
+ public RolePath[] getRoles(AgentPath agentPath);
+
+ /**
+ * Returns all of the Agents in this centre who hold this role (including sub-roles)
+ *
+ * @param agentPath
+ * @param role
+ * @return
+ */
+ public boolean hasRole(AgentPath agentPath, RolePath role);
+
+ /**
+ * @param agentPath
+ * @return
+ * @throws ObjectNotFoundException
+ */
+ public String getAgentName(AgentPath agentPath) throws ObjectNotFoundException;
+
+}
diff --git a/src/main/java/org/cristalise/kernel/lookup/LookupManager.java b/src/main/java/org/cristalise/kernel/lookup/LookupManager.java
new file mode 100644
index 0000000..0ce04c3
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/LookupManager.java
@@ -0,0 +1,124 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.security.NoSuchAlgorithmException;
+
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectCannotBeUpdated;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+
+
+/**
+ * The LookupManager interface contains all of the directory modifying methods
+ * of the Lookup. This allows read-only Lookup implementations. Server processes
+ * will attempt to cast their Lookups into LookupManagers, and fail to start up
+ * if this is not possible.
+ *
+ */
+public interface LookupManager extends Lookup {
+
+ /**
+ * Called when a server starts up. The Lookup implementation should ensure
+ * that the initial structure of its directory is valid, and create it on
+ * first boot.
+ *
+ * @throws ObjectNotFoundException When initialization data is not found
+ */
+ public void initializeDirectory() throws ObjectNotFoundException;
+
+ // Path management
+
+ /**
+ * Register a new a Path in the directory.
+ *
+ * @param newPath The path to add
+ * @throws ObjectCannotBeUpdated When there is an error writing to the
+ * directory
+ * @throws ObjectAlreadyExistsException When the Path has already been registered
+ */
+ public void add(Path newPath) throws ObjectCannotBeUpdated, ObjectAlreadyExistsException;
+
+ /**
+ * Remove a Path from the directory.
+ *
+ * @param path The path to remove
+ * @throws ObjectCannotBeUpdated When an error occurs writing to the directory
+ */
+ public void delete(Path path) throws ObjectCannotBeUpdated;
+
+ // Role and agent management
+
+ /**
+ * Creates a new Role. Called by the server predefined step 'CreateNewRole'
+ *
+ * @param role The new role path
+ * @return
+ * @throws ObjectAlreadyExistsException
+ * @throws ObjectCannotBeUpdated
+ */
+ public RolePath createRole(RolePath role) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated;
+
+ /**
+ * Adds the given Agent to the given Role, if they both exist.
+ *
+ * @param agent
+ * @param rolePath
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ */
+ public void addRole(AgentPath agent, RolePath rolePath) throws ObjectCannotBeUpdated, ObjectNotFoundException;
+
+ /**
+ * Remove the given Agent from the given Role. Does not delete the Role.
+ *
+ * @param agent
+ * @param role
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ */
+ public void removeRole(AgentPath agent, RolePath role) throws ObjectCannotBeUpdated, ObjectNotFoundException;
+
+ /**
+ * Set an Agent's password
+ *
+ * @param agent The Agent
+ * @param newPassword The Agent's new password
+ * @throws ObjectNotFoundException
+ * @throws ObjectCannotBeUpdated
+ * @throws NoSuchAlgorithmException
+ */
+ public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException;
+
+ /**
+ * Set the flag specifying whether Activities holding this Role should push
+ * Jobs its Agents.
+ *
+ * @param role The role to modify
+ * @param hasJobList boolean flag
+ *
+ * @throws ObjectNotFoundException When the Role doesn't exist
+ * @throws ObjectCannotBeUpdated
+ */
+ public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated;
+
+
+}
diff --git a/src/main/java/org/cristalise/kernel/lookup/Path.java b/src/main/java/org/cristalise/kernel/lookup/Path.java
new file mode 100644
index 0000000..77bca9b
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/Path.java
@@ -0,0 +1,243 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+import java.util.UUID;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.SystemKey;
+import org.cristalise.kernel.process.Gateway;
+
+
+
+/**
+*
+**/
+public abstract class Path
+{
+ public static final String delim = "/";
+
+ // types
+ public static final short UNKNOWN = 0;
+ public static final short CONTEXT = 1;
+ public static final short ENTITY = 2;
+
+ protected String[] mPath = new String[0];
+
+ // slash delimited path
+ protected String mStringPath = null;
+ // entity or context
+ protected short mType = CONTEXT;
+
+ // item UUID (only valid for ItemPaths and DomainPaths that are aliases for Items)
+ protected UUID mUUID;
+ protected SystemKey mSysKey;
+
+ // ior is stored in here when it is resolved
+ protected org.omg.CORBA.Object mIOR = null;
+
+ public Path() {
+ }
+
+ /*
+ * Creates an empty path
+ */
+ public Path(short type)
+ {
+ mType = type;
+ }
+
+ /*
+ * Creates a path with an arraylist of the path (big endian)
+ */
+ public Path(String[] path, short type) {
+ setPath(path);
+ mType = type;
+ }
+
+ /*
+ * Creates a path from a slash separated string (big endian)
+ */
+ public Path(String path, short type) {
+ setPath(path);
+ mType = type;
+ }
+
+ /*
+ * Create a path by appending a child string to an existing path
+ */
+ public Path(Path parent, String child, short type) {
+ String[] oldPath = parent.getPath();
+ mPath = new String[oldPath.length+1];
+ for (int i=0; i<oldPath.length; i++)
+ mPath[i] = oldPath[i];
+ mPath[oldPath.length] = child;
+ mType = type;
+ }
+
+ /*
+ * Create a path by appending a child and inheriting the type
+ */
+ public Path(Path parent, String child) {
+ this(parent, child, UNKNOWN);
+ }
+ /*************************************************************************/
+
+ // Setters
+
+ /* string array path e.g. { "Product", "Crystal", "Barrel", "2L", "331013013348" }
+ * system/domain node ABSENT
+ */
+ public void setPath(String[] path)
+ {
+ mStringPath = null;
+ mPath = path.clone();
+ mUUID = null;
+ mSysKey = null;
+ }
+
+ /* string path e.g. /system/d000/d000/d001
+ * system/domain node PRESENT
+ */
+ public void setPath(String path)
+ {
+ ArrayList<String> newPath = new ArrayList<String>();
+ if (path != null) {
+ StringTokenizer tok = new StringTokenizer(path, delim);
+ if (tok.hasMoreTokens()) {
+ String first = tok.nextToken();
+ if (!first.equals(getRoot()))
+ newPath.add(first);
+ while (tok.hasMoreTokens())
+ newPath.add(tok.nextToken());
+ }
+ }
+
+ mPath = (newPath.toArray(mPath));
+ mStringPath = null;
+ mUUID = null;
+ mSysKey = null;
+ }
+
+ // lookup sets the IOR
+ public void setIOR(org.omg.CORBA.Object IOR) {
+ mIOR = IOR;
+ if (IOR == null) mType = Path.CONTEXT;
+ else mType = Path.ENTITY;
+ }
+
+ /* clone another path object
+ */
+ public void setPath(Path path)
+ {
+ mStringPath = null;
+ mPath = (path.getPath().clone());
+ mUUID = null;
+ mSysKey = null;
+ }
+
+ /*************************************************************************/
+
+
+ /*
+ * Getter Methods
+ */
+
+ // root is defined as 'domain', 'entity' or 'system' in subclasses
+ public abstract String getRoot();
+
+ public String[] getPath()
+ {
+ return mPath;
+ }
+
+ public String getString()
+ {
+ if (mStringPath == null) {
+ StringBuffer stringPathBuffer = new StringBuffer("/").append(getRoot());
+ for (String element : mPath)
+ stringPathBuffer.append(delim).append(element);
+ mStringPath = stringPathBuffer.toString();
+ }
+ return mStringPath;
+ }
+
+ public boolean exists() {
+ return Gateway.getLookup().exists(this);
+ }
+
+ /** Queries the lookup for the IOR
+ */
+
+ public org.omg.CORBA.Object getIOR() {
+ org.omg.CORBA.Object newIOR = null;
+ if (mIOR==null) { // if not cached try to resolve
+ Lookup myLookup = Gateway.getLookup();
+ try {
+ newIOR = myLookup.resolve(this);
+ } catch (ObjectNotFoundException ex) {
+ }
+ setIOR(newIOR);
+ }
+ return mIOR;
+ }
+
+ @Override
+ public String toString() {
+ return getString();
+ }
+
+ public short getType() {
+ return mType;
+ }
+
+ public SystemKey getSystemKey() {
+ return mSysKey;
+ }
+
+ public UUID getUUID() {
+ return mUUID;
+ }
+
+ public abstract ItemPath getItemPath() throws ObjectNotFoundException;
+
+ @Override
+ public boolean equals( Object path )
+ {
+ if (path == null) return false;
+ return toString().equals(path.toString());
+ }
+
+ @Override
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ public String dump() {
+ StringBuffer comp = new StringBuffer("Components: { ");
+ for (String element : mPath)
+ comp.append("'").append(element).append("' ");
+ return "Path - dump(): "+comp.toString()+"}\n string="+toString()+"\n uuid="+getUUID()+"\n type="+mType;
+ }
+}
+
diff --git a/src/main/java/org/cristalise/kernel/lookup/RolePath.java b/src/main/java/org/cristalise/kernel/lookup/RolePath.java
new file mode 100644
index 0000000..61f444c
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/lookup/RolePath.java
@@ -0,0 +1,116 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * 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 3 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; with out 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; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.lookup;
+
+import java.util.Iterator;
+
+import org.cristalise.kernel.common.CannotManageException;
+import org.cristalise.kernel.common.ObjectCannotBeUpdated;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.process.Gateway;
+
+
+
+
+/**
+* @version $Revision: 1.7 $ $Date: 2005/04/26 06:48:12 $
+* @author $Author: abranson $
+**/
+public class RolePath extends DomainPath
+{
+ /**
+ *
+ */
+
+ private boolean hasJobList = false;
+
+ public RolePath() {
+ super("agent");
+ }
+
+ @Override
+ public RolePath getParent() {
+ try {
+ if (mPath.length > 2)
+ return Gateway.getLookup().getRolePath(mPath[mPath.length-2]);
+ } catch (ObjectNotFoundException ex) { }
+ return null;
+ }
+
+ public RolePath(RolePath parent, String roleName) {
+ super(parent, roleName);
+ }
+
+ public RolePath(String[] path, boolean jobList) {
+ super(path);
+ hasJobList = jobList;
+ }
+
+ public RolePath(RolePath parent, String roleName, boolean jobList) {
+ this(parent, roleName);
+ hasJobList = jobList;
+ }
+
+ /**
+ * @return Returns the hasJobList.
+ */
+ public boolean hasJobList() {
+ return hasJobList;
+ }
+ /**
+ * @param hasJobList The hasJobList to set.
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ * @throws CannotManageException
+ */
+ public void setHasJobList(boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
+ this.hasJobList = hasJobList;
+ }
+
+
+ @Override
+ protected void checkType() {
+ mType = CONTEXT;
+ }
+
+ public Iterator<Path> getChildren() {
+ return Gateway.getLookup().getChildren(this);
+ }
+
+ @Override
+ public String dump() {
+ StringBuffer comp = new StringBuffer("Components: { ");
+ for (String element : mPath)
+ comp.append("'").append(element).append("' ");
+
+ return "Path - dump(): "+
+ comp.toString()+
+ "}\n string="+
+ toString()+
+ "\n type="+
+ mType+
+ "\n name="+
+ getName()+
+ "\n ";
+ }
+
+}
+