class PathTemplateFilter {

   public static PathTemplateFilter parse(List<String> attributes) throws ParseException
   {
      if (attributes == null || attributes.isEmpty())
      {
         return NO_OP_FILTER;
      }

      Builder builder = null;
      for (String attribute : attributes)
      {
         for (String attr : PathAddress.split(attribute, ";"))
         {
            Matcher matcher = PATH_TEMPLATE_PATTERN.matcher(attr);
            if (matcher.matches())
            {
               String pathTemplate = matcher.group(1);
               if (builder == null)
               {
                  builder = create(pathTemplate);
               }
               else
               {
                  builder.and(pathTemplate);
               }

               boolean exclusion = (matcher.group(2) != null);
               List<String> expressions = PathAddress.split(matcher.group(3), ",");
               for (String expression : expressions)
               {
                  boolean wildcard = WILDCARD.equals(expression);
                  if (exclusion)
                  {
                     if (wildcard)
                     {
                        builder.excludeAll();
                     }
                     else
                     {
                        builder.exclude(expression);
                     }
                  }
                  else
                  {
                     if (wildcard)
                     {
                        builder.includeAll();
                     }
                     else
                     {
                        builder.include(expression);
                     }
                  }
               }
            }
            else
            {
               throw new ParseException("Filter attribute '" + attribute + "' is not valid.", 0);
            }
         }
      }

      return (builder == null) ? NO_OP_FILTER : builder.build();
   }

}