1 22 23 package org.xquark.xquery.parser.primitivefunctions.fnfunctions; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.xquery.parser.*; 28 import org.xquark.xquery.typing.TypeException; 29 30 public class FunctionCOLLECTION extends InputFunctionCall { 31 32 private static final String RCSRevision = "$Revision: 1.8 $"; 33 private static final String RCSName = "$Name: $"; 34 35 private final static String STAR = "*"; 36 private ArrayList sources = new ArrayList (1); 37 private String collectionName = STAR; 38 39 43 public void accept(ParserVisitor visitor) throws XQueryException { 44 visitor.visit(this); 45 } 46 47 51 public FunctionCOLLECTION(ArrayList args, XQueryModule parentModule) throws TypeException, XQueryException { 52 super(new QName("collection",null),null); 53 if (args == null) 54 args = new ArrayList (1); 55 if (args.size() == 0) { 56 args.add(new ValueString("*:*",parentModule)); 57 } 58 setArguments(args); 59 setParentModule(parentModule); 60 if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null) 61 accept(parentModule.getStaticContext().getTypeVisitor()); 62 } 63 64 public void setArguments(ArrayList arguments) throws XQueryException { 65 71 if (arguments == null || arguments.size() == 0) { 72 return; 73 } else if (arguments.size() == 1) { 74 for (int i=0;i<arguments.size();i++) { 75 ValueString valStr = null; 76 try { 77 valStr = (ValueString)arguments.get(i); 78 } 79 catch (ClassCastException e) { 80 throw new XQueryException("Argument of collection function must be a literal string"); 81 } 82 String arg = valStr.getValue(); 83 int colonIndex = -1; 85 int startIndex = 0; 86 while ((colonIndex = arg.indexOf(":",startIndex)) != -1) { 87 sources.add(arg.substring(startIndex,colonIndex)); 88 startIndex = colonIndex+1; 89 } 90 collectionName = arg.substring(startIndex); 91 if (sources.isEmpty()) { 92 sources.add(STAR); 93 valStr.setValue("*:"+arg); 94 } 95 } 96 } 97 else { 98 throw new XQueryException("Function collection should have at most one argument"); 99 } 100 super.setArguments(arguments); 101 } 102 103 public String getCollectionName() { 104 return collectionName; 105 } 106 public String getSourceName() { 107 return (String )sources.get(0); 108 } 109 public void eraseSourceName() throws XQueryException { 110 sources.remove(0); 111 if (sources.isEmpty()) { 112 sources.add(STAR); 113 } 114 StringBuffer buf = new StringBuffer (); 115 for (int i=0;i<sources.size();i++) { 116 buf.append(sources.get(i)); 117 buf.append(":"); 118 } 119 buf.append(collectionName); 120 ((ValueString)arguments.get(0)).setValue(buf.toString()); 121 } 122 123 } 124 | Popular Tags |