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
.apache
.commons
.logging
.Log
;
30 import org
.apache
.commons
.logging
.LogFactory
;
31 import org
.hibernate
.Hibernate
;
32 import org
.hibernate
.HibernateException
;
33 import org
.hibernate
.usertype
.UserType
;
35 import com
.ibm
.wsdl
.factory
.WSDLFactoryImpl
;
37 import eu
.etaxonomy
.cdm
.model
.common
.LSIDWSDLLocator
;
40 * UserType which allows persistence of a wsdl definition - used to persist the
41 * wsdl definition of an LSIDAuthority
45 * @see org.cateproject.model.lsid.PersistableLSIDAuthority
46 * @see org.hibernate.usertype.UserType UserType
47 * @see javax.wsdl.Definition Definition
49 public class WSDLDefinitionUserType
implements UserType
{
50 private static Log log
= LogFactory
.getLog(WSDLDefinitionUserType
.class);
51 private static final int[] TYPES
= { Types
.CLOB
};
53 public Object
deepCopy(Object o
) throws HibernateException
{
59 Definition d
= (Definition
) o
;
62 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
63 StringWriter stringWriter
= new StringWriter();
64 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
65 writer
.writeWSDL(d
, stringWriter
);
66 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
67 Reader reader
= new StringReader(stringWriter
.getBuffer().toString());
68 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
69 Definition definition
= wsdlReader
.readWSDL(locator
);
71 } catch (Exception e
) {
72 throw new HibernateException(e
);
76 public Object
assemble(Serializable cached
, Object owner
) throws HibernateException
{
78 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
79 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
80 Reader reader
= new StringReader(cached
.toString());
81 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
82 Definition definition
= wsdlReader
.readWSDL(locator
);
84 } catch (Exception e
) {
85 throw new HibernateException(e
);
89 public Serializable
disassemble(Object value
) throws HibernateException
{
91 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
92 Definition definition
= (Definition
) value
;
93 StringWriter stringWriter
= new StringWriter();
94 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
95 writer
.writeWSDL(definition
, stringWriter
);
96 return stringWriter
.getBuffer().toString();
97 } catch (WSDLException e
) {
98 throw new HibernateException(e
);
102 public boolean equals(Object x
, Object y
) throws HibernateException
{
103 return (x
== y
) || (x
!= null && y
!= null && (x
.equals(y
)));
106 public int hashCode(Object x
) throws HibernateException
{
110 public boolean isMutable() {
114 public Object
nullSafeGet(ResultSet resultSet
, String
[] names
, Object o
)
115 throws HibernateException
, SQLException
{
116 Clob val
= (Clob
) resultSet
.getClob(names
[0]);
121 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
122 WSDLReader wsdlReader
= wsdlFactory
.newWSDLReader();
123 Reader reader
= val
.getCharacterStream();
124 WSDLLocator locator
= new LSIDWSDLLocator("wsdl",reader
,Thread
.currentThread().getContextClassLoader());
125 Definition definition
= wsdlReader
.readWSDL(locator
);
127 } catch (Exception e
) {
128 throw new HibernateException(e
);
133 public void nullSafeSet(PreparedStatement preparedStatement
, Object o
, int index
)
134 throws HibernateException
, SQLException
{
136 preparedStatement
.setNull(index
, Types
.CLOB
);
139 Definition definition
= (Definition
) o
;
140 WSDLFactory wsdlFactory
= WSDLFactoryImpl
.newInstance();
141 StringWriter stringWriter
= new StringWriter();
142 WSDLWriter writer
= wsdlFactory
.newWSDLWriter();
143 writer
.writeWSDL(definition
, stringWriter
);
144 preparedStatement
.setClob(index
, Hibernate
.createClob(stringWriter
.getBuffer().toString()));
145 } catch (WSDLException e
) {
146 throw new HibernateException(e
);
152 public Object
replace(Object original
, Object target
, Object owner
)
153 throws HibernateException
{
157 public Class
returnedClass() {
158 return Definition
.class;
161 public int[] sqlTypes() {