Skip to content

Commit

Permalink
Add module for Hibernate support (XSTR-226, XSTR-377).
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Apr 21, 2011
1 parent 940c909 commit e0fe8f9
Show file tree
Hide file tree
Showing 25 changed files with 1,036 additions and 14 deletions.
44 changes: 38 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
Copyright (C) 2006 Joe Walnes.
Copyright (C) 2006, 2007, 2008, 2009, 2010 XStream committers.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream committers.
All rights reserved.
The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -39,6 +39,7 @@
<modules>
<module>xstream</module>
<!--module>xstream-builder</module-->
<module>xstream-hibernate</module>
<module>xstream-benchmark</module>
<module>xstream-distribution</module>
</modules>
Expand All @@ -51,6 +52,7 @@
<modules>
<module>xstream</module>
<!--module>xstream-builder</module-->
<module>xstream-hibernate</module>
<module>xstream-benchmark</module>
<module>xstream-distribution</module>
</modules>
Expand All @@ -62,6 +64,7 @@
</activation>
<modules>
<module>xstream</module>
<module>xstream-hibernate</module>
<module>xstream-benchmark</module>
<module>xstream-distribution</module>
</modules>
Expand Down Expand Up @@ -101,6 +104,11 @@
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>

<dependency>
<groupId>dom4j</groupId>
Expand Down Expand Up @@ -226,6 +234,29 @@
<version>2.8.1</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>

<!-- always test-scoped -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -260,6 +291,7 @@
<testResource>
<directory>${basedir}/src/test</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.xsl</include>
<include>**/*.txt</include>
</includes>
Expand All @@ -285,12 +317,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<version>2.1</version><!-- JVM 1.4 -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0-alpha-4</version>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -300,9 +332,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<configuration>
<downloadSources>true</downloadSources>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -317,7 +349,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 2 additions & 2 deletions xstream-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@

<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>xstream</artifactId>
<version>${pom.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sf.kxml</groupId>
Expand Down
4 changes: 2 additions & 2 deletions xstream-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>xstream</artifactId>
<version>${pom.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
2 changes: 2 additions & 0 deletions xstream-distribution/src/content/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ <h1 id="Upcoming">Upcoming</h1>
<h2>Major changes</h2>

<ul>
<li>JIRA:XSTR-377+JIRA:XSTR-226: New artifact xstream-hibernate with converters and mapper to process Hibernate object graphs (by Costin
Leau, Konstantin Pribluda and in special Jaime Metcher).</li>
<li>New NameCoder interface and implementations to support a generic name translation between names from the object graph and a target
format. The new XmlFriendlyNameCoder replaces the XmlFriendlyReplacer used for XML.</li>
<li>JIRA:XSTR-542: The XppDriver uses now the official XmlPullParser API to locate an available parser using the XmlPullParserFactory. This
Expand Down
5 changes: 4 additions & 1 deletion xstream-distribution/src/content/team.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<!--
Copyright (C) 2005, 2006 Joe Walnes.
Copyright (C) 2006, 2007, 2008, 2009, 2010 XStream committers.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream committers.
All rights reserved.
The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -46,6 +46,8 @@ <h2 id="hibernate">Hibernating Committers</h2>

<h2 id="contributors">Contributors</h2>

<p>List in sequence of first contribution to XStream.</p>

<ul>
<li>Tim Mackinnon</li>
<li>James Strachan</li>
Expand Down Expand Up @@ -109,6 +111,7 @@ <h2 id="contributors">Contributors</h2>
<li>Doug Daniels</li>
<li>Jason Greanya</li>
<li>Carlos Roman</li>
<li>Jaime Metcher</li>
</ul>

<p>Please direct all correspondence about XStream to the <a href="list-user.html">users' mailing lists</a>
Expand Down
64 changes: 64 additions & 0 deletions xstream-hibernate/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
Copyright (C) 2011 XStream committers.
All rights reserved.
The software in this package is published under the terms of the BSD
style license a copy of which has been included with this distribution in
the LICENSE.txt file.
Created on 5. April 2011 by Joerg Schaible
-->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream-parent</artifactId>
<version>1.4-SNAPSHOT</version>
</parent>
<artifactId>xstream-hibernate</artifactId>
<packaging>jar</packaging>
<name>XStream Hibernate Extension</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>xstream</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>xstream</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2011 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 19. April 2011 by Joerg Schaible
*/
package com.thoughtworks.xstream.hibernate.converter;

import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.mapper.Mapper;

import org.hibernate.collection.PersistentBag;
import org.hibernate.collection.PersistentList;
import org.hibernate.collection.PersistentSet;


/**
* A converter for Hibernate's {@link PersistentBag}, {@link PersistentList} and
* {@link PersistentSet}. The converter will drop any reference to the Hibernate collection and
* emit at serialization time an equivalent JDK collection instead.
*
* @author J&ouml;rg Schaible
* @since upcoming
*/
public class HibernatePersistentCollectionConverter extends CollectionConverter {

/**
* Construct a HibernatePersistentCollectionConverter.
*
* @param mapper
* @since upcoming
*/
public HibernatePersistentCollectionConverter(final Mapper mapper) {
super(mapper);
}

public boolean canConvert(final Class type) {
return type == PersistentBag.class
|| type == PersistentList.class
|| type == PersistentSet.class;
}

public Object unmarshal(final HierarchicalStreamReader reader,
final UnmarshallingContext context) {
throw new ConversionException("Cannot deserialize Hibernate collection");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2011 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 19. April 2011 by Joerg Schaible
*/
package com.thoughtworks.xstream.hibernate.converter;

import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.collections.MapConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.mapper.Mapper;

import org.hibernate.collection.PersistentMap;


/**
* A converter for Hibernate's {@link PersistentMap}. The converter will drop any reference to
* the Hibernate collection and emit at serialization time an equivalent JDK collection instead.
*
* @author J&ouml;rg Schaible
* @since upcoming
*/
public class HibernatePersistentMapConverter extends MapConverter {

/**
* Construct a HibernatePersistentMapConverter.
*
* @param mapper
* @since upcoming
*/
public HibernatePersistentMapConverter(final Mapper mapper) {
super(mapper);
}

public boolean canConvert(final Class type) {
return type == PersistentMap.class;
}

public Object unmarshal(final HierarchicalStreamReader reader,
final UnmarshallingContext context) {
throw new ConversionException("Cannot deserialize Hibernate collection");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2011 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 19. April 2011 by Joerg Schaible
*/
package com.thoughtworks.xstream.hibernate.converter;

import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.collections.TreeMapConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.mapper.Mapper;

import org.hibernate.collection.PersistentSortedMap;


/**
* A converter for Hibernate's {@link PersistentSortedMap}. The converter will drop any
* reference to the Hibernate collection and emit at serialization time an equivalent JDK
* collection instead.
*
* @author J&ouml;rg Schaible
* @since upcoming
*/
public class HibernatePersistentSortedMapConverter extends TreeMapConverter {

/**
* Construct a HibernatePersistentSortedMapConverter.
*
* @param mapper
* @since upcoming
*/
public HibernatePersistentSortedMapConverter(final Mapper mapper) {
super(mapper);
}

public boolean canConvert(final Class type) {
return type == PersistentSortedMap.class;
}

public Object unmarshal(final HierarchicalStreamReader reader,
final UnmarshallingContext context) {
throw new ConversionException("Cannot deserialize Hibernate collection");
}
}
Loading

0 comments on commit e0fe8f9

Please sign in to comment.