Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser.impl;
  
  import java.util.*;
  
  
Container class for storing information on creators (based on annotations, visibility), to be able to build actual instantiator later on.
 
 public class CreatorCollector
 {
     /// Type of bean being created
     final protected BeanDescription _beanDesc;
 
     final protected boolean _canFixAccess;

    
Reference to the default creator (constructor or factory method).

Note: name is a misnomer, after resolving of [JACKSON-850], since this can also point to factory method.

 
     
 
     // when there are injectable values along with delegate:
     protected CreatorProperty[] _delegateArgs;
     
     protected CreatorProperty[] _propertyBasedArgs = null;
 
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
     
     public CreatorCollector(BeanDescription beanDescboolean canFixAccess)
     {
          = beanDesc;
          = canFixAccess;
     }
 
     {
         StdValueInstantiator inst = new StdValueInstantiator(config.getType());
 
         JavaType delegateType;
 
         if ( == null) {
             delegateType = null;
         } else {
             // need to find type...
             int ix = 0;
             if ( != null) {
                 for (int i = 0, len = .i < len; ++i) {
                     if ([i] == null) { // marker for delegate itself
                         ix = i;
                         break;
                     }
                 }
             }
             TypeBindings bindings = .bindingsForBeanType();
             delegateType = bindings.resolveType(.getGenericParameterType(ix));
         }
         
                 delegateType,
                 );
         inst.configureFromIntCreator();
         inst.configureFromLongCreator();
         return inst;
     }
     
     /*
     /**********************************************************
     /* Setters
     /**********************************************************
      */

    
    @Deprecated
    public void setDefaultConstructor(AnnotatedConstructor ctor) {
         = _fixAccess(ctor);
    }
    
    
Method called to indicate the default creator: no-arguments constructor or factory method that is called to instantiate a value before populating it with data. Default creator is only used if no other creators are indicated.

Parameters:
creator Creator method; no-arguments constructor or static factory method.
    public void setDefaultCreator(AnnotatedWithParams creator)
    {
        // !!! TODO: 23-Jul-2012, tatu: Should change to directly change things
        //    here in future; but for backwards compatibility, can't do that yet
        if (creator instanceof AnnotatedConstructor) {
            setDefaultConstructor((AnnotatedConstructorcreator);
            return;
        }
         = _fixAccess(creator);
    }
    
    public void addStringCreator(AnnotatedWithParams creator) {
         = verifyNonDup(creator"String");
    }
    public void addIntCreator(AnnotatedWithParams creator) {
         = verifyNonDup(creator"int");
    }
    public void addLongCreator(AnnotatedWithParams creator) {
         = verifyNonDup(creator"long");
    }
    public void addDoubleCreator(AnnotatedWithParams creator) {
         = verifyNonDup(creator"double");
    }
    public void addBooleanCreator(AnnotatedWithParams creator) {
         = verifyNonDup(creator"boolean");
    }
    public void addDelegatingCreator(AnnotatedWithParams creator,
            CreatorProperty[] injectables)
    {
         = verifyNonDup(creator"delegate");
         = injectables;
    }
    
    public void addPropertyCreator(AnnotatedWithParams creatorCreatorProperty[] properties)
    {
         = verifyNonDup(creator"property-based");
        // [JACKSON-470] Better ensure we have no duplicate names either...
        if (properties.length > 1) {
            HashMap<String,Integernames = new HashMap<String,Integer>();
            for (int i = 0, len = properties.lengthi < len; ++i) {
                String name = properties[i].getName();
                /* [Issue-13]: Need to consider Injectables, which may not have
                 *   a name at all, and need to be skipped
                 */
                if (name.length() == 0 && properties[i].getInjectableValueId() != null) {
                    continue;
                }
                Integer old = names.put(name, Integer.valueOf(i));
                if (old != null) {
                    throw new IllegalArgumentException("Duplicate creator property \""+name+"\" (index "+old+" vs "+i+")");
                }
            }
        }
         = properties;
    }
    /*
    /**********************************************************
    /* Accessors
    /**********************************************************
     */

    

Since:
2.1
    public boolean hasDefaultCreator() {
        return  != null;
    }
    
    /*
    /**********************************************************
    /* Helper methods
    /**********************************************************
     */
    private <T extends AnnotatedMember> T _fixAccess(T member)
    {
        if (member != null && ) {
            ClassUtil.checkAndFixAccess((Membermember.getAnnotated());
        }
        return member;
    }
            String type)
    {
        if (oldOne != null) {
            // important: ok to override factory with constructor; but not within same type, so:
            if (oldOne.getClass() == newOne.getClass()) {
                throw new IllegalArgumentException("Conflicting "+type+" creators: already had "+oldOne+", encountered "+newOne);
            }
        }
        return _fixAccess(newOne);
    }
New to GrepCode? Check out our FAQ X