2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.hibernate
;
12 import java
.io
.Reader
;
13 import java
.io
.Serializable
;
14 import java
.io
.StringReader
;
15 import java
.io
.StringWriter
;
17 import java
.sql
.PreparedStatement
;
18 import java
.sql
.ResultSet
;
19 import java
.sql
.SQLException
;
20 import java
.sql
.Types
;
22 import javax
.wsdl
.Definition
;
23 import javax
.wsdl
.WSDLException
;
24 import javax
.wsdl
.factory
.WSDLFactory
;
25 import javax
.wsdl
.xml
.WSDLLocator
;
26 import javax
.wsdl
.xml
.WSDLReader
;
27 import javax
.wsdl
.xml
.WSDLWriter
;
29 import org
.hibernate
.HibernateException
;
30 import org
.hibernate
.engine
.spi
.SessionImplementor
;
31 import org
.hibernate
.type
.StandardBasicTypes
;
32 import org
.hibernate
.usertype
.UserType
;
33 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.AbstractSingleColumnUserType
;
34 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.AbstractUserType
;
35 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.ColumnMapper
;
37 import com
.ibm
.wsdl
.factory
.WSDLFactoryImpl
;
39 import eu
.etaxonomy
.cdm
.model
.common
.LSIDWSDLLocator
;
42 * UserType which allows persistence of a wsdl definition - used to persist the
43 * wsdl definition of an LSIDAuthority
47 * @see org.cateproject.model.lsid.PersistableLSIDAuthority
48 * @see org.hibernate.usertype.UserType UserType
49 * @see javax.wsdl.Definition Definition
51 public class WSDLDefinitionUserType
extends AbstractUserType
implements UserType
{
53 private static final int[] SQL_TYPES
= { Types
.CLOB
};
55 public Object
deepCopy(Object o
) throws HibernateException
{
61 Definition d
= (Definition
) o
;
64 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
65 StringWriter stringWriter
= new StringWriter();
66 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
67 writer
.writeWSDL(d
, stringWriter
);
68 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
69 Reader reader
= new StringReader(stringWriter
.getBuffer().toString());
70 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
71 Definition definition
= wsdlReader
.readWSDL(locator
);
73 } catch (Exception e
) {
74 throw new HibernateException(e
);
79 //not tested if this works with jadira.usertype
81 public Object
assemble(Serializable cached
, Object owner
) throws HibernateException
{
83 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
84 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
85 Reader reader
= new StringReader(cached
.toString());
86 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
87 Definition definition
= wsdlReader
.readWSDL(locator
);
89 } catch (Exception e
) {
90 throw new HibernateException(e
);
94 //not tested if this works with jadira.usertype
96 public Serializable
disassemble(Object value
) throws HibernateException
{
98 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
99 Definition definition
= (Definition
) value
;
100 StringWriter stringWriter
= new StringWriter();
101 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
102 writer
.writeWSDL(definition
, stringWriter
);
103 return stringWriter
.getBuffer().toString();
104 } catch (WSDLException e
) {
105 throw new HibernateException(e
);
112 public Definition
nullSafeGet(ResultSet rs
, String
[]names
, SessionImplementor session
, Object o
)
113 throws HibernateException
, SQLException
{
114 Clob val
= (Clob
)StandardBasicTypes
.CLOB
.nullSafeGet(rs
, names
, session
, o
);
115 // Clob val = (Clob) rs.getClob(names[0]);
120 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
121 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
122 Reader reader
= val
.getCharacterStream();
123 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
124 Definition definition
= wsdlReader
.readWSDL(locator
);
126 } catch (Exception e
) {
127 throw new HibernateException(e
);
135 public void nullSafeSet(PreparedStatement statement
, Object value
, int index
, SessionImplementor session
)
136 throws HibernateException
, SQLException
{
138 // statement.setNull(index, Types.CLOB); //old version
139 StandardBasicTypes
.CLOB
.nullSafeSet(statement
, value
, index
, session
);
142 Definition definition
= (Definition
) value
;
143 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
144 StringWriter stringWriter
= new StringWriter();
145 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
146 writer
.writeWSDL(definition
, stringWriter
);
147 // statement.setClob(index, Hibernate.createClob(stringWriter.getBuffer().toString())); //old version
148 StandardBasicTypes
.CLOB
.nullSafeSet(statement
, stringWriter
.getBuffer().toString(), index
, session
);
149 } catch (WSDLException e
) {
150 throw new HibernateException(e
);
157 public Class
returnedClass() {
158 return Definition
.class;
163 public int[] sqlTypes() {