Coverage Report - org.mule.config.spring.parsers.processors.BlockAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
BlockAttribute
0%
0/12
0%
0/4
1.75
BlockAttribute$1
N/A
N/A
1.75
BlockAttribute$BlockAttributeException
0%
0/3
N/A
1.75
 
 1  
 /*
 2  
  * $Id: BlockAttribute.java 10256 2008-01-08 15:20:25Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config.spring.parsers.processors;
 12  
 
 13  
 import org.mule.config.spring.parsers.PreProcessor;
 14  
 import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
 15  
 import org.mule.config.spring.util.SpringXMLUtils;
 16  
 
 17  
 import java.util.Arrays;
 18  
 import java.util.HashSet;
 19  
 import java.util.Set;
 20  
 
 21  
 import org.w3c.dom.Attr;
 22  
 import org.w3c.dom.Element;
 23  
 import org.w3c.dom.NamedNodeMap;
 24  
 
 25  
 /**
 26  
  * Throws an exception if any of the disallowed attributes (after translation) is present.
 27  
  * Designed to cooperates with
 28  
  * {@link org.mule.config.spring.parsers.delegate.AbstractSerialDelegatingDefinitionParser#addHandledException(Class)}
 29  
  */
 30  
 public class BlockAttribute implements PreProcessor
 31  
 {
 32  
 
 33  
     private Set disallowed;
 34  
 
 35  
     public BlockAttribute(String disallowed)
 36  
     {
 37  0
         this(new String[]{disallowed});
 38  0
     }
 39  
 
 40  
     public BlockAttribute(String[] disallowed)
 41  0
     {
 42  0
         this.disallowed = new HashSet(Arrays.asList(disallowed));
 43  0
     }
 44  
 
 45  
     public void preProcess(PropertyConfiguration config, Element element)
 46  
     {
 47  0
         NamedNodeMap attributes = element.getAttributes();
 48  0
         for (int i = 0; i < attributes.getLength(); i++)
 49  
         {
 50  0
             String alias = SpringXMLUtils.attributeName((Attr) attributes.item(i));
 51  0
             String name = config.translateName(alias);
 52  0
             if (disallowed.contains(name))
 53  
             {
 54  0
                 throw new BlockAttributeException("Attribute " + alias + " is not allowed here.");
 55  
             }
 56  
         }
 57  0
     }
 58  
 
 59  0
     public static class BlockAttributeException extends IllegalStateException
 60  
     {
 61  
 
 62  
         private BlockAttributeException(String message)
 63  
         {
 64  0
             super(message);
 65  0
         }
 66  
 
 67  
     }
 68  
 
 69  
 }