Java Code Examples for com.thoughtworks.xstream.converters.reflection.ReflectionProvider

The following examples show how to use com.thoughtworks.xstream.converters.reflection.ReflectionProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param type the type that is handled by this converter instance
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 * @param valueDefinedIn the type defining the field
 */
public ToAttributedValueConverter(
    final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName, Class valueDefinedIn) {
    this.type = type;
    this.mapper = mapper;
    this.reflectionProvider = reflectionProvider;
    this.lookup = lookup;

    if (valueFieldName == null) {
        valueField = null;
    } else {
        Field field = null;
        try {
            field = (valueDefinedIn != null ? valueDefinedIn : type)
                .getDeclaredField(valueFieldName);
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
        } catch (NoSuchFieldException e) {
            throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
        }
        this.valueField = field;
    }
    enumMapper = JVM.isVersion(5) ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
}
 
Example 2
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 * @param valueDefinedIn the type defining the field
 */
public IdentifiableToIdConverter(
    final Class<Identifiable<?>> type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName, Class<?> valueDefinedIn) {
    this.type = type;

       Field field = null;
       try {
           field = (valueDefinedIn != null ? valueDefinedIn : type.getSuperclass())
               .getDeclaredField("id");
          
           if (!field.isAccessible()) {
               field.setAccessible(true);
           }
       } catch (NoSuchFieldException e) {
           throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
       }
}
 
Example 3
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static XStream createTrustingXStream(ReflectionProvider reflectionProvider, final Function<MapperWrapper, MapperWrapper> mapper) {
    return internalCreateTrustingXStream(new XStream(reflectionProvider) {
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return (MapperWrapper)mapper.apply(next);
        }
    });
}
 
Example 4
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static XStream createNonTrustingXStream(ReflectionProvider reflectionProvider, final Function<MapperWrapper, MapperWrapper> mapper) {
    return internalCreateNonTrustingXStream(new XStream(reflectionProvider) {
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return (MapperWrapper)mapper.apply(next);
        }
    });
}
 
Example 5
Source Project: lams   Source File: XStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
private XStream(
        ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
        Mapper mapper, final DefaultConverterLookup defaultConverterLookup) {
    this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() {
        public Converter lookupConverterForType(Class type) {
            return defaultConverterLookup.lookupConverterForType(type);
        }
    }, new ConverterRegistry() {
        public void registerConverter(Converter converter, int priority) {
            defaultConverterLookup.registerConverter(converter, priority);
        }
    });
}
 
Example 6
Source Project: lams   Source File: XStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Mapper buildMapper() {
    Mapper mapper = new DefaultMapper(classLoaderReference);
    if (useXStream11XmlFriendlyMapper()) {
        mapper = new XStream11XmlFriendlyMapper(mapper);
    }
    mapper = new DynamicProxyMapper(mapper);
    mapper = new PackageAliasingMapper(mapper);
    mapper = new ClassAliasingMapper(mapper);
    mapper = new ElementIgnoringMapper(mapper);
    mapper = new FieldAliasingMapper(mapper);
    mapper = new AttributeAliasingMapper(mapper);
    mapper = new SystemAttributeAliasingMapper(mapper);
    mapper = new ImplicitCollectionMapper(mapper, reflectionProvider);
    mapper = new OuterClassMapper(mapper);
    mapper = new ArrayMapper(mapper);
    mapper = new DefaultImplementationsMapper(mapper);
    mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
    if (JVM.isVersion(5)) {
        mapper = buildMapperDynamically(
            "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
            new Object[]{mapper});
    }
    mapper = new LocalConversionMapper(mapper);
    mapper = new ImmutableTypesMapper(mapper);
    if (JVM.isVersion(8)) {
        mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
            new Object[]{mapper});
    }
    mapper = new SecurityMapper(mapper);
    if (JVM.isVersion(5)) {
        mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
            Mapper.class, ConverterRegistry.class, ConverterLookup.class,
            ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
            mapper, converterRegistry, converterLookup, classLoaderReference,
            reflectionProvider});
    }
    mapper = wrapMapper((MapperWrapper)mapper);
    mapper = new CachingMapper(mapper);
    return mapper;
}
 
Example 7
@Deprecated
public AnnotationReflectionConverter(
                                     Mapper mapper, ReflectionProvider reflectionProvider,
                                     AnnotationProvider annotationProvider) {
    super(mapper, reflectionProvider);
    this.annotationProvider = annotationProvider;
    this.cachedConverters = new HashMap<Class<? extends ConverterMatcher>, Converter>();
}
 
Example 8
Source Project: lams   Source File: AnnotationMapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an AnnotationMapper.
 * 
 * @param wrapped the next {@link Mapper} in the chain
 * @since 1.4.5
 */
public AnnotationMapper(
    final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup,
    final ClassLoaderReference classLoaderReference, final ReflectionProvider reflectionProvider) {
    super(wrapped);
    this.converterRegistry = converterRegistry;
    annotatedTypes.add(Object.class);
    setupMappers();
    locked = true;
    
    final ClassLoader classLoader = classLoaderReference.getReference();
    arguments = new Object[]{
        this, classLoaderReference, reflectionProvider, converterLookup, new JVM(),
        classLoader != null ? classLoader : new TypedNull(ClassLoader.class)};
}
 
Example 9
Source Project: lams   Source File: JVM.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated As of 1.4.5 use {@link #newReflectionProvider()}
 */
public synchronized ReflectionProvider bestReflectionProvider() {
    if (reflectionProvider == null) {
        reflectionProvider = newReflectionProvider();
    }
    return reflectionProvider;
}
 
Example 10
Source Project: cuba   Source File: CubaXStream.java    License: Apache License 2.0 5 votes vote down vote up
protected CubaXStream(
        ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
        Mapper mapper, final CubaXStreamConverterLookup converterLookup) {
    super(reflectionProvider, driver, classLoader, mapper,
            converterLookup::lookupConverterForType,
            converterLookup::registerConverter);
}
 
Example 11
Source Project: engage-api-client   Source File: XStreamFactory.java    License: Apache License 2.0 5 votes vote down vote up
public XStream createXStream(ReflectionProvider reflectionProvider) {
       return new XStream(reflectionProvider, new DomDriver("UTF-8", new XmlFriendlyNameCoder("__","_"))) {
		@Override
		protected MapperWrapper wrapMapper(MapperWrapper next) {
               return new ApiMapperWrapper(next, apiResponseType);
		}
	};
}
 
Example 12
Source Project: camel-quarkus   Source File: SubstituteJVM.java    License: Apache License 2.0 4 votes vote down vote up
@Substitute
public static ReflectionProvider newReflectionProvider() {
    /* The default SunUnsafeReflectionProvider would require registering every field of every bean for unsafe access */
    return new SunLimitedUnsafeReflectionProvider();
}
 
Example 13
Source Project: camel-quarkus   Source File: SubstituteJVM.java    License: Apache License 2.0 4 votes vote down vote up
@Substitute
public static ReflectionProvider newReflectionProvider(FieldDictionary dictionary) {
    /* The default SunUnsafeReflectionProvider would require registering every field of every bean for unsafe access */
    return new SunLimitedUnsafeReflectionProvider(dictionary);
}
 
Example 14
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createTrustingXStream(HierarchicalStreamDriver hierarchicalStreamDriver, ClassLoader classLoader) {
    return internalCreateTrustingXStream(new XStream((ReflectionProvider)null, hierarchicalStreamDriver, new ClassLoaderReference(classLoader)));
}
 
Example 15
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createTrustingXStream(ReflectionProvider reflectionProvider) {
    return internalCreateTrustingXStream(new XStream(reflectionProvider));
}
 
Example 16
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createTrustingXStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
    return internalCreateTrustingXStream(new XStream(reflectionProvider, hierarchicalStreamDriver));
}
 
Example 17
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createNonTrustingXStream(HierarchicalStreamDriver hierarchicalStreamDriver, ClassLoader classLoader) {
    return internalCreateNonTrustingXStream(new XStream((ReflectionProvider)null, hierarchicalStreamDriver, new ClassLoaderReference(classLoader)));
}
 
Example 18
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createNonTrustingXStream(ReflectionProvider reflectionProvider) {
    return internalCreateNonTrustingXStream(new XStream(reflectionProvider));
}
 
Example 19
Source Project: kogito-runtimes   Source File: XStreamUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XStream createNonTrustingXStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
    return internalCreateNonTrustingXStream(new XStream(reflectionProvider, hierarchicalStreamDriver));
}
 
Example 20
public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
  super(mapper, reflectionProvider);
}
 
Example 21
Source Project: onedev   Source File: ReflectionConverter.java    License: MIT License 4 votes vote down vote up
public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example 22
Source Project: onedev   Source File: ReflectionConverter.java    License: MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider, Class type) {
   	super(mapper, reflectionProvider, type);
   }
 
Example 23
Source Project: openmrs-module-initializer   Source File: InitializerSerializer.java    License: MIT License 4 votes vote down vote up
public IdentifierSourceConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example 24
Source Project: lams   Source File: XStream.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
 * {@link ConverterRegistry}.
 * <p>
 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup
 * should access the ConverterRegistry if you intent to register {@link Converter} instances
 * with XStream facade or you are using annotations.
 * </p>
 * 
 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
 *            matching Provider
 * @param driver the driver instance
 * @param classLoaderReference the reference to the {@link ClassLoader} to use
 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
 *            chain
 * @param converterLookup the instance that is used to lookup the converters
 * @param converterRegistry an instance to manage the converter instances or <em>null</em>
 *            to prevent any further registry (including annotations)
 * @throws InitializationException in case of an initialization problem
 * @since 1.4.5
 */
public XStream(
    ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
    ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
    ConverterRegistry converterRegistry) {
    if (reflectionProvider == null) {
        reflectionProvider = JVM.newReflectionProvider();
    }
    this.reflectionProvider = reflectionProvider;
    this.hierarchicalStreamDriver = driver;
    this.classLoaderReference = classLoaderReference;
    this.converterLookup = converterLookup;
    this.converterRegistry = converterRegistry;
    this.mapper = mapper == null ? buildMapper() : mapper;

    setupMappers();
    setupSecurity();
    setupAliases();
    setupDefaultImplementations();
    setupConverters();
    setupImmutableTypes();
    setMode(XPATH_RELATIVE_REFERENCES);
}
 
Example 25
Source Project: lams   Source File: AttributeMapper.java    License: GNU General Public License v2.0 4 votes vote down vote up
public AttributeMapper(Mapper wrapped, ConverterLookup converterLookup, ReflectionProvider refProvider) {
    super(wrapped);
    this.converterLookup = converterLookup;
    this.reflectionProvider = refProvider;
}
 
Example 26
public ImplicitCollectionMapper(Mapper wrapped, ReflectionProvider reflectionProvider) {
    super(wrapped);
    this.reflectionProvider = reflectionProvider;
}
 
Example 27
public Converter(final Mapper mapper, final ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example 28
public Converter(final Mapper mapper, final ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example 29
public ProxyConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
    super(mapper, reflectionProvider);
}
 
Example 30
public ProxyConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
    super(mapper, reflectionProvider);
}