Coverage Report - org.simpleframework.xml.core.Qualifier
 
Classes in this File Line Coverage Branch Coverage Complexity
Qualifier
90%
19/21
50%
3/6
1.5
 
 1  
 /*
 2  
  * Qualifier.java July 2008
 3  
  *
 4  
  * Copyright (C) 2008, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.core;
 20  
 
 21  
 import org.simpleframework.xml.Namespace;
 22  
 import org.simpleframework.xml.NamespaceList;
 23  
 import org.simpleframework.xml.stream.OutputNode;
 24  
 
 25  
 /**
 26  
  * The <code>Qualifier</code> object is used to provide decorations
 27  
  * to an output node for namespaces. This will scan a provided
 28  
  * contact object for namespace annotations. If any are found they
 29  
  * can then be used to apply these namespaces to the provided node.
 30  
  * The <code>Contact</code> objects can represent fields or methods
 31  
  * that have been annotated with XML annotations.
 32  
  * 
 33  
  * @author Niall Gallagher
 34  
  */
 35  
 class Qualifier implements Decorator {
 36  
 
 37  
    /**
 38  
     * This is the namespace decorator that is populated for use.
 39  
     */
 40  
    private NamespaceDecorator decorator;
 41  
    
 42  
    /**
 43  
     * Constructor for the <code>Qualifier</code> object. This is
 44  
     * used to create a decorator that will scan the provided
 45  
     * contact for <code>Namespace</code> annotations. These can
 46  
     * then be applied to the output node to provide qualification.
 47  
     * 
 48  
     * @param contact this is the contact to be scanned 
 49  
     */
 50  5914
    public Qualifier(Contact contact) {
 51  5914
       this.decorator = new NamespaceDecorator();
 52  5914
       this.scan(contact);
 53  5914
    }
 54  
 
 55  
    /**
 56  
     * This method is used to decorate the provided node. This node 
 57  
     * can be either an XML element or an attribute. Decorations that
 58  
     * can be applied to the node by invoking this method include
 59  
     * things like namespaces and namespace lists.
 60  
     * 
 61  
     * @param node this is the node that is to be decorated by this
 62  
     */
 63  
    public void decorate(OutputNode node) {
 64  208849
       decorator.decorate(node);
 65  208849
    }
 66  
 
 67  
    /**
 68  
     * This method is used to decorate the provided node. This node 
 69  
     * can be either an XML element or an attribute. Decorations that
 70  
     * can be applied to the node by invoking this method include
 71  
     * things like namespaces and namespace lists. This can also be 
 72  
     * given another <code>Decorator</code> which is applied before 
 73  
     * this decorator, any common data can then be overwritten.
 74  
     * 
 75  
     * @param node this is the node that is to be decorated by this
 76  
     * @param secondary this is a secondary decorator to be applied
 77  
     */
 78  
    public void decorate(OutputNode node, Decorator secondary) {
 79  419698
       decorator.decorate(node, secondary);
 80  419698
    }
 81  
    
 82  
    /**
 83  
     * This method is used to scan the <code>Contact</code> provided
 84  
     * to determine if there are any namespace annotations. If there
 85  
     * are any annotations then these are added to the internal
 86  
     * namespace decorator. This ensues that they can be applied to
 87  
     * the node when that node requests decoration.
 88  
     * 
 89  
     * @param contact this is the contact to be scanned for namespaces
 90  
     */
 91  
    private void scan(Contact contact) {
 92  5914
       namespace(contact);
 93  5914
       scope(contact);
 94  5914
    }
 95  
    
 96  
    /**
 97  
     * This is use to scan for <code>Namespace</code> annotations on
 98  
     * the contact. Once a namespace has been located then it is used
 99  
     * to populate the internal namespace decorator. This can then be
 100  
     * used to decorate any output node that requires it.
 101  
     * 
 102  
     * @param contact this is the contact to scan for namespaces
 103  
     */
 104  
    private void namespace(Contact contact) {
 105  5914
       Namespace primary = contact.getAnnotation(Namespace.class);
 106  
       
 107  5914
       if(primary != null) {
 108  297
          decorator.set(primary);
 109  297
          decorator.add(primary);
 110  
       }
 111  5914
    }
 112  
    
 113  
    /**
 114  
     * This is use to scan for <code>NamespaceList</code> annotations 
 115  
     * on the contact. Once a namespace list has been located then it is 
 116  
     * used to populate the internal namespace decorator. This can then 
 117  
     * be used to decorate any output node that requires it.
 118  
     * 
 119  
     * @param contact this is the contact to scan for namespace lists
 120  
     */
 121  
    private void scope(Contact contact) {
 122  5914
       NamespaceList scope = contact.getAnnotation(NamespaceList.class);
 123  
       
 124  5914
       if(scope != null) {
 125  0
          for(Namespace name : scope.value()) {
 126  0
             decorator.add(name);
 127  
          }
 128  
       }
 129  5914
    }
 130  
 }