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

The following examples show how to use com.thoughtworks.xstream.converters.reflection.ReflectionProvider. 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
Source File: ToAttributedValueConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: IdentifiableToIdConverter.java    From cloudstreetmarket.com with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: XStreamUtils.java    From kogito-runtimes with 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 #4
Source File: XStream.java    From lams with 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 #5
Source File: XStream.java    From lams with 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 #6
Source File: AnnotationReflectionConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
public AnnotationReflectionConverter(
                                     Mapper mapper, ReflectionProvider reflectionProvider,
                                     AnnotationProvider annotationProvider) {
    super(mapper, reflectionProvider);
    this.annotationProvider = annotationProvider;
    this.cachedConverters = new HashMap<Class<? extends ConverterMatcher>, Converter>();
}
 
Example #7
Source File: AnnotationMapper.java    From lams with 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 #8
Source File: JVM.java    From lams with 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 #9
Source File: CubaXStream.java    From cuba with 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 #10
Source File: XStreamUtils.java    From kogito-runtimes with 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 #11
Source File: XStreamFactory.java    From engage-api-client with 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 File: VersionedExternalizable.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public Converter(final Mapper mapper, final ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example #13
Source File: SubstituteJVM.java    From camel-quarkus with 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 File: ImplicitCollectionMapper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ImplicitCollectionMapper(Mapper wrapped, ReflectionProvider reflectionProvider) {
    super(wrapped);
    this.reflectionProvider = reflectionProvider;
}
 
Example #15
Source File: VersionedExternalizable.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public Converter(final Mapper mapper, final ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}
 
Example #16
Source File: AttributeMapper.java    From lams with 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 #17
Source File: SerializerServiceBase.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public ProxyConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
    super(mapper, reflectionProvider);
}
 
Example #18
Source File: XmlObjectSerializerServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public ProxyConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
    super(mapper, reflectionProvider);
}
 
Example #19
Source File: XStream.java    From lams with 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 #20
Source File: HibernateProxyConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public HibernateProxyConverter(Mapper arg0, ReflectionProvider arg1, ConverterLookup converterLookup)
{
  super(arg0, arg1);
  this.converterLookup = converterLookup;
}
 
Example #21
Source File: ReflectionConverter.java    From onedev with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider, Class type) {
   	super(mapper, reflectionProvider, type);
   }
 
Example #22
Source File: XStreamUtils.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public static XStream createTrustingXStream(ReflectionProvider reflectionProvider) {
    return internalCreateTrustingXStream(new XStream(reflectionProvider));
}
 
Example #23
Source File: XStreamUtils.java    From kogito-runtimes with 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 #24
Source File: XStreamUtils.java    From kogito-runtimes with 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 #25
Source File: XStreamUtils.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public static XStream createNonTrustingXStream(ReflectionProvider reflectionProvider) {
    return internalCreateNonTrustingXStream(new XStream(reflectionProvider));
}
 
Example #26
Source File: XStreamUtils.java    From kogito-runtimes with 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 #27
Source File: XStreamUtils.java    From kogito-runtimes with 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 #28
Source File: SubstituteJVM.java    From camel-quarkus with 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 #29
Source File: WxPayOrderNotifyResultConverter.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
  super(mapper, reflectionProvider);
}
 
Example #30
Source File: ReflectionConverter.java    From onedev with MIT License 4 votes vote down vote up
public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
	super(mapper, reflectionProvider);
}