1 package com
.interrupt
.bob
.base
;
3 import org
.apache
.log4j
.Logger
;
4 import org
.xml
.sax
.Attributes
;
5 import org
.xml
.sax
.helpers
.AttributesImpl
;
7 import java
.io
.ByteArrayOutputStream
;
9 import java
.io
.InputStream
;
10 import java
.io
.IOException
;
11 import java
.io
.ByteArrayInputStream
;
12 import java
.io
.InputStreamReader
;
13 import java
.io
.ObjectInputStream
;
14 import java
.io
.ObjectOutputStream
;
15 import java
.io
.PipedInputStream
;
16 import java
.io
.PipedOutputStream
;
17 import java
.io
.PushbackReader
;
18 import java
.io
.Serializable
;
19 import java
.util
.List
;
20 import java
.util
.ArrayList
;
21 import java
.util
.ListIterator
;
22 import java
.util
.TreeSet
;
23 import java
.util
.HashMap
;
24 import java
.util
.Iterator
;
25 import java
.util
.Properties
;
26 import java
.util
.Stack
;
28 import com
.interrupt
.IAncestor
;
29 import com
.interrupt
.bob
.FindFiles
;
30 //import com.interrupt.bob.Attributes;
31 /*import com.interrupt.bob.base.IBob;
32 import com.interrupt.bob.base.BobException;
33 import com.interrupt.bob.base.ToXMLVisitorPass1;
34 import com.interrupt.bob.base.ToXMLVisitorPass2;
36 import com
.interrupt
.bob
.core
.IMemory
;
37 import com
.interrupt
.bob
.core
.IMemoryField
;
38 import com
.interrupt
.bob
.core
.Memory
;
39 import com
.interrupt
.bob
.core
.MemoryField
;
40 import com
.interrupt
.bob
.core
.Queue
;
41 import com
.interrupt
.bob
.handler
.DocumentHandler
;
42 import com
.interrupt
.bob
.handler
.DefinitionHandler
;
43 import com
.interrupt
.bob
.handler
.BobHandler
;
44 import com
.interrupt
.bob
.util
.StringUtil
;
45 import com
.interrupt
.bob
.processor
.ProcessorException
;
46 import com
.interrupt
.bob
.processor
.DocumentProcessor
;
47 import com
.interrupt
.bob
.processor
.cc
.DepthFirstVisitor
;
49 import com
.interrupt
.bob
.util
.Util
;
50 import com
.interrupt
.cc
.xpath
.lexer
.Lexer
;
51 import com
.interrupt
.cc
.xpath
.lexer
.LexerException
;
52 import com
.interrupt
.cc
.xpath
.node
.Node
;
53 import com
.interrupt
.cc
.xpath
.node
.Start
;
54 import com
.interrupt
.cc
.xpath
.parser
.Parser
;
55 import com
.interrupt
.cc
.xpath
.parser
.ParserException
;
57 import org
.xml
.sax
.XMLReader
;
58 import org
.xml
.sax
.helpers
.XMLReaderFactory
;
59 import org
.xml
.sax
.SAXException
;
60 import org
.xml
.sax
.InputSource
;
63 public class Bob
implements IBob
{
66 private Logger logger
= Logger
.getLogger(Bob
.class);
68 // '_genchildren' used when compiling definitions
69 protected TreeSet _genchildren
= null;
70 protected List _children
= null;
71 protected IBob _parent
= null;
73 private Properties _properties
= null;
74 private boolean _nsVisible
= true;
75 private String _name
= null;
76 protected String _namespaceURI
= null;
77 private HashMap _namespaceMap
= null;
79 private HashMap _nsPrefixMappings
= null;
80 private String nsPrefix
= null;
82 protected Attributes _attributes
= null;
84 private String _text
= null;
85 private String _openString
= null;
86 private String _closeString
= null;
93 _properties
= new Properties();
95 _children
= new ArrayList();
96 _genchildren
= new TreeSet(new BobComparator());
97 _namespaceMap
= new HashMap();
98 _attributes
= new AttributesImpl();
101 public Bob(String namespace
, String tagName
) {
104 _namespaceURI
= namespace
;
106 _properties
= new Properties();
108 _children
= new ArrayList();
109 _genchildren
= new TreeSet(new BobComparator());
110 _namespaceMap
= new HashMap();
111 _attributes
= new AttributesImpl();
115 public void overwriteShallow(IBob overwritor
) {
117 this.setAttributes(overwritor
.getAttributes());
118 this.setChildren(overwritor
.getChildren());
123 public void setProperty(String name
, String value
) {
125 _properties
.setProperty(name
, value
);
127 public String
getProperty(String name
) {
129 return (String
)_properties
.getProperty(name
);
134 public boolean isNSVisible() {
137 public void setNSVisible(boolean visible
) {
138 this._nsVisible
= visible
;
142 public void setNSPrefix(String prefix
) {
143 this.nsPrefix
= prefix
;
145 public String
getNSPrefix() {
151 public IBob
getParent() {
154 public void setParent(IBob _parent
) {
155 this._parent
= _parent
;
158 public void addChild(IBob child
) {
159 this._children
.add(child
);
161 public void addChildren(List children
) {
162 this._children
.addAll(children
);
165 public List
allChildren() {
166 return new ArrayList(_children
);
168 public void removeAllChildren() {
169 this._children
.clear();
171 public boolean removeChild(IBob child
) {
173 // can't do this as an 'equals' comparison is not working
174 //return this._children.remove(child);
179 // TODO - this is much more inefficient!!!
180 Iterator liter
= this._children
.iterator();
182 while(liter
.hasNext()) {
184 eachbob
= (IBob
)liter
.next();
185 if(child
.equals(eachbob
)) {
193 public boolean remove(String tagName
, String attName
, String attValue
) {
196 logger
.debug("remove 1 / tname["+ tagName
+"] / attName["+ attName
+"] / attValue["+ attValue
+"]");
198 Iterator iter
= this.getChildren().iterator();
201 boolean matchFound
= false;
203 //** only loop if there's children
204 while(iter
.hasNext()) {
206 eachBob
= (IBob
)iter
.next();
207 boolean mfound
= eachBob
.remove(tagName
, attName
, attValue
);
212 logger
.debug(" 2 EACH / tname["+ eachBob
.getTagName() +"] / attName["+ attName
+"] / attValue["+ eachBob
.getAttributeValue(attName
) +"] / MATCH["+ (eachBob
.getTagName().equals( tagName
) && eachBob
.getAttributeValue(attName
).equals(attValue
)) +"]");
213 if( eachBob
.getTagName().equals( tagName
) &&
214 eachBob
.getAttributeValue(attName
).equals(attValue
) ) {
218 logger
.debug("MATCH FOUND!! / tname["+ tagName
+"] / attName["+ attName
+"] / attValue["+ attValue
+"]");
219 logger
.debug("Bob.logger.debugg ["+ eachBob
+"] ");
229 public boolean remove(String tagName
, String tagId
) {
231 return this.remove(tagName
, "id", tagId
);
235 public List
allGenChildren() {
236 return new ArrayList(_genchildren
);
238 public void addGenChild(IBob child
) {
239 this._genchildren
.add(child
);
241 public void removeAllGenChildren() {
242 this._genchildren
.clear();
244 public boolean removeGenChild(IBob child
) {
247 // can't do this as an 'equals' comparison is not working
248 //return this._genchildren.remove(child);
250 // TODO - this is much more inefficient!!!
251 Iterator liter
= this._genchildren
.iterator();
253 while(liter
.hasNext()) {
255 eachbob
= (IBob
)liter
.next();
256 if(child
.equals(eachbob
)) {
268 public IBob
find(String xpath
) {
271 // throw new RuntimeException("XPath 2.0 evaluation not yet implemented");
273 ByteArrayInputStream baInputStream
= new ByteArrayInputStream( xpath
.getBytes() );
274 PushbackReader pbreader
=
275 new PushbackReader( new InputStreamReader(baInputStream
), 1024 );
277 IBob xdmResults
= new Bob();
278 DepthFirstVisitor rdvisitor
= new DepthFirstVisitor();
279 rdvisitor
.setDocument(this);
281 System
.out
.println("xpath > start");
284 //** parse the syntax and provide the MODEL
285 Lexer lexer
= new Lexer(pbreader
);
286 Parser parser
= new Parser(lexer
);
288 System
.out
.println("xpath > parsing input");
291 Start tree
= parser
.parse();
293 System
.out
.println("");
294 System
.out
.println("xpath > running analyser");
297 tree
.apply(rdvisitor
);
298 if(rdvisitor
.getXdmList() instanceof Bob
) {
299 xdmResults
= rdvisitor
.getXdmList();
302 xdmResults
.addChild(rdvisitor
.getXdmList());
305 System
.out
.println("xpath > finished");
308 catch(java
.io
.IOException e
) {
311 catch(LexerException e
) {
314 catch(ParserException e
) {
323 public String
xpath() {
328 public String
xpath(boolean relative
) {
330 StringBuffer sbuffer
= new StringBuffer();
332 // get parent axis string
335 IBob parent
= this.getParent();
336 while(parent
!= null) {
338 sbuffer
.insert(0, "/");
339 sbuffer
.insert(0, parent
.buildAxisString());
340 parent
= parent
.getParent();
342 sbuffer
.insert(0, "/");
345 // append the axis string
346 sbuffer
.append(this.buildAxisString());
347 return sbuffer
.toString();
351 public String
buildAxisString() {
353 // take node name & append predicates
354 String axisString
= this.getTagName() + this.buildPredicateString(this.getAttributes());
357 public String
buildPredicateString(Attributes attributes
) {
359 // construct predicate based on attributes. should look something like...
360 // [ @attr='value' and @attr='value' ]
362 StringBuffer pbuffer
= new StringBuffer();
363 pbuffer
.append("[ ");
364 for(int i
= 0; i
< attributes
.getLength(); i
++) {
366 String avalue
= attributes
.getValue(i
).trim();
369 String aname
= attributes
.getLocalName(i
);
371 pbuffer
.append(aname
);
374 pbuffer
.append(avalue
);
377 if(i
< (attributes
.getLength() - 1)) {
379 pbuffer
.append(" and ");
383 pbuffer
.append(" ]");
385 return pbuffer
.toString();
389 public void replace(IBob replacor
) {
391 // the parent should stay the same
392 IBob parent
= this.getParent();
394 replacor
.setParent(parent
);
395 if( parent
!= null ) {
396 parent
.removeChild(this);
397 parent
.addChild(replacor
);
402 * ** a weakness of this method is that it cannot replace itself
404 public boolean replace(String tagName, String tagId, IBob replacor) {
406 logger.debug("Bob.replace["+ tagName +"] / tagId["+ tagId +"] / replacor["+ replacor.getClass() +"]");
407 Iterator iter = this.getChildren().iterator();
410 boolean matchFound = false;
412 //** only loop if there's children
413 while(iter.hasNext()) {
415 eachBob = (IBob)iter.next();
416 boolean mfound = eachBob.replace(tagName, tagId, replacor);
421 logger.debug("Bob.replace 2 / logger.debugteValue(id)["+ eachBob.getAttributeValue("id") +"] / MATCH["+ (eachBob.getTagName().equals( tagName ) &&
422 eachBob.getAttributeValue("id").equals( tagId )) +"]");
424 if( eachBob.getTagName().equals( tagName ) &&
425 eachBob.getAttributeValue("id").equals( tagId ) ) {
427 //logger.debug("Bob.replace 3");
430 //logger.debug("Bob.replace 2 / MATCH FOUND!logger.debugme +"] / id["+ tagId +"]");
431 //logger.debug("Bob.replace 3 / replacing["+ eachBob +"]");
439 this.addChild(replacor);
446 public IBob
getRoot() {
448 if(this._parent
!= null) {
449 return this._parent
.getRoot();
454 /*public IBob searchTree(String tag, String attributeName, String attributeValue) {
456 return this.getRoot().search(tag, attributeName, attributeValue);
461 public void accept(IVisitor visitor
) throws BobException
{
464 //logger.debug("Bob.accept: children["+_children+"] / children.size["+_children.size()+"] / iterator["+_children.iterator()+"]");
465 Iterator iter
= _children
.iterator();
467 while(iter
.hasNext()) {
470 next
= (IBob
)iter
.next();
474 logger
.debug("Cause: "+ e
.getCause());
475 logger
.debug("Message: "+ e
.getMessage());
476 e
.printStackTrace(System
.out
);
477 //logger.debug("Bob.accept: next["+next+"]");
478 //logger.debug("Bob.accept: children["+_children+"] / children.size["+_children.size()+"] / iterator["+_children.iterator()+"]");
479 throw new BobException(e
);
482 next
.accept(visitor
);
486 public void acceptFirst(IVisitor visitor
) throws BobException
{
490 Iterator iter
= _children
.iterator();
492 while(iter
.hasNext()) {
494 next
= (IBob
)iter
.next();
495 next
.acceptFirst(visitor
);
498 public void acceptSax(ISaxVisitor visitor
) throws BobException
{
500 visitor
.visitStart(this);
502 Iterator iter
= _children
.iterator();
504 while(iter
.hasNext()) {
506 next
= (IBob
)iter
.next();
507 next
.acceptSax(visitor
);
509 visitor
.visitEnd(this);
513 /* some methods to pull through the entire tree of objects
515 private Stack _pullStack
= null;
516 public IBob
pullNext() {
518 if(this._pullStack
== null) {
521 if(this._pullStack
.empty()) {
524 return (IBob
)this._pullStack
.pop();
526 public boolean canPull() {
528 if(this._pullStack
== null) {
531 if(this._pullStack
.empty()) {
534 return !this._pullStack
.empty();
536 public void resetPull() {
538 class PullVisitor
implements IVisitor
{
540 private Stack pullStack
= new Stack();
541 public void setStack(Stack stack
) {
542 this.pullStack
= stack
;
544 public Stack
getStack() {
545 return this.pullStack
;
548 public void visit(IBob bob
) {
550 this.pullStack
.push(bob
);
554 PullVisitor pvisitor
= new PullVisitor();
555 this.accept(pvisitor
);
557 this._pullStack
= pvisitor
.getStack();
562 /* search the tree for the first IBob node with this
564 public IBob
search( String tag
, String attributeName
, String attributeValue
) {
567 SearchVisitor svisitor
= new SearchVisitor();
568 svisitor
.setTagName(tag
);
569 svisitor
.setAttributeName(attributeName
);
570 svisitor
.setAttributeValue(attributeValue
);
572 this.accept(svisitor
);
573 return svisitor
.getResult();
581 public void toXML(java
.io
.PrintStream ps
) {
584 public void toXML(boolean inlineNS
, java
.io
.PrintStream ps
) {
585 ps
.print(toXML(inlineNS
));
588 public String
toXML() {
589 return this.toXML(true);
591 public String
toXML(boolean inlineNS
) {
593 //** clear XML String
594 ToXMLVisitorEraser veraser
= new ToXMLVisitorEraser();
595 this.accept(veraser
);
597 //** compose XML String
598 ToXMLVisitorPass1 txVisitor1
= new ToXMLVisitorPass1();
599 txVisitor1
.setInlineNS(inlineNS
);
601 String depth_s
= this.getProperty(IBob
.XML_DEPTH
);
602 if((depth_s
!= null) && (depth_s
.length() > 0)) {
603 int depth
= Integer
.parseInt(depth_s
);
604 txVisitor1
.setDepth(depth
);
606 ToXMLVisitorPass2 txVisitor2
= new ToXMLVisitorPass2();
608 this.acceptSax(txVisitor1
);
609 this.acceptSax(txVisitor2
);
610 return txVisitor2
.getXML();
617 public void setNamespace(String namespaceURI
) {
618 _namespaceURI
= namespaceURI
;
620 public String
getNamespace() {
621 return _namespaceURI
;
623 public void addNamespace(String ns
, String value
) {
624 _namespaceMap
.put(ns
,value
);
626 public String
getNamespace(String ns
) {
627 return (String
)_namespaceMap
.get(ns
);
629 public HashMap
getNamespaces() {
630 return new HashMap(_namespaceMap
);
632 public boolean hasNamespaces() {
633 return !_namespaceMap
.isEmpty();
637 /* namespace preix mappings
639 public void setPrefixMappings(HashMap prefixMappings
) {
640 this._nsPrefixMappings
= prefixMappings
;
642 public HashMap
getPrefixMappings() {
643 return this._nsPrefixMappings
;
647 /* attribute accessors
649 public void setTagName(String localName
) {
652 public String
getTagName() {
656 //public void setQName(String qName) {
659 public String
getQName() {
661 StringBuffer temp
= new StringBuffer();
662 if(this._namespaceURI
!= null) {
663 if(!this._namespaceURI
.equals("")) {
664 temp
.append(this._namespaceURI
);
667 temp
.append(this._name
);
669 return temp
.toString();
672 public void setAttributes(Attributes attribs
) {
673 _attributes
= attribs
;
675 public Attributes
getAttributes() {
678 public String
getAttributeValue(String avalue
) {
680 return _attributes
.getValue(avalue
);
683 public void setContent(String text
) {
686 public String
getContent() {
692 public IBob
getChild(int cindex
) {
693 return (IBob
)_children
.get(cindex
);
695 public List
getChildren() {
698 public void setChildren(List _children
) {
699 this._children
= _children
;
703 public void _setOpenString(String os
) {
706 public String
_getOpenString() {
709 public void _setCloseString(String cs
) {
712 public String
_getCloseString() {
721 public static IBob
make(String namespace
, String localName
) {
724 //logger.debug("Bob:: make / namespace["+namespace+"] / localname["+localName+"]");
726 /* TODO *** KLUDGE *** CLASS CREATION
727 * - there should be a 'createGName' / 'createIName'
729 String ns
= StringUtil
.namespaceToPackage(namespace
);
730 String cname
= StringUtil
.upperFirstLetter(localName
);
731 //logger.debug("1. Bob:: make / classname["+ ns + "." + cname +"]");
733 Class bobClass
= null;
737 if(ns
.trim().length() > 0) {
739 bobClass
= Class
.forName( ns
+ "." + cname
);
743 bobClass
= Class
.forName( cname
);
745 //logger.debug("1.5. Bob:: make / class["+ bobClass +"]");
747 catch(ClassNotFoundException e
) {
749 //e.printStackTrace();
752 //logger.debug("2. Bob:: make / classname["+ ns + "." + "G" + cname +"]");
753 if(ns
.length() > 0) {
755 bobClass
= Class
.forName( ns
+ "." + "G" + cname
);
758 bobClass
= Class
.forName( "G" + cname
);
761 catch(ClassNotFoundException ex
) {
762 ex
.printStackTrace();
773 result
= (IBob
)bobClass
.newInstance();
774 result
.setNamespace( namespace
);
776 //logger.debug("F: "+ result);
779 catch(InstantiationException e
) {
782 catch(IllegalAccessException e
) {
785 //logger.debug("3. Bob:: generated class["+ result +"]");
792 public static IBob
make( String fqclassname
) {
795 Class bobClass
= null;
798 //logger.debug("make / fqclassname["+fqclassname+"]");
799 bobClass
= Class
.forName( fqclassname
);
802 catch(ClassNotFoundException e
) {
809 String package_s
= fqclassname
.substring( 0, fqclassname
.lastIndexOf(".") );
810 String namespace
= StringUtil
.packageToNamespace( package_s
);
813 result
= (IBob
)bobClass
.newInstance();
814 result
.setNamespace( namespace
);
816 catch(InstantiationException e
) {
819 catch(IllegalAccessException e
) {
828 public static IBob
loadS(String xmlString
) {
830 String def_s
= System
.getProperties().getProperty(Util
.DEF
);
831 return Bob
.loadS( xmlString
, def_s
);
833 public static IBob
loadS(String xmlString
, String definitionFiles
) {
836 Logger
.getLogger(Bob
.class).debug("Bob.load("+xmlString
+", "+definitionFiles
+")");
839 ByteArrayInputStream bs
= null;
841 bs
= new ByteArrayInputStream(xmlString
.getBytes("UTF-8"));
843 catch(java
.io
.UnsupportedEncodingException e
) {
846 return Bob
.loadS( bs
, definitionFiles
);
851 public static IBob
loadS(File xmlFile
) {
853 java
.io
.FileInputStream fis
= null;
855 fis
= new java
.io
.FileInputStream(xmlFile
);
857 catch(java
.io
.FileNotFoundException e
) {
858 Logger
.getLogger(Bob
.class).error(e
,e
);
860 return Bob
._loadS( fis
);
862 public static IBob
loadS(File xmlFile
, String definitionFiles
) {
864 java
.io
.FileInputStream fis
= null;
866 fis
= new java
.io
.FileInputStream(xmlFile
);
868 catch(java
.io
.FileNotFoundException e
) {
869 Logger
.getLogger(Bob
.class).error(e
,e
);
871 return Bob
._loadS( fis
, definitionFiles
);
876 public static IBob
loadS(InputStream xmlis
) {
877 return Bob
._loadS( xmlis
);
879 public static IBob
loadS(InputStream xmlis
, String definitionFiles
) {
880 return Bob
._loadS( xmlis
, definitionFiles
);
885 private static IBob
_loadS( Object inputSource
) {
887 String def_s
= System
.getProperties().getProperty(Util
.DEF
);
888 return Bob
._loadS( inputSource
, def_s
);
891 private static IBob
_loadS( Object inputSource
, String definitionFiles
) {
893 Logger
.getLogger(Bob
.class).debug("Bob._load("+inputSource
+", "+definitionFiles
+")");
896 if( definitionFiles
== null || definitionFiles
.trim().length() < 1 ) {
897 Logger
.getLogger(Bob
.class).error("ERROR. definition files not specified for [_loadS( Object inputSource, String definitionFiles )]. Stopping.");
901 // create a BobHandler and its Listener
902 class LoadHandler
implements com
.interrupt
.bob
.DocumentHandler
{
904 private Logger logger
= Logger
.getLogger(Bob
.class);
905 private IBob bobToChange
= null;
906 public void endHandle(com
.interrupt
.callback
.CallbackEvent cevent
) {
908 Object result
= cevent
.getMessage();
909 if( result
instanceof IBob
) {
911 Bob rootBob
= (Bob
)result
;
912 logger
.debug("LoadHandler.endHandle / bobResult / ["+ rootBob
.toXML() +"]");
913 bobToChange
= (IBob
)rootBob
.allChildren().get(0);
918 public IBob
getBobToChange() {
921 public void setBobToChange(IBob bob
) {
926 LoadHandler lhandler
= new LoadHandler();
927 lhandler
.setBobToChange(new Bob());
929 com
.interrupt
.bob
.handler
.DocumentHandler definitionHandler
= new com
.interrupt
.bob
.handler
.DefinitionHandler();
930 definitionHandler
.setNamespace("com.interrupt.bob.handler");
931 definitionHandler
.setType("com.interrupt.bob.handler.DefinitionHandler");
932 definitionHandler
.setFiles(definitionFiles
);
933 definitionHandler
.setOut("definition.list");
936 com
.interrupt
.bob
.handler
.IHandlerField handlerField
= new com
.interrupt
.bob
.handler
.HandlerField();
937 handlerField
.setName("tagList");
938 handlerField
.setValue("${definition.list}");
940 com
.interrupt
.bob
.handler
.DocumentHandler bobHandler
= new com
.interrupt
.bob
.handler
.BobHandler();
941 bobHandler
.setNamespace("com.interrupt.bob.handler");
942 bobHandler
.setType("com.interrupt.bob.handler.BobHandler");
943 bobHandler
.setFiles("${bob.files}");
944 bobHandler
.setOut("bob.tree");
945 bobHandler
.addHandlerField(handlerField
);
946 bobHandler
.addListener(lhandler
);
948 com
.interrupt
.bob
.core
.Queue queue
= new com
.interrupt
.bob
.core
.Queue();
949 queue
.addDocumentHandler(definitionHandler
);
950 queue
.addDocumentHandler(bobHandler
);
953 MemoryField mfield
= new MemoryField();
954 mfield
.setName("bob.files");
955 mfield
.setValue(inputSource
);
956 queue
.getMemory().addMemoryField(mfield
);
959 Logger
.getLogger(Bob
.class).debug("BEGIN execute");
961 Logger
.getLogger(Bob
.class).debug("END execute");
964 catch(ProcessorException e
) {
965 e
.printStackTrace(System
.out
);
969 return lhandler
.getBobToChange();
974 public IBob
load(String xmlString
) { return Bob
.loadS(xmlString
); }
975 public IBob
load(String xmlString
, String definitionFiles
) { return Bob
.loadS(xmlString
, definitionFiles
); }
977 public IBob
load(File xmlFile
) { return Bob
.loadS(xmlFile
); }
978 public IBob
load(File xmlFile
, String definitionFiles
) { return Bob
.loadS(xmlFile
, definitionFiles
); }
980 public IBob
load(InputStream xmlis
) { return Bob
.loadS(xmlis
); }
981 public IBob
load(InputStream xmlis
, String definitionFiles
) { return Bob
.loadS(xmlis
, definitionFiles
); }
984 public boolean equals(Object bob
) {
986 if( !(bob
instanceof IBob
) ) {
988 //object for comparison is not an instance of 'IBob'
991 IBob ibob
= (IBob
)bob
;
993 // the specific XML structure must match
994 //return super.equals(bob);
995 String thisXML
= this.toXML();
996 String bobXML
= ibob
.toXML();
998 return thisXML
.equals(bobXML
);
1002 public int hashCode() {
1004 /*String xmls = this.toXML(false);
1005 int intValue = this..intValue();
1006 return intValue * 178345;
1011 public String
toString() {
1013 return this.toXML(false);
1017 public static void main(String args
[]) {
1019 System
.getProperties().setProperty(Util
.BASE
, ".");
1020 System
.getProperties().setProperty(Util
.END
, ".xml");
1021 System
.getProperties().setProperty(Util
.DEF
, "xml");
1023 IBob bobby
= new Bob();
1024 com
.interrupt
.bookkeeping
.GBookkeeping bkeeping
= (com
.interrupt
.bookkeeping
.GBookkeeping
)bobby
.load(new File("test/xml/bookkeeping.2.system.xml"),"test/xml/bookkeeping.2.system.xml");
1025 bkeeping
.setProperty(IBob
.XML_DEPTH
, "-1");
1027 class XOutput
implements IVisitor
{
1029 public void visit(IBob bob
) {
1030 System
.out
.println("");
1031 System
.out
.println("Visiting ["+ bob
.getTagName() +"]");
1032 System
.out
.println(bob
.xpath(false));
1035 XOutput xout
= new XOutput();
1036 //bkeeping.accept(xout); // print out the xpaths
1039 // credit[ @id='' and @amount='11.50' and @entryid='' and @accountid='3' and @account='' ]
1040 //IBob result = bkeeping.find("credit[ @id='' and @amount='11.50' and @entryid='' and @accountid='3' and @account='' ][ @zzz='timmy' ]");
1042 // /bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='j1' and @name='generalledger' and @type='' and @balance='' ]
1044 //IBob result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='j1' and @name='generalledger' and @type='' or @balance='' ] [ @zzz='timmy' ]");
1045 IBob result
= bkeeping
.find("/bookkeeping[ @id='' ]");
1046 //IBob result = bkeeping.find("/bookkeeping");
1047 //IBob result = bkeeping.find("/");
1049 System
.out
.println("\n\n\nFind RESULTS...");
1050 result
.toXML(System
.out
);
1052 // needs to return an XDM 1. Bob, text, sequence, etc