コード例 #1
0
 private FilterDirective[] buildFilterDirectives(Element element) throws Exception {
   if (null == element) {
     return new FilterDirective[0];
   } else {
     Element[] children = ElementHelper.getChildren(element);
     FilterDirective[] filters = new FilterDirective[children.length];
     for (int i = 0; i < children.length; i++) {
       Element child = children[i];
       String token = ElementHelper.getAttribute(child, "token");
       if ("filter".equals(child.getTagName())) {
         String value = ElementHelper.getAttribute(child, "value");
         filters[i] = new SimpleFilterDirective(token, value);
       } else if ("feature".equals(child.getTagName())) {
         String id = ElementHelper.getAttribute(child, "id").toUpperCase();
         Feature feature = Feature.valueOf(id);
         String ref = ElementHelper.getAttribute(child, "ref");
         String type = ElementHelper.getAttribute(child, "type");
         boolean alias = ElementHelper.getBooleanAttribute(child, "alias");
         filters[i] = new FeatureFilterDirective(token, ref, feature, type, alias);
       } else {
         final String error =
             "Element name not recognized [" + child.getTagName() + "] (expecting 'filter').";
         throw new DecodingException(error, null, element);
       }
     }
     return filters;
   }
 }