Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id
In directory sc8-pr-cvs1:/tmp/cvs-serv4908/src/java/org/neuclear/id
Modified Files:
GenericNamedObject.java InvalidNameSpaceException.java
NSTools.java NameSpace.java NamedObject.java
NamedObjectFactory.java
Log Message:
More fixes throughout to problems caused by renaming.
Index: GenericNamedObject.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/GenericNamedObject.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** GenericNamedObject.java 19 Sep 2003 14:41:03 -0000 1.1.1.1
--- GenericNamedObject.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:03 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 28,32 ****
import org.dom4j.Element;
import org.dom4j.Namespace;
! import org.neuclear.utils.NeudistException;
public class GenericNamedObject extends NamedObject {
--- 31,35 ----
import org.dom4j.Element;
import org.dom4j.Namespace;
! import org.neudist.utils.NeudistException;
public class GenericNamedObject extends NamedObject {
***************
*** 36,40 ****
public Namespace getNS() {
! return getElement().getQName().getNamespace();
}
--- 39,43 ----
public Namespace getNS() {
! return getElement().getQName().getNamespace();
}
Index: InvalidNameSpaceException.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/InvalidNameSpaceException.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** InvalidNameSpaceException.java 19 Sep 2003 14:40:55 -0000 1.1.1.1
--- InvalidNameSpaceException.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:40:55 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 56,60 ****
package org.neuclear.id;
! import org.neuclear.utils.NeudistException;
public class InvalidNameSpaceException extends NeudistException {
--- 59,63 ----
package org.neuclear.id;
! import org.neudist.utils.NeudistException;
public class InvalidNameSpaceException extends NeudistException {
Index: NSTools.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NSTools.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** NSTools.java 19 Sep 2003 14:40:58 -0000 1.1.1.1
--- NSTools.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:40:58 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 85,96 ****
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
! import org.neuclear.crypto.CryptoTools;
! import org.neuclear.utils.NeudistException;
! import org.neuclear.utils.Utility;
import java.util.Random;
public final class NSTools {
! private NSTools(){};
/**
--- 88,100 ----
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
! import org.neudist.crypto.CryptoTools;
! import org.neudist.utils.NeudistException;
! import org.neudist.utils.Utility;
import java.util.Random;
public final class NSTools {
! private NSTools() {
! };
/**
***************
*** 100,110 ****
* @throws NeudistException If name isn't a valid NEU Name
*/
! public static String normalizeNameURI(String name) throws NeudistException{
! if (!isValidName(name))
! throw new NeudistException("Name: '"+name+"' is not valid");
! if (!name.startsWith("neu://"))
! return "neu:/"+name;
! return name;
}
/**
* Name must follow the follwing rules:<br>
--- 104,115 ----
* @throws NeudistException If name isn't a valid NEU Name
*/
! public static String normalizeNameURI(String name) throws NeudistException {
! if (!isValidName(name))
! throw new NeudistException("Name: '" + name + "' is not valid");
! if (!name.startsWith("neu://"))
! return "neu:/" + name;
! return name;
}
+
/**
* Name must follow the follwing rules:<br>
***************
*** 120,125 ****
if (Utility.isEmpty(name))
return false;
! RE re=new RE("^(neu:\\/)?((\\/)|(\\/[a-zA-Z0-9_\\-\\.]+)*)$");
! return(re.match(name));
} catch (RESyntaxException e) {
e.printStackTrace();
--- 125,130 ----
if (Utility.isEmpty(name))
return false;
! RE re = new RE("^(neu:\\/)?((\\/)|(\\/[a-zA-Z0-9_\\-\\.]+)*)$");
! return (re.match(name));
} catch (RESyntaxException e) {
e.printStackTrace();
***************
*** 136,164 ****
*/
public static String getParentNSURI(String name) throws NeudistException {
! String uri=normalizeNameURI(name);
! int slash=uri.lastIndexOf('/');
! if (uri.equals("neu://")||(slash<5))
return "neu://";
! if (slash==5)
! return uri.substring(0,slash+1);
! return uri.substring(0,slash);
}
! public static String createUniqueNamedID(String nameSpace,String reqNameSpace) {
// Yeah, yeah there are better ways to do this
! String ms=new Long(System.currentTimeMillis()+new Random().nextLong()).toString(); //TODO seed the Random number generator
! byte ticketsrc[]=new byte[ms.length()+reqNameSpace.length()];
! System.arraycopy(ms.getBytes(),0,ticketsrc,0,ms.length());
! System.arraycopy(reqNameSpace.getBytes(),0,ticketsrc,ms.length(),reqNameSpace.length());
! String ticket=CryptoTools.formatAsURLSafe(CryptoTools.digest256(ticketsrc));
//Lets reuse ticketsrc for memory reasons
! int offset=ms.length()+1;
if (reqNameSpace.startsWith("neu://"))
! offset+=5;
! for (int i=offset;i<ticketsrc.length;i++) {
! if (ticketsrc[i]==(byte)'/')
! ticketsrc[i]=(byte)'.';
}
/*
--- 141,169 ----
*/
public static String getParentNSURI(String name) throws NeudistException {
! String uri = normalizeNameURI(name);
! int slash = uri.lastIndexOf('/');
! if (uri.equals("neu://") || (slash < 5))
return "neu://";
! if (slash == 5)
! return uri.substring(0, slash + 1);
! return uri.substring(0, slash);
}
! public static String createUniqueNamedID(String nameSpace, String reqNameSpace) {
// Yeah, yeah there are better ways to do this
! String ms = new Long(System.currentTimeMillis() + new Random().nextLong()).toString(); //TODO seed the Random number generator
! byte ticketsrc[] = new byte[ms.length() + reqNameSpace.length()];
! System.arraycopy(ms.getBytes(), 0, ticketsrc, 0, ms.length());
! System.arraycopy(reqNameSpace.getBytes(), 0, ticketsrc, ms.length(), reqNameSpace.length());
! String ticket = CryptoTools.formatAsURLSafe(CryptoTools.digest256(ticketsrc));
//Lets reuse ticketsrc for memory reasons
! int offset = ms.length() + 1;
if (reqNameSpace.startsWith("neu://"))
! offset += 5;
! for (int i = offset; i < ticketsrc.length; i++) {
! if (ticketsrc[i] == (byte) '/')
! ticketsrc[i] = (byte) '.';
}
/*
***************
*** 168,196 ****
System.arraycopy(ticket,0,ticketName,userNameSpace.length()+1,ticket.length);
*/
! return nameSpace+'/'+new String(ticketsrc,offset,ticketsrc.length-offset)+'.'+ticket;
}
public static String url2path(String name) {
! if (!Utility.isEmpty(name)){
! int loc=name.indexOf("://");
! if (loc>=0)
! return name.substring(loc+2); //leave in one '/'
! else if (name.substring(0,1).equals("/"))
return name;
else
! return "/"+name;
}
return "/";
}
! public static void main(String args[]){
try {
! NamedObject obj=NamedObjectFactory.fetchNamedObject("neu://free/pelle");
! System.out.println("Got: "+obj.getName());
! obj=NamedObjectFactory.fetchNamedObject("neu://pelle");
! System.out.println("Got: "+obj.getName());
! obj=NamedObjectFactory.fetchNamedObject("neu://free");
! System.out.println("Got: "+obj.getName());
! obj=NamedObjectFactory.fetchNamedObject("neu://free/pelle");
! System.out.println("Got: "+obj.getName());
// obj=NamedObjectFactory.fetchNamedObject("neu://free/trix");
// System.out.println("Got: "+obj.getName());
--- 173,202 ----
System.arraycopy(ticket,0,ticketName,userNameSpace.length()+1,ticket.length);
*/
! return nameSpace + '/' + new String(ticketsrc, offset, ticketsrc.length - offset) + '.' + ticket;
}
public static String url2path(String name) {
! if (!Utility.isEmpty(name)) {
! int loc = name.indexOf("://");
! if (loc >= 0)
! return name.substring(loc + 2); //leave in one '/'
! else if (name.substring(0, 1).equals("/"))
return name;
else
! return "/" + name;
}
return "/";
}
!
! public static void main(String args[]) {
try {
! NamedObject obj = NamedObjectFactory.fetchNamedObject("neu://free/pelle");
! System.out.println("Got: " + obj.getName());
! obj = NamedObjectFactory.fetchNamedObject("neu://pelle");
! System.out.println("Got: " + obj.getName());
! obj = NamedObjectFactory.fetchNamedObject("neu://free");
! System.out.println("Got: " + obj.getName());
! obj = NamedObjectFactory.fetchNamedObject("neu://free/pelle");
! System.out.println("Got: " + obj.getName());
// obj=NamedObjectFactory.fetchNamedObject("neu://free/trix");
// System.out.println("Got: "+obj.getName());
Index: NameSpace.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NameSpace.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** NameSpace.java 19 Sep 2003 14:41:08 -0000 1.1.1.1
--- NameSpace.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:08 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 142,149 ****
import org.neuclear.senders.LogSender;
import org.neuclear.senders.Sender;
! import org.neuclear.utils.NeudistException;
! import org.neuclear.utils.Utility;
! import org.neuclear.xml.xmlsec.KeyInfo;
! import org.neuclear.xml.xmlsec.XMLSecTools;
import java.security.PublicKey;
--- 145,152 ----
import org.neuclear.senders.LogSender;
import org.neuclear.senders.Sender;
! import org.neudist.utils.NeudistException;
! import org.neudist.utils.Utility;
! import org.neudist.xml.xmlsec.KeyInfo;
! import org.neudist.xml.xmlsec.XMLSecTools;
import java.security.PublicKey;
***************
*** 151,200 ****
import java.util.List;
! public final class NameSpace extends NamedObject {
! /**
! * This constructor should be used by subclasses of NameSpace. It creates a Standard NameSpace document, but doesn't sign it.
! * The signing should be done as the last step of the constructor of the subclass.
! * @param name The Name of NameSpace
! * @param allow PublicKey allowed to sign in here
! * @param repository URL of Default Store for NameSpace. (Note. A NameSpace object is stored in the default repository of it's parent namespace)
! * @param signer URL of default interactive signing service for namespace. If null it doesnt allow interactive signing
! * @param receiver URL of default receiver for namespace
! * @throws NeudistException
! */
! public NameSpace(String name,PublicKey allow,String repository,String signer,String logger,String receiver) throws NeudistException {
! super(name,"NameSpace");
! Element root=getElement();
! // We have meaningful defaults for the following two
! this.repository=Utility.denullString(repository,NSResolver.NSROOTSTORE);
! this.logger=Utility.denullString(repository,LogSender.LOGGER);
! this.signer=signer;
! this.receiver=receiver;
! root.addAttribute(DocumentHelper.createQName("repository",NamedObject.NS_NSDL),this.repository);
! root.addAttribute(DocumentHelper.createQName("logger",NamedObject.NS_NSDL),receiver);
! if (!Utility.isEmpty(signer))
! root.addAttribute(DocumentHelper.createQName("signer",NamedObject.NS_NSDL),signer);
! if (!Utility.isEmpty(receiver))
! root.addAttribute(DocumentHelper.createQName("receiver",NamedObject.NS_NSDL),receiver);
! if (allow!=null) {
! QName allowName=DocumentHelper.createQName("allow",NamedObject.NS_NSDL);
! Element pub=root.addElement(allowName);
! pubs=new PublicKey[1];
! pubs[0]=allow;
! pub.add(XMLSecTools.createKeyInfo(allow));
! }
}
! public NameSpace(String name,PublicKey allow,String repository) throws NeudistException {
! this(name,allow,repository,null,null,null);
}
- public NameSpace(String name,PublicKey allow) throws NeudistException {
- this(name,allow,null);
- }
/**
--- 154,204 ----
import java.util.List;
! public final class NameSpace extends NamedObject {
! /**
! * This constructor should be used by subclasses of NameSpace. It creates a Standard NameSpace document, but doesn't sign it.
! * The signing should be done as the last step of the constructor of the subclass.
! * @param name The Name of NameSpace
! * @param allow PublicKey allowed to sign in here
! * @param repository URL of Default Store for NameSpace. (Note. A NameSpace object is stored in the default repository of it's parent namespace)
! * @param signer URL of default interactive signing service for namespace. If null it doesnt allow interactive signing
! * @param receiver URL of default receiver for namespace
! * @throws NeudistException
! */
! public NameSpace(String name, PublicKey allow, String repository, String signer, String logger, String receiver) throws NeudistException {
! super(name, "NameSpace");
! Element root = getElement();
! // We have meaningful defaults for the following two
! this.repository = Utility.denullString(repository, NSResolver.NSROOTSTORE);
! this.logger = Utility.denullString(repository, LogSender.LOGGER);
! this.signer = signer;
! this.receiver = receiver;
! root.addAttribute(DocumentHelper.createQName("repository", NamedObject.NS_NSDL), this.repository);
! root.addAttribute(DocumentHelper.createQName("logger", NamedObject.NS_NSDL), receiver);
! if (!Utility.isEmpty(signer))
! root.addAttribute(DocumentHelper.createQName("signer", NamedObject.NS_NSDL), signer);
! if (!Utility.isEmpty(receiver))
! root.addAttribute(DocumentHelper.createQName("receiver", NamedObject.NS_NSDL), receiver);
! if (allow != null) {
! QName allowName = DocumentHelper.createQName("allow", NamedObject.NS_NSDL);
! Element pub = root.addElement(allowName);
! pubs = new PublicKey[1];
! pubs[0] = allow;
! pub.add(XMLSecTools.createKeyInfo(allow));
}
+ }
! public NameSpace(String name, PublicKey allow, String repository) throws NeudistException {
! this(name, allow, repository, null, null, null);
! }
!
! public NameSpace(String name, PublicKey allow) throws NeudistException {
! this(name, allow, null);
}
/**
***************
*** 214,230 ****
super(nsElem);
try {
! Element ns =getElement();
! repository=ns.attributeValue(DocumentHelper.createQName("store",NamedObject.NS_NSDL));
! signer=ns.attributeValue(DocumentHelper.createQName("signer",NamedObject.NS_NSDL));
! logger=ns.attributeValue(DocumentHelper.createQName("logger",NamedObject.NS_NSDL));
! receiver=ns.attributeValue(DocumentHelper.createQName("receiver",NamedObject.NS_NSDL));
! Element allowElement=ns.element(DocumentHelper.createQName("allow",NamedObject.NS_NSDL));
! List keys=allowElement.elements(XMLSecTools.createQName("KeyInfo"));
! pubs=new PublicKey[keys.size()];
! int i=0;
! for (Iterator iter=keys.iterator();iter.hasNext();i++) {
! KeyInfo ki=new KeyInfo((Element)iter.next());
! pubs[i]=ki.getPublicKey();
}
} catch (Exception e) {
--- 218,234 ----
super(nsElem);
try {
! Element ns = getElement();
! repository = ns.attributeValue(DocumentHelper.createQName("store", NamedObject.NS_NSDL));
! signer = ns.attributeValue(DocumentHelper.createQName("signer", NamedObject.NS_NSDL));
! logger = ns.attributeValue(DocumentHelper.createQName("logger", NamedObject.NS_NSDL));
! receiver = ns.attributeValue(DocumentHelper.createQName("receiver", NamedObject.NS_NSDL));
! Element allowElement = ns.element(DocumentHelper.createQName("allow", NamedObject.NS_NSDL));
! List keys = allowElement.elements(XMLSecTools.createQName("KeyInfo"));
! pubs = new PublicKey[keys.size()];
! int i = 0;
! for (Iterator iter = keys.iterator(); iter.hasNext(); i++) {
! KeyInfo ki = new KeyInfo((Element) iter.next());
! pubs[i] = ki.getPublicKey();
}
} catch (Exception e) {
***************
*** 238,247 ****
*/
public PublicKey getAllowed() {
! if (pubs!=null&&pubs.length>0)
return pubs[0];
else
return null;
}
! public boolean postAllowed(NamedObject obj) throws NeudistException{
try {
for (int i = 0; i < pubs.length; i++) {
--- 242,252 ----
*/
public PublicKey getAllowed() {
! if (pubs != null && pubs.length > 0)
return pubs[0];
else
return null;
}
!
! public boolean postAllowed(NamedObject obj) throws NeudistException {
try {
for (int i = 0; i < pubs.length; i++) {
***************
*** 269,284 ****
public final void send(NamedObject obj) throws NeudistException {
if (!Utility.isEmpty(receiver))
! Sender.quickSend(receiver,obj);
else
! throw new NeudistException("Cant send object, "+getName()+" doesnt have a registered Receiver");
}
void log(NamedObject obj) throws NeudistException {
if (!Utility.isEmpty(logger))
! Sender.quickSend(logger,obj);
}
public String getTagName() {
return "NameSpace";
}
private String repository;
private String signer;
--- 274,291 ----
public final void send(NamedObject obj) throws NeudistException {
if (!Utility.isEmpty(receiver))
! Sender.quickSend(receiver, obj);
else
! throw new NeudistException("Cant send object, " + getName() + " doesnt have a registered Receiver");
}
void log(NamedObject obj) throws NeudistException {
if (!Utility.isEmpty(logger))
! Sender.quickSend(logger, obj);
}
+
public String getTagName() {
return "NameSpace";
}
+
private String repository;
private String signer;
Index: NamedObject.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NamedObject.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** NamedObject.java 19 Sep 2003 14:41:03 -0000 1.1.1.1
--- NamedObject.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:03 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 129,139 ****
import org.neuclear.id.targets.TargetReference;
import org.neuclear.time.TimeTools;
! import org.neuclear.utils.NeudistException;
! import org.neuclear.utils.Utility;
! import org.neuclear.xml.AbstractElementProxy;
! import org.neuclear.xml.XMLException;
! import org.neuclear.xml.xmlsec.SignedElement;
! import org.neuclear.xml.xmlsec.XMLSecTools;
! import org.neuclear.xml.xmlsec.XMLSecurityException;
import java.sql.Timestamp;
--- 132,142 ----
import org.neuclear.id.targets.TargetReference;
import org.neuclear.time.TimeTools;
! import org.neudist.utils.NeudistException;
! import org.neudist.utils.Utility;
! import org.neudist.xml.AbstractElementProxy;
! import org.neudist.xml.XMLException;
! import org.neudist.xml.xmlsec.SignedElement;
! import org.neudist.xml.xmlsec.XMLSecTools;
! import org.neudist.xml.xmlsec.XMLSecurityException;
import java.sql.Timestamp;
***************
*** 141,149 ****
import java.util.LinkedList;
import java.util.List;
/**
* This simple wrapper takes most of the contents of a NamedObject and puts it into a Serializable form that can be signed.
*/
public abstract class NamedObject extends SignedElement {
! protected NamedObject(String name,String tagName, String prefix, String nsURI) {
super(tagName, prefix, nsURI);
createDocument();
--- 144,153 ----
import java.util.LinkedList;
import java.util.List;
+
/**
* This simple wrapper takes most of the contents of a NamedObject and puts it into a Serializable form that can be signed.
*/
public abstract class NamedObject extends SignedElement {
! protected NamedObject(String name, String tagName, String prefix, String nsURI) {
super(tagName, prefix, nsURI);
createDocument();
***************
*** 151,166 ****
}
! protected NamedObject(String name,String tagName, Namespace ns) {
super(tagName, ns);
createDocument();
setName(name);
}
! protected NamedObject(String name,String tagName) {
! super(tagName,NamedObject.NS_NSDL);
createDocument();
setName(name);
}
! protected NamedObject(String name,QName qname) {
super(qname);
createDocument();
--- 155,171 ----
}
! protected NamedObject(String name, String tagName, Namespace ns) {
super(tagName, ns);
createDocument();
setName(name);
}
!
! protected NamedObject(String name, String tagName) {
! super(tagName, NamedObject.NS_NSDL);
createDocument();
setName(name);
}
! protected NamedObject(String name, QName qname) {
super(qname);
createDocument();
***************
*** 171,178 ****
super(elem);
createDocument();
! String name=getName();
processTargetElements();
if (Utility.isEmpty(name))
! throw new NeudistException("Element: "+elem.getQualifiedName()+" doesnt contain a valid name attribute");
}
--- 176,183 ----
super(elem);
createDocument();
! String name = getName();
processTargetElements();
if (Utility.isEmpty(name))
! throw new NeudistException("Element: " + elem.getQualifiedName() + " doesnt contain a valid name attribute");
}
***************
*** 181,185 ****
* @return String containing the fully qualified URI of an object
*/
! public String getName() throws NeudistException{
return NSTools.normalizeNameURI(getElement().attributeValue(getNameAttrQName()));
}
--- 186,190 ----
* @return String containing the fully qualified URI of an object
*/
! public String getName() throws NeudistException {
return NSTools.normalizeNameURI(getElement().attributeValue(getNameAttrQName()));
}
***************
*** 189,212 ****
* @return Parent Name
*/
! public String getLocalName() throws NeudistException{
! String fullName=getName();
! int i=fullName.lastIndexOf('/');
! return fullName.substring(i+1);
}
private void setName(String name) {
! getElement().addAttribute(getNameAttrQName(),name);
}
private static QName getNameAttrQName() {
! return DocumentHelper.createQName("name",NamedObject.NS_NSDL);
}
private void createDocument() {
! Element elem=getElement();
! if(elem.getDocument()==null) {
! Document doc=DocumentHelper.createDocument(elem);
}
}
/**
* @return the URI of the object. In this case the same as getName();
--- 194,219 ----
* @return Parent Name
*/
! public String getLocalName() throws NeudistException {
! String fullName = getName();
! int i = fullName.lastIndexOf('/');
! return fullName.substring(i + 1);
}
private void setName(String name) {
! getElement().addAttribute(getNameAttrQName(), name);
}
private static QName getNameAttrQName() {
! return DocumentHelper.createQName("name", NamedObject.NS_NSDL);
}
+
private void createDocument() {
! Element elem = getElement();
! if (elem.getDocument() == null) {
! Document doc = DocumentHelper.createDocument(elem);
}
}
+
/**
* @return the URI of the object. In this case the same as getName();
***************
*** 245,255 ****
super.addElement(child);
}
protected void addElement(NamedObject child) throws XMLException {
! addElement((AbstractElementProxy)child);
}
protected void isModifiable() throws NeudistException {
if (isSigned())
! throw new NeudistException("NamedObject: "+getName()+" is signed and cant be modified");
}
--- 252,263 ----
super.addElement(child);
}
+
protected void addElement(NamedObject child) throws XMLException {
! addElement((AbstractElementProxy) child);
}
protected void isModifiable() throws NeudistException {
if (isSigned())
! throw new NeudistException("NamedObject: " + getName() + " is signed and cant be modified");
}
***************
*** 257,264 ****
* Sign NamedObject using given PrivateKey. This also adds a timestamp to the root element prior to signing
*/
! protected final void preSign() throws XMLSecurityException{
// We need to timestamp it before we sign it
! getElement().addAttribute(DocumentHelper.createQName("timestamp",NamedObject.NS_NSDL),TimeTools.createTimeStamp());
! }
/**
--- 265,272 ----
* Sign NamedObject using given PrivateKey. This also adds a timestamp to the root element prior to signing
*/
! protected final void preSign() throws XMLSecurityException {
// We need to timestamp it before we sign it
! getElement().addAttribute(DocumentHelper.createQName("timestamp", NamedObject.NS_NSDL), TimeTools.createTimeStamp());
! }
/**
***************
*** 281,319 ****
public void addTarget(TargetReference target) throws NeudistException {
isModifiable();
! if (target==null)
return;
! QName targetsQN=DocumentHelper.createQName("Targets",NamedObject.NS_NSDL);
! Element targetsElem=getElement().element(targetsQN);
! if (targetsElem==null){
! targetsElem=DocumentHelper.createElement(targetsQN);
getElement().add(targetsElem);
}
! targetsElem.add(target.getElement());
! targetList().add(target);
}
/**
! */
! private void processTargetElements() throws NeudistException {
! //System.out.println("NEUDIST: registering targets for "+getName());
! QName targetsQN=DocumentHelper.createQName("Targets",NamedObject.NS_NSDL);
! Element targetsElem=getElement().element(targetsQN);
! if (targetsElem!=null){
! Iterator iter=targetsElem.elementIterator(DocumentHelper.createQName("TargetReference",NamedObject.NS_NSDL));
! while (iter.hasNext()) {
! Element o = (Element) iter.next();
! TargetReference target=new TargetReference(this,o);
! System.out.println("NEUDIST: Registring target: "+target.getHref());
! targetList().add(target);
! }
! }
! }
private synchronized List targetList() {
! if (targets==null)
! targets=new LinkedList();
return targets;
}
/**
* Lists the targets within an object
--- 289,329 ----
public void addTarget(TargetReference target) throws NeudistException {
isModifiable();
! if (target == null)
return;
! QName targetsQN = DocumentHelper.createQName("Targets", NamedObject.NS_NSDL);
! Element targetsElem = getElement().element(targetsQN);
! if (targetsElem == null) {
! targetsElem = DocumentHelper.createElement(targetsQN);
getElement().add(targetsElem);
}
! targetsElem.add(target.getElement());
! targetList().add(target);
}
+
/**
! */
! private void processTargetElements() throws NeudistException {
! //System.out.println("NEUDIST: registering targets for "+getName());
! QName targetsQN = DocumentHelper.createQName("Targets", NamedObject.NS_NSDL);
! Element targetsElem = getElement().element(targetsQN);
! if (targetsElem != null) {
! Iterator iter = targetsElem.elementIterator(DocumentHelper.createQName("TargetReference", NamedObject.NS_NSDL));
! while (iter.hasNext()) {
! Element o = (Element) iter.next();
! TargetReference target = new TargetReference(this, o);
! System.out.println("NEUDIST: Registring target: " + target.getHref());
! targetList().add(target);
! }
! }
! }
private synchronized List targetList() {
! if (targets == null)
! targets = new LinkedList();
return targets;
}
+
/**
* Lists the targets within an object
***************
*** 327,339 ****
* Sends copy of object to all targets within
*/
! public void sendObject() throws NeudistException{
! System.out.println("NEUDIST: Sending Object "+getName());
if (this.isSigned()) {
! Iterator iter=listTargets();
! while(iter.hasNext()) {
! TargetReference tg=((TargetReference)iter.next());
tg.send();
! System.out.println("NEUDIST: Sent to "+tg.getHref());
}
--- 337,349 ----
* Sends copy of object to all targets within
*/
! public void sendObject() throws NeudistException {
! System.out.println("NEUDIST: Sending Object " + getName());
if (this.isSigned()) {
! Iterator iter = listTargets();
! while (iter.hasNext()) {
! TargetReference tg = ((TargetReference) iter.next());
tg.send();
! System.out.println("NEUDIST: Sent to " + tg.getHref());
}
***************
*** 343,348 ****
public Timestamp getTimeStamp() throws NeudistException {
! String timeString=getElement().attributeValue(DocumentHelper.createQName("timestamp",NamedObject.NS_NSDL));
! if (isSigned()&&!Utility.isEmpty(timeString)){
try {
return TimeTools.parseTimeStamp(timeString);
--- 353,358 ----
public Timestamp getTimeStamp() throws NeudistException {
! String timeString = getElement().attributeValue(DocumentHelper.createQName("timestamp", NamedObject.NS_NSDL));
! if (isSigned() && !Utility.isEmpty(timeString)) {
try {
return TimeTools.parseTimeStamp(timeString);
***************
*** 356,359 ****
--- 366,370 ----
}
+
public final void log() throws NeudistException {
NameSpace ns = getParent();
***************
*** 362,366 ****
public NameSpace getParent() throws NeudistException {
! NameSpace ns=NSResolver.resolveNameSpace(NSTools.getParentNSURI(getName()));
return ns;
}
--- 373,377 ----
public NameSpace getParent() throws NeudistException {
! NameSpace ns = NSResolver.resolveNameSpace(NSTools.getParentNSURI(getName()));
return ns;
}
***************
*** 368,375 ****
private List targets;
! public static final String NSDL_NAMESPACE="http://neuclear.org/neu/nsdl";
! public static final Namespace NS_NSDL=DocumentHelper.createNamespace("nsdl",NamedObject.NSDL_NAMESPACE);
! public static final String NSDL_PREFIX="nsdl:";
}
--- 379,386 ----
private List targets;
! public static final String NSDL_NAMESPACE = "http://neuclear.org/neu/nsdl";
! public static final Namespace NS_NSDL = DocumentHelper.createNamespace("nsdl", NamedObject.NSDL_NAMESPACE);
! public static final String NSDL_PREFIX = "nsdl:";
}
Index: NamedObjectFactory.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NamedObjectFactory.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** NamedObjectFactory.java 19 Sep 2003 14:40:53 -0000 1.1.1.1
--- NamedObjectFactory.java 22 Sep 2003 19:24:01 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:01 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:40:53 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 118,122 ****
import org.neuclear.id.verifier.NSVerifier;
import org.neuclear.source.Source;
! import org.neuclear.utils.NeudistException;
public class NamedObjectFactory {
--- 121,125 ----
import org.neuclear.id.verifier.NSVerifier;
import org.neuclear.source.Source;
! import org.neudist.utils.NeudistException;
public class NamedObjectFactory {
***************
*** 140,147 ****
*/
public static NamedObject createNamedObject(Element elem) throws NeudistException {
! QName rootName=elem.getQName();
! if (rootName.getName().equals("NameSpace")&&rootName.getNamespaceURI().equals(NamedObject.NSDL_NAMESPACE))
return new NameSpace(elem);
! else if(rootName.getName().equals("AuthenticationTicket")&&rootName.getNamespaceURI().equals(AuthenticationTicket.URI_NSAUTH))
return new AuthenticationTicket(elem);
else
--- 143,150 ----
*/
public static NamedObject createNamedObject(Element elem) throws NeudistException {
! QName rootName = elem.getQName();
! if (rootName.getName().equals("NameSpace") && rootName.getNamespaceURI().equals(NamedObject.NSDL_NAMESPACE))
return new NameSpace(elem);
! else if (rootName.getName().equals("AuthenticationTicket") && rootName.getNamespaceURI().equals(AuthenticationTicket.URI_NSAUTH))
return new AuthenticationTicket(elem);
else
***************
*** 150,164 ****
}
! public static NamedObject fetchNamedObject(String name) throws NeudistException{
! String parentName=NSTools.getParentNSURI(name);
if (!parentName.equals("neu://")) {
! NameSpace parent=NSResolver.resolveNameSpace(parentName);
! if (parent==null)
return null;
}
! NamedObject nobj= Source.getInstance().fetch(NSResolver.NSROOTSTORE,name);
if (!NSVerifier.isNameValid(nobj))
! throw new InvalidNameSpaceException(nobj.getName()+" is not valid");
return nobj;
}
--- 153,167 ----
}
! public static NamedObject fetchNamedObject(String name) throws NeudistException {
! String parentName = NSTools.getParentNSURI(name);
if (!parentName.equals("neu://")) {
! NameSpace parent = NSResolver.resolveNameSpace(parentName);
! if (parent == null)
return null;
}
! NamedObject nobj = Source.getInstance().fetch(NSResolver.NSROOTSTORE, name);
if (!NSVerifier.isNameValid(nobj))
! throw new InvalidNameSpaceException(nobj.getName() + " is not valid");
return nobj;
}
|