Coverage Report - org.simpleframework.xml.core.PrimitiveScanner
 
Classes in this File Line Coverage Branch Coverage Complexity
PrimitiveScanner
76%
20/26
N/A
1
PrimitiveScanner$EmptySection
40%
6/15
N/A
1
 
 1  
 /*
 2  
  * PrimitiveScanner.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, 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 java.util.Iterator;
 22  
 import java.util.LinkedList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.simpleframework.xml.Order;
 26  
 import org.simpleframework.xml.Version;
 27  
 
 28  
 /**
 29  
  * The <code>PrimitiveScanner</code> performs the reflective inspection
 30  
  * of a class and builds a map of attributes and elements for each
 31  
  * annotated field. This acts as a cachable container for reflection
 32  
  * actions performed on a specific type. When scanning the provided
 33  
  * class this inserts the scanned field as a <code>Label</code> in to
 34  
  * a map so that it can be retrieved by name. Annotations classified
 35  
  * as attributes have the <code>Attribute</code> annotation, all other
 36  
  * annotated fields are stored as elements.
 37  
  * 
 38  
  * @author Niall Gallagher
 39  
  * 
 40  
  * @see org.simpleframework.xml.core.Schema
 41  
  */ 
 42  
 class PrimitiveScanner implements Scanner {
 43  
    
 44  
    /**
 45  
     * This is an empty section that is used by every scanner object.
 46  
     */
 47  
    private final Section section;
 48  
    
 49  
    /**
 50  
     * This contains the details for the class that is being scanned.
 51  
     */
 52  
    private final Detail detail;
 53  
    
 54  
    /**
 55  
     * Constructor for the <code>PrimitiveScanner</code> object. This 
 56  
     * is used to represent primitives or other types that do not have
 57  
     * and XML annotations present.      
 58  
     * 
 59  
     * @param detail this contains the details for the class scanned
 60  
     */
 61  1012
    public PrimitiveScanner(Detail detail) {
 62  1012
       this.section = new EmptySection(this);
 63  1012
       this.detail = detail;
 64  1012
    }
 65  
    
 66  
    /**
 67  
     * This is used to acquire the default signature for the class. 
 68  
     * The default signature is the signature for the no argument
 69  
     * constructor for the type. If there is no default constructor
 70  
     * for the type then this will return null.
 71  
     * 
 72  
     * @return this returns the default signature if it exists
 73  
     */
 74  
    public Signature getSignature() {
 75  0
       return null;
 76  
    }
 77  
    
 78  
    /**
 79  
     * This returns the signatures for the type. All constructors are
 80  
     * represented as a signature and returned. More signatures than
 81  
     * constructors will be returned if a constructor is annotated 
 82  
     * with a union annotation.
 83  
     *
 84  
     * @return this returns the list of signatures for the type
 85  
     */
 86  
    public List<Signature> getSignatures() {
 87  0
       return new LinkedList<Signature>();
 88  
    }
 89  
    
 90  
    /**
 91  
     * This returns a map of all parameters that exist. This is used
 92  
     * to validate all the parameters against the field and method
 93  
     * annotations that exist within the class. 
 94  
     * 
 95  
     * @return this returns a map of all parameters within the type
 96  
     */
 97  
    public ParameterMap getParameters() {
 98  0
       return new ParameterMap();
 99  
    }
 100  
    
 101  
    /**
 102  
     * This is used to acquire the instantiator for the type. This is
 103  
     * used to create object instances based on the constructors that
 104  
     * have been annotated. If no constructors have been annotated
 105  
     * then this can be used to create default no argument instances.
 106  
     * 
 107  
     * @return this instantiator responsible for creating instances
 108  
     */
 109  
    public Instantiator getInstantiator() {
 110  172
       return null;
 111  
    }
 112  
 
 113  
    /**
 114  
     * This is used to acquire the type that this scanner scans for
 115  
     * annotations to be used in a schema. Exposing the class that
 116  
     * this represents allows the schema it creates to be known.
 117  
     * 
 118  
     * @return this is the type that this creator will represent
 119  
     */
 120  
    public Class getType() {
 121  172
       return detail.getType();
 122  
    }
 123  
    
 124  
    /**
 125  
     * This is used to acquire the <code>Decorator</code> for this.
 126  
     * A decorator is an object that adds various details to the
 127  
     * node without changing the overall structure of the node. For
 128  
     * example comments and namespaces can be added to the node with
 129  
     * a decorator as they do not affect the deserialization.
 130  
     * 
 131  
     * @return this returns the decorator associated with this
 132  
     */
 133  
    public Decorator getDecorator() {
 134  316641
       return null;
 135  
    }
 136  
    
 137  
    /**
 138  
     * This method is used to return the <code>Caller</code> for this
 139  
     * class. The caller is a means to deliver invocations to the
 140  
     * object for the persister callback methods. It aggregates all of
 141  
     * the persister callback methods in to a single object.
 142  
     * 
 143  
     * @return this returns a caller used for delivering callbacks
 144  
     */
 145  
    public Caller getCaller(Context context) {
 146  316494
       return new Caller(this, context);
 147  
    }
 148  
 
 149  
    /**
 150  
     * This is used to create a <code>Section</code> given the context
 151  
     * used for serialization. A section is an XML structure that 
 152  
     * contains all the elements and attributes defined for the class.
 153  
     * Each section is a tree like structure defining exactly where
 154  
     * each attribute an element is located within the source XML.
 155  
     * 
 156  
     * @return this will return a section for serialization
 157  
     */
 158  
    public Section getSection() {
 159  172
       return section;
 160  
    }
 161  
    
 162  
    /**
 163  
     * This is the <code>Version</code> for the scanned class. It 
 164  
     * allows the deserialization process to be configured such that
 165  
     * if the version is different from the schema class none of
 166  
     * the fields and methods are required and unmatched elements
 167  
     * and attributes will be ignored.
 168  
     * 
 169  
     * @return this returns the version of the class that is scanned
 170  
     */
 171  
    public Version getRevision() {
 172  172
       return null;
 173  
    }
 174  
    
 175  
    /**
 176  
     * This is used to acquire the <code>Order</code> annotation for
 177  
     * the class schema. The order annotation defines the order that
 178  
     * the elements and attributes should appear within the document.
 179  
     * Providing order in this manner makes the resulting XML more
 180  
     * predictable. If no order is provided, appearance is random.
 181  
     * 
 182  
     * @return this returns the order, if any, defined for the class
 183  
     */
 184  
    public Order getOrder() {
 185  0
       return null;
 186  
    }
 187  
    
 188  
    /**
 189  
     * This returns the <code>Label</code> that represents the version
 190  
     * annotation for the scanned class. Only a single version can
 191  
     * exist within the class if more than one exists an exception is
 192  
     * thrown. This will read only floating point types such as double.
 193  
     * 
 194  
     * @return this returns the label used for reading the version
 195  
     */
 196  
    public Label getVersion() {
 197  172
       return null;
 198  
    }
 199  
    
 200  
    /**
 201  
     * This returns the <code>Label</code> that represents the text
 202  
     * annotation for the scanned class. Only a single text annotation
 203  
     * can be used per class, so this returns only a single label
 204  
     * rather than a <code>LabelMap</code> object. Also if this is
 205  
     * not null then the elements label map must be empty.
 206  
     * 
 207  
     * @return this returns the text label for the scanned class
 208  
     */
 209  
    public Label getText() {
 210  172
       return null;
 211  
    }
 212  
    
 213  
    /**
 214  
     * This returns the name of the class processed by this scanner.
 215  
     * The name is either the name as specified in the last found
 216  
     * <code>Root</code> annotation, or if a name was not specified
 217  
     * within the discovered root then the Java Bean class name of
 218  
     * the last class annotated with a root annotation.
 219  
     * 
 220  
     * @return this returns the name of the object being scanned
 221  
     */
 222  
    public String getName() {
 223  1190
       return null;
 224  
    }
 225  
 
 226  
    /**
 227  
     * This method is used to retrieve the schema class commit method
 228  
     * during the deserialization process. The commit method must be
 229  
     * marked with the <code>Commit</code> annotation so that when the
 230  
     * object is deserialized the persister has a chance to invoke the
 231  
     * method so that the object can build further data structures.
 232  
     * 
 233  
     * @return this returns the commit method for the schema class
 234  
     */
 235  
    public Function getCommit() {
 236  316494
       return null;
 237  
    }
 238  
 
 239  
    /**
 240  
     * This method is used to retrieve the schema class validation
 241  
     * method during the deserialization process. The validation method
 242  
     * must be marked with the <code>Validate</code> annotation so that
 243  
     * when the object is deserialized the persister has a chance to 
 244  
     * invoke that method so that object can validate its field values.
 245  
     * 
 246  
     * @return this returns the validate method for the schema class
 247  
     */   
 248  
    public Function getValidate() {
 249  316494
       return null;
 250  
    }
 251  
    
 252  
    /**
 253  
     * This method is used to retrieve the schema class persistence
 254  
     * method. This is invoked during the serialization process to
 255  
     * get the object a chance to perform an nessecary preparation
 256  
     * before the serialization of the object proceeds. The persist
 257  
     * method must be marked with the <code>Persist</code> annotation.
 258  
     * 
 259  
     * @return this returns the persist method for the schema class
 260  
     */
 261  
    public Function getPersist() {
 262  316494
       return null;
 263  
    }
 264  
 
 265  
    /**
 266  
     * This method is used to retrieve the schema class completion
 267  
     * method. This is invoked after the serialization process has
 268  
     * completed and gives the object a chance to restore its state
 269  
     * if the persist method required some alteration or locking.
 270  
     * This is marked with the <code>Complete</code> annotation.
 271  
     * 
 272  
     * @return returns the complete method for the schema class
 273  
     */   
 274  
    public Function getComplete() {
 275  316494
       return null;
 276  
    }
 277  
    
 278  
    /**
 279  
     * This method is used to retrieve the schema class replacement
 280  
     * method. The replacement method is used to substitute an object
 281  
     * that has been deserialized with another object. This allows
 282  
     * a seamless delegation mechanism to be implemented. This is
 283  
     * marked with the <code>Replace</code> annotation. 
 284  
     * 
 285  
     * @return returns the replace method for the schema class
 286  
     */
 287  
    public Function getReplace() {
 288  316494
       return null;
 289  
    }
 290  
    
 291  
    /**
 292  
     * This method is used to retrieve the schema class replacement
 293  
     * method. The replacement method is used to substitute an object
 294  
     * that has been deserialized with another object. This allows
 295  
     * a seamless delegation mechanism to be implemented. This is
 296  
     * marked with the <code>Replace</code> annotation. 
 297  
     * 
 298  
     * @return returns the replace method for the schema class
 299  
     */
 300  
    public Function getResolve() {
 301  316494
       return null;
 302  
    }
 303  
 
 304  
    /**
 305  
     * This is used to determine whether the scanned class represents
 306  
     * a primitive type. A primitive type is a type that contains no
 307  
     * XML annotations and so cannot be serialized with an XML form.
 308  
     * Instead primitives a serialized using transformations.
 309  
     * 
 310  
     * @return this returns true if no XML annotations were found
 311  
     */
 312  
    public boolean isPrimitive() {
 313  172
       return true;
 314  
    }
 315  
    
 316  
    /**
 317  
     * This is used to determine whether the scanned class represents
 318  
     * a primitive type. A primitive type is a type that contains no
 319  
     * XML annotations and so cannot be serialized with an XML form.
 320  
     * Instead primitives a serialized using transformations.
 321  
     * 
 322  
     * @return this returns true if no XML annotations were found
 323  
     */
 324  
    public boolean isEmpty() {
 325  0
       return true;
 326  
    }
 327  
    
 328  
    /**
 329  
     * This method is used to determine whether strict mappings are
 330  
     * required. Strict mapping means that all labels in the class
 331  
     * schema must match the XML elements and attributes in the
 332  
     * source XML document. When strict mapping is disabled, then
 333  
     * XML elements and attributes that do not exist in the schema
 334  
     * class will be ignored without breaking the parser.
 335  
     *
 336  
     * @return true if strict parsing is enabled, false otherwise
 337  
     */ 
 338  
    public boolean isStrict() {
 339  0
       return true;
 340  
    }
 341  
    
 342  
    /**
 343  
     * The <code>EmptySection</code> object creates a section for
 344  
     * used with primitives that has no values. No primitive can have
 345  
     * annotations as they will be processed by a transform rather
 346  
     * than by a schema object, this object saves memory and time.
 347  
     * 
 348  
     * @author Niall Gallagher
 349  
     */
 350  
    private static class EmptySection implements Section {
 351  
    
 352  
       /**
 353  
        * This is an empty list used to create empty iterators.
 354  
        */
 355  
       private final List<String> list;
 356  
       
 357  
       /**
 358  
        * This is the source scanner object this is created for.
 359  
        */
 360  
       private final Scanner scanner;
 361  
       
 362  
       /**
 363  
        * Constructor for the <code>EmptySection</code> object. This
 364  
        * is used to represent a primitive where thare are no other
 365  
        * parts to the object. This acts as a lightweight container.
 366  
        * 
 367  
        * @param scanner this is the owning scanner for the section
 368  
        */
 369  1012
       public EmptySection(Scanner scanner) {
 370  1012
          this.list = new LinkedList<String>();
 371  1012
          this.scanner = scanner;
 372  1012
       }
 373  
 
 374  
       /**
 375  
        * This will produce an interator with no elements. No elements
 376  
        * are returned because this represents an empty section. A
 377  
        * non-null value is best as it avoids possible exceptions.
 378  
        * 
 379  
        * @return this returns an empty iterator for the section
 380  
        */
 381  
       public Iterator<String> iterator() {
 382  0
          return list.iterator();
 383  
       }
 384  
 
 385  
       /**
 386  
        * This is used to return the name of the section. The name is 
 387  
        * must be a valid XML element name. It is used when a style
 388  
        * is applied to a path as the section name must be styled.
 389  
        * 
 390  
        * @return this returns the name of this section instance
 391  
        */
 392  
       public String getName() {
 393  0
          return null;
 394  
       }
 395  
 
 396  
       /**
 397  
        * This is used to acquire the path prefix for the section. The
 398  
        * path prefix is used when the section is transformed in to an
 399  
        * XML structure. This ensures that the XML element created to
 400  
        * represent the section contains the optional prefix.
 401  
        * 
 402  
        * @return this returns the prefix for this section
 403  
        */
 404  
       public String getPrefix() {
 405  0
          return null;
 406  
       }
 407  
 
 408  
       /**
 409  
        * This is used to acquire the text label for this section if 
 410  
        * one has been specified. A text label can only exist in a
 411  
        * section if there are no elements associated with the section
 412  
        * and the section is not composite, as in it does not contain
 413  
        * any further sections.
 414  
        * 
 415  
        * @return this returns the text label for this section
 416  
        */
 417  
       public Label getText() {
 418  0
          return null;
 419  
       }
 420  
 
 421  
       /**
 422  
        * Returns a <code>LabelMap</code> that contains the details for
 423  
        * all fields and methods marked with XML annotations. All of the
 424  
        * element annotations are considered and gathered by name in 
 425  
        * this map. Also, if there is an associated <code>Style</code> 
 426  
        * for serialization the element names are renamed with this.
 427  
        * 
 428  
        * @return returns the elements associated with this section
 429  
        */
 430  
       public LabelMap getElements()  {
 431  28
          return new LabelMap(scanner);
 432  
       }
 433  
 
 434  
       /**
 435  
        * Returns a <code>LabelMap</code> that contains the details for
 436  
        * all fields and methods marked with XML annotations. All of the
 437  
        * attribute annotations are considered and gathered by name in 
 438  
        * this map. Also, if there is an associated <code>Style</code> 
 439  
        * for serialization the attribute names are renamed with this.
 440  
        * 
 441  
        * @return returns the attributes associated with this section
 442  
        */
 443  
       public LabelMap getAttributes() {
 444  28
          return new LabelMap(scanner);
 445  
       }
 446  
 
 447  
       /**
 448  
        * Returns the named element as a <code>Label</code> object.
 449  
        * For convenience this method is provided so that when iterating
 450  
        * over the names of the elements in the section a specific one
 451  
        * of interest can be acquired.    
 452  
        * 
 453  
        * @param name the name of the element that is to be acquired
 454  
        * 
 455  
        * @return this returns the label associated with the name
 456  
        */
 457  
       public Label getElement(String name) {
 458  0
          return null;
 459  
       }
 460  
 
 461  
       /**
 462  
        * Returns the named section as a <code>Section</code> object.
 463  
        * For convenience this method is provided so that when iterating
 464  
        * over the names of the elements in the section a specific one
 465  
        * of interest can be acquired. 
 466  
        * 
 467  
        * @param name the name of the element that is to be acquired
 468  
        * 
 469  
        * @return this returns the section associated with the name
 470  
        */
 471  
       public Section getSection(String name) {
 472  0
          return null;
 473  
       }
 474  
 
 475  
       /**
 476  
        * This is used to acquire the full element path for this
 477  
        * section. The element path is simply the fully qualified
 478  
        * path for this expression with the provided name appended.
 479  
        * If this is an empty path, the provided name is returned.
 480  
        * 
 481  
        * @param name this is the name of the element to be used
 482  
        * 
 483  
        * @return a fully qualified path for the specified name
 484  
        */
 485  
       public String getPath(String name) {
 486  0
          return null;
 487  
       }
 488  
 
 489  
       /**
 490  
        * This is used to acquire the full attribute path for this 
 491  
        * section. The attribute path is simply the fully qualified
 492  
        * path for this expression with the provided name appended.
 493  
        * If this is an empty path, the provided name is returned.
 494  
        * 
 495  
        * @param name this is the name of the attribute to be used
 496  
        * 
 497  
        * @return a fully qualified path for the specified name
 498  
        */
 499  
       public String getAttribute(String name) {
 500  0
          return null;
 501  
       }
 502  
 
 503  
       /**
 504  
        * To differentiate between a section and an element this can be
 505  
        * used. When iterating over the elements within the section the
 506  
        * names of both elements and sections are provided. So in order
 507  
        * to determine how to interpret the structure this can be used.
 508  
        * 
 509  
        * @param name this is the name of the element to be determined
 510  
        * 
 511  
        * @return this returns true if the name represents a section
 512  
        */
 513  
       public boolean isSection(String name) {
 514  0
          return false;
 515  
       }      
 516  
    }
 517  
 }
 518