예제 #1
0
 /// <summary>Find "missing attribute" and "cardinality mismatch" errors.
 /// Excecuted before a template writes its chunks out.
 /// When you find a problem, throw an IllegalArgumentException.
 /// We must check the attributes as well as the incoming arguments
 /// in argumentContext.
 /// protected void checkAttributesAgainstFormalArguments() {
 /// Set args = formalArguments.keySet();
 /// /*
 /// if ( (attributes==null||attributes.size()==0) &&
 /// (argumentContext==null||argumentContext.size()==0) &&
 /// formalArguments.size()!=0 )
 /// {
 /// throw new IllegalArgumentException("missing argument(s): "+args+" in template "+getName());
 /// }
 /// Iterator iter = args.iterator();
 /// while ( iter.hasNext() ) {
 /// String argName = (String)iter.next();
 /// FormalArgument arg = getFormalArgument(argName);
 /// int expectedCardinality = arg.getCardinality();
 /// Object value = getAttribute(argName);
 /// int actualCardinality = getActualArgumentCardinality(value);
 /// // if intersection of expected and actual is empty, mismatch
 /// if ( (expectedCardinality&actualCardinality)==0 ) {
 /// throw new IllegalArgumentException("cardinality mismatch: "+
 /// argName+"; expected "+
 /// FormalArgument.getCardinalityName(expectedCardinality)+
 /// " found cardinality="+getObjectLength(value));
 /// }
 /// }
 /// }
 /// </summary>
 /// <summary>A reference to an attribute with no value, must be compared against
 /// the formal parameter to see if it exists; if it exists all is well,
 /// but if not, throw an exception.
 /// 
 /// Don't do the check if no formal parameters exist for this template;
 /// ask enclosing.
 /// </summary>
 protected internal virtual void checkNullAttributeAgainstFormalArguments(StringTemplate self, String attribute)
 {
     if (self.getFormArguments() == FormalArgument.UNKNOWN)
     {
         // bypass unknown arg lists
         if (self.enclosingInstance != null)
         {
             checkNullAttributeAgainstFormalArguments(self.enclosingInstance, attribute);
         }
         return ;
     }
     FormalArgument formalArg = lookupFormalArgument(attribute);
     if (formalArg == null)
     {
         throw new ArgumentOutOfRangeException("attribute", "no such attribute: " + attribute);
     }
 }