From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- source/com/c2kernel/lookup/Path.java | 301 +++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100755 source/com/c2kernel/lookup/Path.java (limited to 'source/com/c2kernel/lookup/Path.java') diff --git a/source/com/c2kernel/lookup/Path.java b/source/com/c2kernel/lookup/Path.java new file mode 100755 index 0000000..b189910 --- /dev/null +++ b/source/com/c2kernel/lookup/Path.java @@ -0,0 +1,301 @@ +/************************************************************************** + * Path.java + * + * $Revision: 1.27 $ + * $Date: 2006/01/17 07:49:58 $ + * + * Copyright (C) 2001 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +package com.c2kernel.lookup; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.StringTokenizer; + +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.process.Gateway; +import com.novell.ldap.LDAPAttributeSet; +import com.novell.ldap.LDAPConnection; +import com.novell.ldap.LDAPSearchConstraints; + + +/** +* @version $Revision: 1.27 $ $Date: 2006/01/17 07:49:58 $ +* @author $Author: abranson $ +**/ +public abstract class Path implements Serializable +{ + public static final String delim = "/"; + + // types + public static final short UNKNOWN = 0; + public static final short CONTEXT = 1; + public static final short ENTITY = 2; + + // invalid int key + public static final int INVALID = -1; + + protected String[] mPath = new String[0]; + + // slash delimited path + protected String mStringPath = null; + // entity or context + protected short mType = CONTEXT; + // LDAP dn + protected String mDN = null; + // int syskey (only valid for entity SystemPaths) + protected int mSysKey = INVALID; + + // ior is stored in here when it is resolved + protected org.omg.CORBA.Object mIOR = null; + // + // needed for unusual subclass constructors + + protected static String mGlobalPath; //cern.ch + protected static String mRootPath; //cristal2 + protected static String mLocalPath; //lab27 + + 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=0; i--) + dnBuffer.append("cn=").append(mPath[i]).append(","); + dnBuffer.append("cn="+getRoot()+","); + mDN = dnBuffer.toString(); + } + return mDN; + } + + public String getFullDN() { + return getDN()+mLocalPath; + } + + public boolean exists() { + return Gateway.getLDAPLookup().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 + LDAPLookup myLookup = Gateway.getLDAPLookup(); + try { + newIOR = myLookup.getIOR(this); + } catch (ObjectNotFoundException ex) { + newIOR = null; + } + setIOR(newIOR); + } + return mIOR; + } + + public String toString() { + return getString(); + } + + public short getType() { + return mType; + } + + public int getSysKey() { + return mSysKey; + } + + public Enumeration getChildren() { + String filter = "objectclass=*"; + LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); + searchCons.setBatchSize(10); + searchCons.setDereference(LDAPSearchConstraints.DEREF_FINDING ); + return Gateway.getLDAPLookup().search(getFullDN(), LDAPConnection.SCOPE_ONE,filter,searchCons); + } + + public Path find(String name) throws ObjectNotFoundException { + Enumeration e = Gateway.getLDAPLookup().search(this, name); + if (e.hasMoreElements()) { + Path thisPath =(Path)e.nextElement(); + if (e.hasMoreElements()) + throw new ObjectNotFoundException("More than one match for "+name, ""); + return thisPath; + } + throw new ObjectNotFoundException("No match for "+name, ""); + } + + public abstract EntityPath getEntity() throws ObjectNotFoundException; + + public abstract LDAPAttributeSet createAttributeSet() throws ObjectCannotBeUpdated; + + public boolean equals( Object path ) + { + return toString().equals(path.toString()); + } + + public int hashCode() { + return toString().hashCode(); + } + + public String dump() { + StringBuffer comp = new StringBuffer("Components: { "); + for (int i=0; i