svn-gvsig-desktop / tmp / trunk / servidor / WorkSpace_Servidor / src / org / tigris / frogs / parsers / ows / DocumentSerializer.java @ 26474
History | View | Annotate | Download (6.3 KB)
1 |
/*
|
---|---|
2 |
* ============================================================================
|
3 |
* Copyright 2006 Government of Canada
|
4 |
*
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
* you may not use this file except in compliance with the License.
|
7 |
* You may obtain a copy of the License at
|
8 |
*
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
*
|
11 |
* Unless required by applicable law or agreed to in writing, software
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
* See the License for the specific language governing permissions and
|
15 |
* limitations under the License.
|
16 |
* ============================================================================
|
17 |
*/
|
18 |
/*
|
19 |
$Id: DocumentSerializer.java 5251 2006-08-02 18:51:26Z caronr $
|
20 |
$HeadURL: http://nlwis-ms.agr.gc.ca/data/SVN/RESEARCH/sandbox/frogs/wps-plugin-0.4.0/src/org/tigris/frogs/plugin/wpsint/impl_0_4_0/DocumentSerializer.java $
|
21 |
*/
|
22 |
|
23 |
|
24 |
package org.tigris.frogs.parsers.ows; |
25 |
|
26 |
import java.io.ByteArrayOutputStream; |
27 |
import java.io.ByteArrayInputStream; |
28 |
|
29 |
import javax.xml.bind.JAXBException; |
30 |
|
31 |
import org.tigris.frogs.commons.Constants.Charsets; |
32 |
import org.tigris.frogs.ows.reportexception.DocumentErrors; |
33 |
|
34 |
|
35 |
/**
|
36 |
* To be documented
|
37 |
*
|
38 |
*/
|
39 |
public class DocumentSerializer { |
40 |
|
41 |
protected DocumentErrors documentErrors = null; |
42 |
private org.tigris.frogs.parser.ows.impl0_3_20.OWSXmlParser owsParser0_3_20 = null; |
43 |
private org.tigris.frogs.parser.ows.impl0_3_0.OWSXmlParser owsParser0_3_0 = null; |
44 |
private org.tigris.frogs.parser.ows.impl1_0_0.OWSXmlParser owsParser1_0_0 = null; |
45 |
private org.tigris.frogs.parser.ows.impl1_1_0.OWSXmlParser owsParser1_1_0 = null; |
46 |
|
47 |
public DocumentSerializer() throws JAXBException { |
48 |
this.owsParser0_3_20 = new org.tigris.frogs.parser.ows.impl0_3_20.OWSXmlParser(); |
49 |
this.owsParser0_3_0 = new org.tigris.frogs.parser.ows.impl0_3_0.OWSXmlParser(); |
50 |
this.owsParser1_0_0 = new org.tigris.frogs.parser.ows.impl1_0_0.OWSXmlParser(); |
51 |
this.owsParser1_1_0 = new org.tigris.frogs.parser.ows.impl1_1_0.OWSXmlParser(); |
52 |
} |
53 |
|
54 |
/**
|
55 |
* To be documented
|
56 |
*
|
57 |
* @return org.tigris.frogs.ows.reportexception.DocumentErrors
|
58 |
*
|
59 |
*/
|
60 |
public DocumentErrors getDocumentErrors() {
|
61 |
return this.documentErrors; |
62 |
} |
63 |
|
64 |
/**
|
65 |
* To be documented
|
66 |
*
|
67 |
* @param documentErrors
|
68 |
*
|
69 |
*/
|
70 |
public void setDocumentErrors(DocumentErrors documentErrors) { |
71 |
this.documentErrors=documentErrors;
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Is there error found?
|
76 |
*
|
77 |
*/
|
78 |
public boolean isError() { |
79 |
if ( this.documentErrors == null || |
80 |
this.documentErrors.getCountErrorsAll() != 0 ) return false; |
81 |
return true; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* To be documented
|
86 |
*
|
87 |
* @param objectToSerialize
|
88 |
* @throws Exception
|
89 |
* @return ByteArrayOutputStream
|
90 |
*
|
91 |
*/
|
92 |
public ByteArrayOutputStream marshall(Object objectToSerialize) throws Throwable { |
93 |
return marshall(objectToSerialize, Charsets.getDefault());
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* To be documented
|
98 |
*
|
99 |
* @param objectToSerialize
|
100 |
* @param encoding
|
101 |
* @throws Exception
|
102 |
* @return ByteArrayOutputStream
|
103 |
*
|
104 |
*/
|
105 |
public ByteArrayOutputStream marshall(Object objectToSerialize, String encoding) throws Throwable { |
106 |
setDocumentErrors(null);
|
107 |
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); |
108 |
|
109 |
if ( org.tigris.frogs.parsers.ows.Analyse.isVersion0_3_0(objectToSerialize) ) {
|
110 |
this.owsParser0_3_0.serialize(objectToSerialize,byteStream,encoding);
|
111 |
setDocumentErrors( this.owsParser0_3_0.getDocumentErrors() );
|
112 |
} |
113 |
|
114 |
else if ( org.tigris.frogs.parsers.ows.Analyse.isVersion0_3_20(objectToSerialize) ) { |
115 |
this.owsParser0_3_20.serialize(objectToSerialize,byteStream,encoding);
|
116 |
setDocumentErrors( this.owsParser0_3_20.getDocumentErrors() );
|
117 |
} |
118 |
|
119 |
else if ( org.tigris.frogs.parsers.ows.Analyse.isVersion1_0_0(objectToSerialize) ) { |
120 |
this.owsParser1_0_0.serialize(objectToSerialize,byteStream,encoding);
|
121 |
setDocumentErrors( this.owsParser1_0_0.getDocumentErrors() );
|
122 |
} |
123 |
|
124 |
else if ( org.tigris.frogs.parsers.ows.Analyse.isVersion1_1_0(objectToSerialize) ) { |
125 |
this.owsParser1_1_0.serialize(objectToSerialize,byteStream,encoding);
|
126 |
setDocumentErrors( this.owsParser1_1_0.getDocumentErrors() );
|
127 |
} |
128 |
|
129 |
return byteStream;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* To be documented
|
134 |
*
|
135 |
* @param xmlMessageBody
|
136 |
* @param toBeStricted
|
137 |
* @throws Exception
|
138 |
* @return Object
|
139 |
*
|
140 |
*/
|
141 |
public Object unmarshall(ByteArrayInputStream xmlMessageBody, boolean toBeStricted) throws Throwable { |
142 |
|
143 |
// Try 0.3.20 - mostly use
|
144 |
Object jaxbObject = this.owsParser0_3_20.load(xmlMessageBody,toBeStricted); |
145 |
if ( org.tigris.frogs.parsers.ows.Analyse.isAnExceptionReport(jaxbObject) ) {
|
146 |
if ( this.owsParser0_3_20.getDocumentErrors().getCountErrorsAll() == 0 ) { |
147 |
return jaxbObject;
|
148 |
} |
149 |
else {
|
150 |
setDocumentErrors(this.owsParser0_3_20.getDocumentErrors());
|
151 |
return null; |
152 |
} |
153 |
} |
154 |
|
155 |
xmlMessageBody.reset(); |
156 |
|
157 |
// Try the 1.0.0. Stage two of this implementation
|
158 |
jaxbObject = this.owsParser1_0_0.load(xmlMessageBody,toBeStricted);
|
159 |
if ( org.tigris.frogs.parsers.ows.Analyse.isAnExceptionReport(jaxbObject) ) {
|
160 |
if ( this.owsParser1_0_0.getDocumentErrors().getCountErrorsAll() == 0 ) { |
161 |
return jaxbObject;
|
162 |
} |
163 |
else {
|
164 |
setDocumentErrors(this.owsParser1_0_0.getDocumentErrors());
|
165 |
return null; |
166 |
} |
167 |
} |
168 |
|
169 |
xmlMessageBody.reset(); |
170 |
// Try 0.3.0 - stage one of this implementation
|
171 |
jaxbObject = this.owsParser0_3_0.load(xmlMessageBody,toBeStricted);
|
172 |
if ( org.tigris.frogs.parsers.ows.Analyse.isAnExceptionReport(jaxbObject) ) {
|
173 |
if ( this.owsParser0_3_0.getDocumentErrors().getCountErrorsAll() == 0 ) { |
174 |
return jaxbObject;
|
175 |
} |
176 |
else {
|
177 |
setDocumentErrors(this.owsParser0_3_0.getDocumentErrors());
|
178 |
return null; |
179 |
} |
180 |
} |
181 |
|
182 |
xmlMessageBody.reset(); |
183 |
// Try 1.1.0 - Last OWS Exception that I know of. It looks exactly like 1.0.0
|
184 |
jaxbObject = this.owsParser1_1_0.load(xmlMessageBody,toBeStricted);
|
185 |
if ( org.tigris.frogs.parsers.ows.Analyse.isAnExceptionReport(jaxbObject) )
|
186 |
if ( this.owsParser1_1_0.getDocumentErrors().getCountErrorsAll() == 0 ) |
187 |
return jaxbObject;
|
188 |
|
189 |
setDocumentErrors(this.owsParser1_1_0.getDocumentErrors());
|
190 |
return null; |
191 |
} |
192 |
|
193 |
|
194 |
|
195 |
} |