Examples of ClassMap


Examples of org.apache.velocity.util.introspection.ClassMap

    public void testPrimitives()
      throws Exception
    {
  Log log = Velocity.getLog();
 
        ClassMap c = new ClassMap(TestClassMap.class, log);
        assertNotNull(c.findMethod("setBoolean",   new Object[] { Boolean.TRUE }));
        assertNotNull(c.findMethod("setByte",      new Object[] { new Byte((byte) 4)}));
        assertNotNull(c.findMethod("setCharacter", new Object[] { new Character('c')}));
        assertNotNull(c.findMethod("setDouble",    new Object[] { new Double(8.0) }));
        assertNotNull(c.findMethod("setFloat",     new Object[] { new Float(15.0) }));
        assertNotNull(c.findMethod("setInteger",   new Object[] { new Integer(16) }));
        assertNotNull(c.findMethod("setLong",      new Object[] { new Long(23) }));
        assertNotNull(c.findMethod("setShort",     new Object[] { new Short((short)42)}));
    }
View Full Code Here

Examples of org.apache.velocity.util.introspection.ClassMap

    public void testPrimitives()
      throws Exception
    {
  Log log = Velocity.getLog();
 
        ClassMap c = new ClassMap(TestClassMap.class, log);
        assertNotNull(c.findMethod("setBoolean",   new Object[] { Boolean.TRUE }));
        assertNotNull(c.findMethod("setByte",      new Object[] { new Byte((byte) 4)}));
        assertNotNull(c.findMethod("setCharacter", new Object[] { new Character('c')}));
        assertNotNull(c.findMethod("setDouble",    new Object[] { new Double(8.0) }));
        assertNotNull(c.findMethod("setFloat",     new Object[] { new Float(15.0) }));
        assertNotNull(c.findMethod("setInteger",   new Object[] { new Integer(16) }));
        assertNotNull(c.findMethod("setLong",      new Object[] { new Long(23) }));
        assertNotNull(c.findMethod("setShort",     new Object[] { new Short((short)42)}));
    }
View Full Code Here

Examples of org.codehaus.plexus.util.introspection.ClassMap

                    catch ( NumberFormatException e )
                    {
                    }
                }

                final ClassMap classMap = getClassMap( value.getClass() );

                final String methodBase = StringUtils.capitalizeFirstLetter( token );

                String methodName = "get" + methodBase;

                Method method = classMap.findMethod( methodName, CLASS_ARGS );

                if ( method == null )
                {
                    // perhaps this is a boolean property??
                    methodName = "is" + methodBase;

                    method = classMap.findMethod( methodName, CLASS_ARGS );
                }

                if ( method == null )
                {
                    return null;
                }

                value = method.invoke( value, OBJECT_ARGS );
                if ( value == null )
                {
                    return null;
                }
                if ( Collection.class.isAssignableFrom( value.getClass() ) )
                {
                    ClassMap classMap2 = getClassMap( value.getClass() );

                    Method method2 = classMap2.findMethod( "toArray", CLASS_ARGS );

                    value = method2.invoke( value, OBJECT_ARGS );
                }
                if ( value.getClass().isArray() )
                {
View Full Code Here

Examples of org.codehaus.plexus.util.introspection.ClassMap

            return value;
        }

        private static ClassMap getClassMap( Class<? extends Object> clazz )
        {
            ClassMap classMap = classMaps.get( clazz );

            if ( classMap == null )
            {
                classMap = new ClassMap( clazz );

                classMaps.put( clazz, classMap );
            }

            return classMap;
View Full Code Here

Examples of org.codehaus.plexus.util.introspection.ClassMap

                    catch ( NumberFormatException e )
                    {
                    }
                }

                final ClassMap classMap = getClassMap( value.getClass() );

                final String methodBase = StringUtils.capitalizeFirstLetter( token );

                String methodName = "get" + methodBase;

                Method method = classMap.findMethod( methodName, CLASS_ARGS );

                if ( method == null )
                {
                    // perhaps this is a boolean property??
                    methodName = "is" + methodBase;

                    method = classMap.findMethod( methodName, CLASS_ARGS );
                }

                if ( method == null )
                {
                    return null;
                }

                value = method.invoke( value, OBJECT_ARGS );
                if ( value == null )
                {
                    return null;
                }
                if ( Collection.class.isAssignableFrom( value.getClass() ) )
                {
                    ClassMap classMap2 = getClassMap( value.getClass() );

                    Method method2 = classMap2.findMethod( "toArray", CLASS_ARGS );

                    value = method2.invoke( value, OBJECT_ARGS );
                }
                if ( value.getClass().isArray() )
                {
View Full Code Here

Examples of org.codehaus.plexus.util.introspection.ClassMap

            return value;
        }

        private static ClassMap getClassMap( Class<? extends Object> clazz )
        {
            ClassMap classMap = classMaps.get( clazz );

            if ( classMap == null )
            {
                classMap = new ClassMap( clazz );

                classMaps.put( clazz, classMap );
            }

            return classMap;
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    assertNotNull("The list of mappings should not be null", mapping);

    assertEquals("There should be one mapping", 3, mapping.size());

    ClassMap classMap = mapping.get(0);

    assertNotNull("The classmap should not be null", classMap);

    List<FieldMap> fieldMaps = classMap.getFieldMaps();

    assertNotNull("The fieldmaps should not be null", fieldMaps);
    assertEquals("The fieldmap should have one mapping", 1, fieldMaps.size());

    FieldMap fieldMap = fieldMaps.get(0);
View Full Code Here

Examples of org.dozer.classmap.ClassMap

      }
    }   

    // iterate through the classmaps and set all of the customconverters on them
    for (Entry<String, ClassMap> entry : customMappings.getAll().entrySet()) {
      ClassMap classMap = entry.getValue();
      if (classMap.getCustomConverters() != null) {
        classMap.getCustomConverters().setConverters(new ArrayList<CustomConverterDescription>(customConverterDescriptions));
      } else {
        classMap.setCustomConverters(new CustomConverterContainer());
        classMap.getCustomConverters().setConverters(new ArrayList<CustomConverterDescription>(customConverterDescriptions));
      }
    }
    return new LoadMappingsResult(customMappings, globalConfiguration);
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    if (classMaps == null || classMaps.size() == 0) {
      return result;
    }
    FieldMap fieldMapPrime;
    // need to create bi-directional mappings now.
    ClassMap classMapPrime;
    Set<String> mapIds = new HashSet<String>();
    for (ClassMap classMap : classMaps) {
      classMap.setGlobalConfiguration(globalConfiguration);

      // add our first class map to the result map and initialize PropertyDescriptor Cache
      ReflectionUtils.findPropertyDescriptor(classMap.getSrcClassToMap(), "", null);
      ReflectionUtils.findPropertyDescriptor(classMap.getDestClassToMap(), "", null);

      // Check to see if this is a duplicate map id, irregardless of src and dest class names.
      // Duplicate map-ids are not allowed
      if (!MappingUtils.isBlankOrNull(classMap.getMapId())) {
        if (mapIds.contains(classMap.getMapId())) {
          throw new IllegalArgumentException("Duplicate Map Id's Found. Map Id: " + classMap.getMapId());
        }
        mapIds.add(classMap.getMapId());
      }

      result.add(classMap.getSrcClassToMap(), classMap.getDestClassToMap(), classMap.getMapId(), classMap);
      // now create class map prime
      classMapPrime = new ClassMap(globalConfiguration);
      MappingUtils.reverseFields(classMap, classMapPrime);

      if (classMap.getFieldMaps() != null) {
        Object[] fms = classMap.getFieldMaps().toArray();
        // iterate through the fields and see wether or not they should be mapped
        // one way class mappings we do not need to add any fields
        if (!MappingDirection.ONE_WAY.equals(classMap.getType())) {
          for (Object fm1 : fms) {
            FieldMap fieldMap = (FieldMap) fm1;
            fieldMap.validate();

            // If we are dealing with a Map data type, transform the field map into a MapFieldMap type
            // only apply transformation if it is map to non-map mapping.
            if (!(fieldMap instanceof ExcludeFieldMap)) {
              if ((isSupportedMap(classMap.getDestClassToMap())
                      && !isSupportedMap(classMap.getSrcClassToMap()))
                  || (isSupportedMap(classMap.getSrcClassToMap())
                      && !isSupportedMap(classMap.getDestClassToMap()))
                  || (isSupportedMap(fieldMap.getDestFieldType(classMap.getDestClassToMap()))
                      && !isSupportedMap(fieldMap.getSrcFieldType(classMap.getSrcClassToMap())))
                  || (isSupportedMap(fieldMap.getSrcFieldType(classMap.getSrcClassToMap())))
                      && !isSupportedMap(fieldMap.getDestFieldType(classMap.getDestClassToMap()))) {
                FieldMap fm = new MapFieldMap(fieldMap);
                classMap.removeFieldMapping(fieldMap);
                classMap.addFieldMapping(fm);
                fieldMap = fm;
              }
            }

            if (!(MappingDirection.ONE_WAY.equals(fieldMap.getType()) && !(fieldMap instanceof ExcludeFieldMap))) {
              // make a prime field map
              fieldMapPrime = (FieldMap) fieldMap.clone();
              fieldMapPrime.setClassMap(classMapPrime);
              // check to see if it is only an exclude one way
              if (fieldMapPrime instanceof ExcludeFieldMap && MappingDirection.ONE_WAY.equals(fieldMap.getType())) {
                // need to make a generic field map for the other direction
                fieldMapPrime = new GenericFieldMap(classMapPrime);
              }
              // reverse the fields
              MappingUtils.reverseFields(fieldMap, fieldMapPrime);

              // iterate through copyByReferences and set accordingly
              if (!(fieldMap instanceof ExcludeFieldMap)) {
                MappingUtils.applyGlobalCopyByReference(globalConfiguration, fieldMap, classMap);
              }
              if (!(fieldMapPrime instanceof ExcludeFieldMap)) {
                MappingUtils.applyGlobalCopyByReference(globalConfiguration, fieldMapPrime, classMapPrime);
              }
            } else { // if it is a one-way field map make the other field map excluded
              // make a prime field map
              fieldMapPrime = new ExcludeFieldMap(classMapPrime);
              MappingUtils.reverseFields(fieldMap, fieldMapPrime);
            }
            classMapPrime.addFieldMapping(fieldMapPrime);
          }
        } else {
          // since it is one-way...we still need to validate if it has some type of method mapping and validate the
          // field maps
          for (Object fm : fms) {
            FieldMap oneWayFieldMap = (FieldMap) fm;
            oneWayFieldMap.validate();

            MappingUtils.applyGlobalCopyByReference(globalConfiguration, oneWayFieldMap, classMap);
            // check to see if we need to exclude the map
            if (MappingDirection.ONE_WAY.equals(oneWayFieldMap.getType())) {
              fieldMapPrime = new ExcludeFieldMap(classMapPrime);
              MappingUtils.reverseFields(oneWayFieldMap, fieldMapPrime);
              classMapPrime.addFieldMapping(fieldMapPrime);
            }
          }
        }
      }
      // if it is a one way mapping or a method/iterate method mapping we can not bi-directionally map
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    } else {
      destType = destClass;
      result = null;
    }

    ClassMap classMap = null;
    try {
      classMap = getClassMap(srcObj.getClass(), destType, mapId);

      eventMgr.fireEvent(new DozerEvent(DozerEventType.MAPPING_STARTED, classMap, null, srcObj, result, null));

      // TODO Check if any proxy issues are here
      // Check to see if custom converter has been specified for this mapping
      // combination. If so, just use it.
      Class<?> converterClass = MappingUtils.findCustomConverter(converterByDestTypeCache, classMap.getCustomConverters(), srcObj
          .getClass(), destType);

      if (converterClass != null) {
        return (T) mapUsingCustomConverter(converterClass, srcObj.getClass(), srcObj, destType, result, null, true);
      }

      if (result == null) {
        result = (T) DestBeanCreator.create(new BeanCreationDirective(srcObj, classMap.getSrcClassToMap(), classMap.getDestClassToMap(), destType, classMap
            .getDestClassBeanFactory(), classMap.getDestClassBeanFactoryId(), classMap.getDestClassCreateMethod()));
      }

      // If this is a nested MapperAware conversion this mapping can be already processed
      Object alreadyMappedValue = mappedFields.getMappedValue(srcObj, destClass);
      if (alreadyMappedValue != null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.