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();
116 public void overwriteShallow(IBob overwritor
) {
118 this.setAttributes(overwritor
.getAttributes());
119 this.setChildren(overwritor
.getChildren());
124 public void setProperty(String name
, String value
) {
126 _properties
.setProperty(name
, value
);
128 public String
getProperty(String name
) {
130 return (String
)_properties
.getProperty(name
);
135 public boolean isNSVisible() {
138 public void setNSVisible(boolean visible
) {
139 this._nsVisible
= visible
;
143 public void setNSPrefix(String prefix
) {
144 this.nsPrefix
= prefix
;
146 public String
getNSPrefix() {
152 public IBob
getParent() {
155 public void setParent(IBob _parent
) {
156 this._parent
= _parent
;
159 public void addChild(IBob child
) {
160 this._children
.add(child
);
162 public void addChildren(List children
) {
163 this._children
.addAll(children
);
166 public List
allChildren() {
167 return new ArrayList(_children
);
169 public void removeAllChildren() {
170 this._children
.clear();
172 public boolean removeChild(IBob child
) {
174 // can't do this as an 'equals' comparison is not working
175 //return this._children.remove(child);
180 // TODO - this is much more inefficient!!!
181 Iterator liter
= this._children
.iterator();
183 while(liter
.hasNext()) {
185 eachbob
= (IBob
)liter
.next();
186 if(child
.equals(eachbob
)) {
194 public boolean remove(String tagName
, String attName
, String attValue
) {
197 logger
.debug("remove 1 / tname["+ tagName
+"] / attName["+ attName
+"] / attValue["+ attValue
+"]");
199 Iterator iter
= this.getChildren().iterator();
202 boolean matchFound
= false;
204 //** only loop if there's children
205 while(iter
.hasNext()) {
207 eachBob
= (IBob
)iter
.next();
208 boolean mfound
= eachBob
.remove(tagName
, attName
, attValue
);
213 logger
.debug(" 2 EACH / tname["+ eachBob
.getTagName() +"] / attName["+ attName
+"] / attValue["+ eachBob
.getAttributeValue(attName
) +"] / MATCH["+ (eachBob
.getTagName().equals( tagName
) && eachBob
.getAttributeValue(attName
).equals(attValue
)) +"]");
214 if( eachBob
.getTagName().equals( tagName
) &&
215 eachBob
.getAttributeValue(attName
).equals(attValue
) ) {
219 logger
.debug("MATCH FOUND!! / tname["+ tagName
+"] / attName["+ attName
+"] / attValue["+ attValue
+"]");
220 logger
.debug("Bob.logger.debugg ["+ eachBob
+"] ");
230 public boolean remove(String tagName
, String tagId
) {
232 return this.remove(tagName
, "id", tagId
);
236 public List
allGenChildren() {
237 return new ArrayList(_genchildren
);
239 public void addGenChild(IBob child
) {
240 this._genchildren
.add(child
);
242 public void removeAllGenChildren() {
243 this._genchildren
.clear();
245 public boolean removeGenChild(IBob child
) {
248 // can't do this as an 'equals' comparison is not working
249 //return this._genchildren.remove(child);
251 // TODO - this is much more inefficient!!!
252 Iterator liter
= this._genchildren
.iterator();
254 while(liter
.hasNext()) {
256 eachbob
= (IBob
)liter
.next();
257 if(child
.equals(eachbob
)) {
269 public IBob
find(String tagName
, String tagId
) {
271 DepthFindVisitor dfVisitor
= new DepthFindVisitor();
272 dfVisitor
.setTagName(tagName
);
273 dfVisitor
.setId(tagId
);
275 this.accept(dfVisitor
);
276 return dfVisitor
.getResult();
279 public List
find(String xpath
) {
282 // throw new RuntimeException("XPath 2.0 evaluation not yet implemented");
284 ByteArrayInputStream baInputStream
= new ByteArrayInputStream( xpath
.getBytes() );
285 PushbackReader pbreader
=
286 new PushbackReader( new InputStreamReader(baInputStream
), 1024 );
288 List xdmResults
= new ArrayList();
289 DepthFirstVisitor rdvisitor
= new DepthFirstVisitor();
290 rdvisitor
.setDocument(this);
292 System
.out
.println("xpath > start");
295 //** parse the syntax and provide the MODEL
296 Lexer lexer
= new Lexer(pbreader
);
297 Parser parser
= new Parser(lexer
);
299 System
.out
.println("xpath > parsing input");
302 Start tree
= parser
.parse();
304 System
.out
.println("");
305 System
.out
.println("xpath > running analyser");
308 tree
.apply(rdvisitor
);
309 xdmResults
= rdvisitor
.getXdmList();
311 System
.out
.println("xpath > finished");
314 catch(java
.io
.IOException e
) {
317 catch(LexerException e
) {
320 catch(ParserException e
) {
329 public String
xpath() {
334 public String
xpath(boolean relative
) {
336 StringBuilder sbuffer
= new StringBuilder();
338 // get parent axis string
341 IBob parent
= this.getParent();
342 while(parent
!= null) {
344 sbuffer
.insert(0, "/");
345 sbuffer
.insert(0, parent
.buildAxisString());
346 parent
= parent
.getParent();
348 sbuffer
.insert(0, "/");
351 // append the axis string
352 sbuffer
.append(this.buildAxisString());
353 return sbuffer
.toString();
357 public String
buildAxisString() {
359 // take node name & append predicates
360 String axisString
= this.getTagName() + this.buildPredicateString(this.getAttributes());
363 public String
buildPredicateString(Attributes attributes
) {
365 // construct predicate based on attributes. should look something like...
366 // [ @attr='value' and @attr='value' ]
368 StringBuilder pbuffer
= new StringBuilder();
369 pbuffer
.append("[ ");
370 for(int i
= 0; i
< attributes
.getLength(); i
++) {
372 String avalue
= attributes
.getValue(i
).trim();
375 String aname
= attributes
.getLocalName(i
);
377 pbuffer
.append(aname
);
380 pbuffer
.append(avalue
);
383 if(i
< (attributes
.getLength() - 1)) {
385 pbuffer
.append(" and ");
389 pbuffer
.append(" ]");
391 return pbuffer
.toString();
395 public void replace(IBob replacor
) {
397 // the parent should stay the same
398 IBob parent
= this.getParent();
400 replacor
.setParent(parent
);
401 if( parent
!= null ) {
402 parent
.removeChild(this);
403 parent
.addChild(replacor
);
408 * ** a weakness of this method is that it cannot replace itself
410 public boolean replace(String tagName
, String tagId
, IBob replacor
) {
412 logger
.debug("Bob.replace["+ tagName
+"] / tagId["+ tagId
+"] / replacor["+ replacor
.getClass() +"]");
413 Iterator iter
= this.getChildren().iterator();
416 boolean matchFound
= false;
418 //** only loop if there's children
419 while(iter
.hasNext()) {
421 eachBob
= (IBob
)iter
.next();
422 boolean mfound
= eachBob
.replace(tagName
, tagId
, replacor
);
427 logger
.debug("Bob.replace 2 / logger.debugteValue(id)["+ eachBob
.getAttributeValue("id") +"] / MATCH["+ (eachBob
.getTagName().equals( tagName
) &&
428 eachBob
.getAttributeValue("id").equals( tagId
)) +"]");
430 if( eachBob
.getTagName().equals( tagName
) &&
431 eachBob
.getAttributeValue("id").equals( tagId
) ) {
433 //logger.debug("Bob.replace 3");
436 //logger.debug("Bob.replace 2 / MATCH FOUND!logger.debugme +"] / id["+ tagId +"]");
437 //logger.debug("Bob.replace 3 / replacing["+ eachBob +"]");
445 this.addChild(replacor
);
452 public IBob
getRoot() {
454 if(this._parent
!= null) {
455 return this._parent
.getRoot();
460 /*public IBob searchTree(String tag, String attributeName, String attributeValue) {
462 return this.getRoot().search(tag, attributeName, attributeValue);
467 public void accept(IVisitor visitor
) throws BobException
{
470 //logger.debug("Bob.accept: tag["+this.getTagName()+"] / children.size["+_children.size()+"]");
471 Iterator iter
= _children
.iterator();
473 while(iter
.hasNext()) {
476 next
= (IBob
)iter
.next();
480 logger
.debug("Cause: "+ e
.getCause());
481 logger
.debug("Message: "+ e
.getMessage());
482 e
.printStackTrace(System
.out
);
483 //logger.debug("Bob.accept: next["+next+"]");
484 //logger.debug("Bob.accept: children["+_children+"] / children.size["+_children.size()+"] / iterator["+_children.iterator()+"]");
485 throw new BobException(e
);
488 next
.accept(visitor
);
492 public void acceptFirst(IVisitor visitor
) throws BobException
{
496 Iterator iter
= _children
.iterator();
498 while(iter
.hasNext()) {
500 next
= (IBob
)iter
.next();
501 next
.acceptFirst(visitor
);
504 public void acceptSax(ISaxVisitor visitor
) throws BobException
{
506 visitor
.visitStart(this);
508 Iterator iter
= _children
.iterator();
510 while(iter
.hasNext()) {
512 next
= (IBob
)iter
.next();
513 next
.acceptSax(visitor
);
515 visitor
.visitEnd(this);
519 /* some methods to pull through the entire tree of objects
521 private Stack _pullStack
= null;
522 public IBob
pullNext() {
524 if(this._pullStack
== null) {
527 if(this._pullStack
.empty()) {
530 return (IBob
)this._pullStack
.pop();
532 public boolean canPull() {
534 if(this._pullStack
== null) {
537 if(this._pullStack
.empty()) {
540 return !this._pullStack
.empty();
542 public void resetPull() {
544 class PullVisitor
implements IVisitor
{
546 private Stack pullStack
= new Stack();
547 public void setStack(Stack stack
) {
548 this.pullStack
= stack
;
550 public Stack
getStack() {
551 return this.pullStack
;
554 public void visit(IBob bob
) {
556 this.pullStack
.push(bob
);
560 PullVisitor pvisitor
= new PullVisitor();
561 this.accept(pvisitor
);
563 this._pullStack
= pvisitor
.getStack();
568 /* search the tree for the first IBob node with this
570 public IBob
search( String tag
, String attributeName
, String attributeValue
) {
573 SearchVisitor svisitor
= new SearchVisitor();
574 svisitor
.setTagName(tag
);
575 svisitor
.setAttributeName(attributeName
);
576 svisitor
.setAttributeValue(attributeValue
);
578 this.accept(svisitor
);
579 return svisitor
.getResult();
587 public void toXML(java
.io
.PrintStream ps
) {
590 public void toXML(boolean inlineNS
, java
.io
.PrintStream ps
) {
591 ps
.print(toXML(inlineNS
));
594 public String
toXML() {
595 return this.toXML(true);
597 public String
toXML(boolean inlineNS
) {
599 //** clear XML String
600 ToXMLVisitorEraser veraser
= new ToXMLVisitorEraser();
601 this.accept(veraser
);
603 //** compose XML String
604 ToXMLVisitorPass1 txVisitor1
= new ToXMLVisitorPass1();
605 txVisitor1
.setInlineNS(inlineNS
);
607 String depth_s
= this.getProperty(IBob
.XML_DEPTH
);
608 if((depth_s
!= null) && (depth_s
.length() > 0)) {
609 int depth
= Integer
.parseInt(depth_s
);
610 txVisitor1
.setDepth(depth
);
612 ToXMLVisitorPass2 txVisitor2
= new ToXMLVisitorPass2();
614 this.acceptSax(txVisitor1
);
615 this.acceptSax(txVisitor2
);
616 return txVisitor2
.getXML();
623 public void setNamespace(String namespaceURI
) {
624 _namespaceURI
= namespaceURI
;
626 public String
getNamespace() {
627 return _namespaceURI
;
629 public void addNamespace(String ns
, String value
) {
630 _namespaceMap
.put(ns
,value
);
632 public String
getNamespace(String ns
) {
633 return (String
)_namespaceMap
.get(ns
);
635 public HashMap
getNamespaces() {
636 return new HashMap(_namespaceMap
);
638 public boolean hasNamespaces() {
639 return !_namespaceMap
.isEmpty();
643 /* namespace preix mappings
645 public void setPrefixMappings(HashMap prefixMappings
) {
646 this._nsPrefixMappings
= prefixMappings
;
648 public HashMap
getPrefixMappings() {
649 return this._nsPrefixMappings
;
653 /* attribute accessors
655 public void setTagName(String localName
) {
658 public String
getTagName() {
662 //public void setQName(String qName) {
665 public String
getQName() {
667 if(this._namespaceURI
!= null) {
669 StringBuilder temp
= new StringBuilder();
670 if(!this._namespaceURI
.equals("")) {
671 temp
.append(this._namespaceURI
);
674 temp
.append(this._name
);
675 return temp
.toString();
680 public void setAttributes(Attributes attribs
) {
681 _attributes
= attribs
;
683 public Attributes
getAttributes() {
687 public String
getAttributeValue(String aname
) {
688 return _attributes
.getValue(aname
);
690 public void setAttributeValue(String aname
, String avalue
) {
692 ((AttributesImpl
)_attributes
).setValue(_attributes
.getIndex(aname
), avalue
);
695 public void setContent(String text
) {
698 public String
getContent() {
704 public IBob
getChild(int cindex
) {
705 return (IBob
)_children
.get(cindex
);
707 public List
getChildren() {
710 public void setChildren(List _children
) {
711 this._children
= _children
;
715 public void _setOpenString(String os
) {
718 public String
_getOpenString() {
721 public void _setCloseString(String cs
) {
724 public String
_getCloseString() {
733 public static IBob
make(String namespace
, String localName
) {
736 Logger logger
= Logger
.getLogger(Bob
.class);
737 logger
.debug("Bob:: make / namespace["+namespace
+"] / localname["+localName
+"]");
739 /* TODO *** KLUDGE *** CLASS CREATION
740 * - there should be a 'createGName' / 'createIName'
742 String ns
= StringUtil
.namespaceToPackage(namespace
);
743 String cname
= StringUtil
.upperFirstLetter(localName
);
744 logger
.debug("1. Bob:: make / classname["+ ns
+ "." + cname
+"]");
746 Class bobClass
= null;
750 if(ns
.trim().length() > 0) {
752 bobClass
= Class
.forName( ns
+ "." + cname
);
756 bobClass
= Class
.forName( cname
);
758 //logger.debug("D. Bob:: make / class["+ bobClass +"]");
760 catch(ClassNotFoundException e
) {
762 //e.printStackTrace();
765 logger
.debug("2. Bob:: make / classname["+ ns
+ "." + "G" + cname
+"]");
766 if(ns
.length() > 0) {
768 bobClass
= Class
.forName( ns
+ "." + "G" + cname
);
771 bobClass
= Class
.forName( "G" + cname
);
774 catch(ClassNotFoundException ex
) {
775 ex
.printStackTrace();
786 result
= (IBob
)bobClass
.newInstance();
787 result
.setNamespace( namespace
);
789 //logger.debug("G: "+ result);
792 catch(InstantiationException e
) {
795 catch(IllegalAccessException e
) {
798 logger
.debug("3. Bob:: generated class["+ result
+"]");
805 public static IBob
make( String fqclassname
) {
808 Class bobClass
= null;
811 //logger.debug("make / fqclassname["+fqclassname+"]");
812 bobClass
= Class
.forName( fqclassname
);
815 catch(ClassNotFoundException e
) {
822 String package_s
= fqclassname
.substring( 0, fqclassname
.lastIndexOf(".") );
823 String namespace
= StringUtil
.packageToNamespace( package_s
);
826 result
= (IBob
)bobClass
.newInstance();
827 result
.setNamespace( namespace
);
829 catch(InstantiationException e
) {
832 catch(IllegalAccessException e
) {
841 public static IBob
loadS(String xmlString
) {
843 String def_s
= System
.getProperties().getProperty(Util
.DEF
);
844 return Bob
.loadS( xmlString
, def_s
);
846 public static IBob
loadS(String xmlString
, String definitionFiles
) {
849 Logger
.getLogger(Bob
.class).debug("Bob.load("+xmlString
+", "+definitionFiles
+")");
852 ByteArrayInputStream bs
= null;
854 bs
= new ByteArrayInputStream(xmlString
.getBytes("UTF-8"));
856 catch(java
.io
.UnsupportedEncodingException e
) {
859 return Bob
.loadS( bs
, definitionFiles
);
864 public static IBob
loadS(File xmlFile
) {
866 java
.io
.FileInputStream fis
= null;
868 fis
= new java
.io
.FileInputStream(xmlFile
);
870 catch(java
.io
.FileNotFoundException e
) {
871 Logger
.getLogger(Bob
.class).error(e
,e
);
873 return Bob
._loadS( fis
);
875 public static IBob
loadS(File xmlFile
, String definitionFiles
) {
877 java
.io
.FileInputStream fis
= null;
879 fis
= new java
.io
.FileInputStream(xmlFile
);
881 catch(java
.io
.FileNotFoundException e
) {
882 Logger
.getLogger(Bob
.class).error(e
,e
);
884 return Bob
._loadS( fis
, definitionFiles
);
889 public static IBob
loadS(InputStream xmlis
) {
890 return Bob
._loadS( xmlis
);
892 public static IBob
loadS(InputStream xmlis
, String definitionFiles
) {
893 return Bob
._loadS( xmlis
, definitionFiles
);
898 private static IBob
_loadS( Object inputSource
) {
900 String def_s
= System
.getProperties().getProperty(Util
.DEF
);
901 return Bob
._loadS( inputSource
, def_s
);
904 private static IBob
_loadS( Object inputSource
, String definitionFiles
) {
906 Logger
.getLogger(Bob
.class).debug( "Bob._load("+inputSource
+", "+definitionFiles
+")" );
909 if( definitionFiles
== null || definitionFiles
.trim().length() < 1 ) {
910 Logger
.getLogger(Bob
.class).error("ERROR. definition files not specified for [_loadS( Object inputSource, String definitionFiles )]. Stopping.");
914 // create a BobHandler and its Listener
915 class LoadHandler
implements com
.interrupt
.bob
.DocumentHandler
{
917 private Logger logger
= Logger
.getLogger(Bob
.class);
918 private IBob bobToChange
= null;
919 public void endHandle(com
.interrupt
.callback
.CallbackEvent cevent
) {
921 Object result
= cevent
.getMessage();
922 if( result
instanceof IBob
) {
924 Bob rootBob
= (Bob
)result
;
925 logger
.debug("LoadHandler.endHandle / bobResult / ["+ rootBob
.toXML() +"]");
926 bobToChange
= (IBob
)rootBob
.allChildren().get(0);
931 public IBob
getBobToChange() {
934 public void setBobToChange(IBob bob
) {
939 LoadHandler lhandler
= new LoadHandler();
940 lhandler
.setBobToChange(new Bob());
942 com
.interrupt
.bob
.handler
.DocumentHandler definitionHandler
= new com
.interrupt
.bob
.handler
.DefinitionHandler();
943 definitionHandler
.setNamespace("com.interrupt.bob.handler");
944 definitionHandler
.setType("com.interrupt.bob.handler.DefinitionHandler");
945 definitionHandler
.setFiles(definitionFiles
);
946 definitionHandler
.setOut("definition.list");
949 com
.interrupt
.bob
.handler
.IHandlerField handlerField
= new com
.interrupt
.bob
.handler
.HandlerField();
950 handlerField
.setName("tagList");
951 handlerField
.setValue("${definition.list}");
953 com
.interrupt
.bob
.handler
.DocumentHandler bobHandler
= new com
.interrupt
.bob
.handler
.BobHandler();
954 bobHandler
.setNamespace("com.interrupt.bob.handler");
955 bobHandler
.setType("com.interrupt.bob.handler.BobHandler");
956 bobHandler
.setFiles("${bob.files}");
957 bobHandler
.setOut("bob.tree");
958 bobHandler
.addHandlerField(handlerField
);
959 bobHandler
.addListener(lhandler
);
961 com
.interrupt
.bob
.core
.Queue queue
= new com
.interrupt
.bob
.core
.Queue();
962 queue
.addDocumentHandler(definitionHandler
);
963 queue
.addDocumentHandler(bobHandler
);
966 MemoryField mfield
= new MemoryField();
967 mfield
.setName("bob.files");
968 mfield
.setValue(inputSource
);
969 queue
.getMemory().addMemoryField(mfield
);
972 Logger
.getLogger(Bob
.class).debug("BEGIN execute");
974 Logger
.getLogger(Bob
.class).debug("END execute");
977 catch(ProcessorException e
) {
978 e
.printStackTrace(System
.out
);
982 return lhandler
.getBobToChange();
987 public IBob
load(String xmlString
) { return Bob
.loadS(xmlString
); }
988 public IBob
load(String xmlString
, String definitionFiles
) { return Bob
.loadS(xmlString
, definitionFiles
); }
990 public IBob
load(File xmlFile
) { return Bob
.loadS(xmlFile
); }
991 public IBob
load(File xmlFile
, String definitionFiles
) { return Bob
.loadS(xmlFile
, definitionFiles
); }
993 public IBob
load(InputStream xmlis
) { return Bob
.loadS(xmlis
); }
994 public IBob
load(InputStream xmlis
, String definitionFiles
) { return Bob
.loadS(xmlis
, definitionFiles
); }
997 public boolean equals(Object bob
) {
999 if( !(bob
instanceof IBob
) ) {
1001 //object for comparison is not an instance of 'IBob'
1004 IBob ibob
= (IBob
)bob
;
1006 // the specific XML structure must match
1007 //return super.equals(bob);
1008 String thisXML
= this.toXML();
1009 String bobXML
= ibob
.toXML();
1011 return thisXML
.equals(bobXML
);
1015 public int hashCode() {
1017 /*String xmls = this.toXML(false);
1018 int intValue = this..intValue();
1019 return intValue * 178345;
1024 public String
toString() {
1026 return this.toXML(false);
1030 public static void main(String args
[]) {
1032 System
.getProperties().setProperty(Util
.BASE
, ".");
1033 System
.getProperties().setProperty(Util
.END
, ".xml");
1034 System
.getProperties().setProperty(Util
.DEF
, "xml");
1036 IBob bobby
= new Bob();
1037 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");
1038 bkeeping
.setProperty(IBob
.XML_DEPTH
, "1");
1040 System
.out
.println("bkeeping["+ bkeeping
.toXML(false) +"]");
1043 class XOutput
implements IVisitor
{
1045 public void visit(IBob bob
) {
1046 System
.out
.println("");
1047 System
.out
.println("Visiting ["+ bob
.getTagName() +"]");
1048 System
.out
.println(bob
.xpath(false));
1051 XOutput xout
= new XOutput();
1054 //** basic xpath expression with predicate
1055 //List result = bkeeping.find("/bookkeeping[ @id=' ' ]");
1056 //[ok] List result = bkeeping.find("/bookkeeping");
1057 //[ok] List result = bkeeping.find("/");
1060 //** multiple predicates (implicit 'and')
1061 //[ok] List result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @zzz='timmy' ] [ @id='j1' or @name='generalledger' or @type='' or @balance='' ]");
1062 //** List result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='j1' or @name='generalledger' or @type='' ] [ @balance='' ]");
1065 //** predicates with and/or conditions
1066 //[ok] List result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='xxx' or @name='xxx' or @type='xxx' or @balance='xxx' ]");
1067 //[ok] List result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='j1' and @name='generalledger' and @type='notthere' and @balance='' ]");
1068 //[ok] List result = bkeeping.find("/bookkeeping[ @id='' ]/journals[ @id='' ]/journal[ @id='j1' or @name='generalledger' and @type='' or @balance='' ]");
1071 //** System.out.println("\n\n\nFind RESULTS...");
1072 //** System.out.println(result);
1074 // needs to return an XDM 1. Bob, text, sequence, etc