-
Notifications
You must be signed in to change notification settings - Fork 188
/
JaxbTestUtil.java
686 lines (597 loc) · 25.7 KB
/
JaxbTestUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/*
* Copyright (c) 2010-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.prism.impl.util;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.*;
import javax.xml.namespace.QName;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.Validate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.impl.schema.SchemaRegistryImpl;
import com.evolveum.midpoint.prism.schema.SchemaDescription;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
/**
* DEPRECATED as of May 12, 2014. MidPoint data structures are not to be processed by JAXB any more.
* (The last drop was the inability to hide RawType from externally-visible model service WSDL.
* The solution devised, based on @Raw type, prevents JAXB from correctly parsing any structures that
* contain RawType elements.)
* <p>
* So, don't use JaxbTestUtil even for testing purposes. Use PrismTestUtil instead.
* <p>
* Original description:
* <p>
* JAXB testing util. Only for use in tests. DO NOT USE IN PRODUCTION CODE.
* This util is used to test the ablility of prism JAXB representation to be used by
* native (Sun) JAXB code.
* <p>
* Note: this is what used to be PrismJaxbProcessor. Therefore there may be still a lot of junk to clean up.
*
* @author Radovan Semancik
*/
@Deprecated
public final class JaxbTestUtil {
private static final QName DEFAULT_ELEMENT_NAME = new QName("http://midpoint.evolveum.com/xml/ns/test/whatever-1.xsd", "whatever");
private static final Trace LOGGER = TraceManager.getTrace(JaxbTestUtil.class);
private PrismContext prismContext;
private JAXBContext context;
private static JaxbTestUtil instance;
public static JaxbTestUtil getInstance() {
if (instance == null) {
instance = new JaxbTestUtil();
instance.prismContext = PrismTestUtil.getPrismContext();
instance.initialize();
}
return instance;
}
private JaxbTestUtil() {
}
public PrismContext getPrismContext() {
return prismContext;
}
private SchemaRegistry getSchemaRegistry() {
return prismContext.getSchemaRegistry();
}
public void initialize() {
StringBuilder sb = new StringBuilder();
Iterator<Package> iterator = getSchemaRegistry().getCompileTimePackages().iterator();
while (iterator.hasNext()) {
Package jaxbPackage = iterator.next();
sb.append(jaxbPackage.getName());
if (iterator.hasNext()) {
sb.append(":");
}
}
String jaxbPaths = sb.toString();
if (jaxbPaths.isEmpty()) {
LOGGER.debug("No JAXB paths, skipping creation of JAXB context");
} else {
try {
context = JAXBContext.newInstance(jaxbPaths);
} catch (JAXBException ex) {
throw new SystemException("Couldn't create JAXBContext for: " + jaxbPaths, ex);
}
}
}
public JAXBContext getContext() {
return context;
}
public void setContext(JAXBContext context) {
this.context = context;
}
public boolean isJaxbClass(Class<?> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("No class, no fun");
}
if (clazz.getPackage() == null) {
// No package: this is most likely a primitive type and definitely
// not a JAXB class
return false;
}
for (Package jaxbPackage : getSchemaRegistry().getCompileTimePackages()) {
if (jaxbPackage.equals(clazz.getPackage())) {
return true;
}
}
return false;
}
public boolean canConvert(Class<?> clazz) {
return isJaxbClass(clazz);
}
public boolean canConvert(QName xsdType) {
SchemaDescription schemaDesc = getSchemaRegistry().findSchemaDescriptionByNamespace(xsdType.getNamespaceURI());
if (schemaDesc == null) {
return false;
}
if (schemaDesc.getCompileTimeClassesPackage() == null) {
return false;
}
// We may be answering "yes" to a broader set of types that we can really convert.
// But that does not matter that much. If the type is in the correct namespace
// then either we can convert it or nobody can.
return true;
// Following code is not really correct. There are XSD types that we can convert and there is
// no complexTypeDefinition for then in our parsed schema. E.g. all the property JAXB types.
// ComplexTypeDefinition complexTypeDefinition = schema.findComplexTypeDefinition(xsdType);
// return complexTypeDefinition != null;
}
private Marshaller createMarshaller(Map<String, Object> jaxbProperties) throws JAXBException {
Marshaller marshaller = context.createMarshaller();
// set default properties
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
DynamicNamespacePrefixMapper namespacePrefixMapper = ((SchemaRegistryImpl) getSchemaRegistry()).getNamespacePrefixMapper().clone();
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", namespacePrefixMapper);
// set custom properties
if (jaxbProperties != null) {
for (Entry<String, Object> property : jaxbProperties.entrySet()) {
marshaller.setProperty(property.getKey(), property.getValue());
}
}
return marshaller;
}
/**
* Allow for pooling and other fancy stuff. Now it dumb, creates in every call.
*/
private Marshaller getMarshaller() throws JAXBException {
return createMarshaller(null);
}
private Unmarshaller createUnmarshaller() throws JAXBException {
return context.createUnmarshaller();
}
/**
* Allow for pooling and other fancy stuff. Now it dumb, creates in every call.
*/
public Unmarshaller getUnmarshaller() throws JAXBException {
return createUnmarshaller();
}
public String marshalToString(Objectable objectable) throws JAXBException {
return marshalToString(objectable, new HashMap<>());
}
public String marshalToString(Objectable objectable, Map<String, Object> properties) throws JAXBException {
QName elementQName = determineElementQName(objectable);
JAXBElement<Object> jaxbElement = new JAXBElement<Object>(elementQName, (Class) objectable.getClass(), objectable);
return marshalElementToString(jaxbElement, properties);
}
public String marshalElementToString(JAXBElement<?> jaxbElement) throws JAXBException {
return marshalElementToString(jaxbElement, new HashMap<>());
}
public String marshalElementToString(JAXBElement<?> jaxbElement, Map<String, Object> properties) throws JAXBException {
StringWriter writer = new StringWriter();
Marshaller marshaller = getMarshaller();
for (Entry<String, Object> entry : properties.entrySet()) {
marshaller.setProperty(entry.getKey(), entry.getValue());
}
marshaller.marshal(jaxbElement, writer);
return writer.getBuffer().toString();
}
public String marshalElementToString(Object element) throws JAXBException {
return marshalElementToString(element, new HashMap<>());
}
/**
* Serializes DOM or JAXB element to string
*/
public String marshalElementToString(Object element, Map<String, Object> properties) throws JAXBException {
if (element == null) {
return null;
}
if (element instanceof Element) {
return DOMUtil.serializeDOMToString((Element) element);
} else if (element instanceof JAXBElement) {
return marshalElementToString((JAXBElement<?>) element, properties);
} else {
throw new IllegalArgumentException("Unsupported element type " + element.getClass().getName());
}
}
/**
* Serializes DOM or JAXB element to string, using specified elementName if needed.
*/
public String marshalElementToString(Object element, QName elementName) throws JAXBException {
if (element == null) {
return null;
}
if (element instanceof Element) {
return DOMUtil.serializeDOMToString((Element) element);
} else if (element instanceof JAXBElement) {
return marshalElementToString((JAXBElement<?>) element);
} else {
JAXBElement<Object> jaxbElement = new JAXBElement<>(elementName, Object.class, element);
return marshalElementToString(jaxbElement);
}
}
public void marshalToDom(Objectable objectable, Node parentNode) throws JAXBException {
QName elementQName = determineElementQName(objectable);
JAXBElement<Object> jaxbElement = new JAXBElement<Object>(elementQName, (Class) objectable.getClass(), objectable);
marshalElementToDom(jaxbElement, parentNode);
}
public void marshalElementToDom(JAXBElement<?> jaxbElement, Node parentNode) throws JAXBException {
getMarshaller().marshal(jaxbElement, parentNode);
}
public <T> Element marshalElementToDom(JAXBElement<T> jaxbElement, Document doc) throws JAXBException {
if (doc == null) {
doc = DOMUtil.getDocument();
}
Element element = doc.createElementNS(jaxbElement.getName().getNamespaceURI(), jaxbElement.getName().getLocalPart());
marshalElementToDom(jaxbElement, element);
return (Element) element.getFirstChild();
}
public <T> Element marshalObjectToDom(T jaxbObject, QName elementQName) throws JAXBException {
return marshalObjectToDom(jaxbObject, elementQName, (Document) null);
}
public String marshalContainerableToString(Containerable containerable) throws JAXBException {
return marshalObjectToString(containerable, determineElementQName(containerable));
}
public <T> String marshalObjectToString(T jaxbObject, QName elementQName) throws JAXBException {
JAXBElement<Object> jaxbElement = new JAXBElement<Object>(elementQName, (Class) jaxbObject.getClass(), jaxbObject);
return marshalElementToString(jaxbElement);
}
public <T> Element marshalObjectToDom(T jaxbObject, QName elementQName, Document doc) throws JAXBException {
if (doc == null) {
doc = DOMUtil.getDocument();
}
JAXBElement<T> jaxbElement = new JAXBElement<>(elementQName, (Class<T>) jaxbObject.getClass(),
jaxbObject);
Element element = doc.createElementNS(elementQName.getNamespaceURI(), elementQName.getLocalPart());
marshalElementToDom(jaxbElement, element);
return (Element) element.getFirstChild();
}
public <T> void marshalObjectToDom(T jaxbObject, QName elementQName, Element parentElement) throws JAXBException {
JAXBElement<T> jaxbElement = new JAXBElement<>(elementQName, (Class<T>) jaxbObject.getClass(),
jaxbObject);
marshalElementToDom(jaxbElement, parentElement);
}
public Element toDomElement(Object element) throws JAXBException {
return toDomElement(element, DOMUtil.getDocument());
}
public Element toDomElement(Object jaxbElement, Document doc) throws JAXBException {
return toDomElement(jaxbElement, doc, false, false, false);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Element toDomElement(Object jaxbElement, Document doc, boolean adopt, boolean clone, boolean deep) throws JAXBException {
if (jaxbElement == null) {
return null;
}
if (jaxbElement instanceof Element) {
Element domElement = (Element) jaxbElement;
if (clone) {
domElement = (Element) domElement.cloneNode(deep);
}
if (domElement.getOwnerDocument().equals(doc)) {
return domElement;
}
if (adopt) {
doc.adoptNode(domElement);
}
return domElement;
} else if (jaxbElement instanceof JAXBElement) {
return marshalElementToDom((JAXBElement) jaxbElement, doc);
} else {
throw new IllegalArgumentException("Not an element: " + jaxbElement + " ("
+ jaxbElement.getClass().getName() + ")");
}
}
public <T> JAXBElement<T> unmarshalElement(String xmlString, Class<T> type) throws JAXBException, SchemaException {
if (xmlString == null) {
return null;
}
xmlString = xmlString.trim();
if (!xmlString.startsWith("<") || !xmlString.endsWith(">")) {
throw new IllegalArgumentException("Provided string is unlikely to be an XML");
}
StringReader reader = null;
try {
reader = new StringReader(xmlString);
JAXBElement<T> element = unmarshalElement(reader, type);
adopt(element);
return element;
} finally {
if (reader != null) {
IOUtils.closeQuietly(reader);
}
}
}
public <T> T unmarshalObject(InputStream input, Class<T> type) throws JAXBException, SchemaException {
Object object = getUnmarshaller().unmarshal(input);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
if (jaxbElement == null) {
return null;
}
T value = jaxbElement.getValue();
// adopt not needed, already adopted in unmarshalElement call above
return value;
}
public <T> T unmarshalObject(InputStream input) throws JAXBException, SchemaException {
Object object = getUnmarshaller().unmarshal(input);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
if (jaxbElement == null) {
return null;
}
T value = jaxbElement.getValue();
// adopt not needed, already adopted in unmarshalElement call above
return value;
}
public <T> JAXBElement<T> unmarshalElement(Reader reader, Class<T> type) throws JAXBException, SchemaException {
Object object = getUnmarshaller().unmarshal(reader);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
return jaxbElement;
}
public <T> T unmarshalToObject(Node node, Class<T> type) throws JAXBException, SchemaException {
JAXBElement<T> element = unmarshalElement(node, type);
if (element == null) {
return null;
}
adopt(element);
return element.getValue();
}
public <T> JAXBElement<T> unmarshalElement(Node node, Class<T> type) throws JAXBException, SchemaException {
Object object = createUnmarshaller().unmarshal(node);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
return jaxbElement;
}
public <T> T unmarshalObject(File file, Class<T> type) throws JAXBException, SchemaException, FileNotFoundException {
JAXBElement<T> element = unmarshalElement(file, type);
if (element == null) {
return null;
}
T value = element.getValue();
// adopt not needed, already adopted in unmarshalElement call above
if (!type.isAssignableFrom(value.getClass())) {
throw new IllegalArgumentException("Unmarshalled " + value.getClass() + " from file " + file + " while " + type + " was expected");
}
return value;
}
public Object unmarshalObjects(File file) throws JAXBException {
return createUnmarshaller().unmarshal(file);
}
public <T> T unmarshalObject(String stringXml, Class<T> type) throws JAXBException, SchemaException {
JAXBElement<T> element = unmarshalElement(stringXml, type);
if (element == null) {
return null;
}
T value = element.getValue();
adopt(value, type);
return value;
}
// element name must correspond to the name that points to the container definition
public <T extends Containerable> PrismContainer<T> unmarshalSingleValueContainer(File file, Class<T> type) throws JAXBException, SchemaException, FileNotFoundException {
return unmarshalSingleValueContainer(unmarshalElement(file, type));
}
// element name must correspond to the name that points to the container definition
public <T extends Containerable> PrismContainer<T> unmarshalSingleValueContainer(String stringXml, Class<T> type) throws JAXBException, SchemaException {
return unmarshalSingleValueContainer(unmarshalElement(stringXml, type));
}
// element name must correspond to the name that points to the container definition
private <T extends Containerable> PrismContainer<T> unmarshalSingleValueContainer(JAXBElement<T> element) throws JAXBException, SchemaException {
if (element == null) {
return null;
}
T value = element.getValue();
// this is a bit tricky - we have to create a container and put the newly obtained value into it
PrismContainerValue<T> containerValue = value.asPrismContainerValue();
containerValue.revive(prismContext);
PrismContainerDefinition<T> definition = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(element.getName());
if (definition == null) {
throw new IllegalStateException("There's no container definition for element name " + element.getName());
}
containerValue.applyDefinition(definition, false);
PrismContainer container = definition.instantiate();
container.add(containerValue);
return container;
}
public <T> T unmarshalObject(Object domOrJaxbElement, Class<T> type) throws SchemaException {
JAXBElement<T> element;
if (domOrJaxbElement instanceof JAXBElement<?>) {
element = (JAXBElement<T>) domOrJaxbElement;
} else if (domOrJaxbElement instanceof Node) {
try {
element = unmarshalElement((Node) domOrJaxbElement, type);
} catch (JAXBException e) {
throw new SchemaException(e.getMessage(), e);
}
} else {
throw new IllegalArgumentException("Unknown element type " + domOrJaxbElement);
}
if (element == null) {
return null;
}
T value = element.getValue();
adopt(value, type);
return value;
}
public <T> JAXBElement<T> unmarshalElement(File file, Class<T> type) throws SchemaException, FileNotFoundException, JAXBException {
if (file == null) {
throw new IllegalArgumentException("File argument must not be null.");
}
InputStream is = null;
try {
is = new FileInputStream(file);
JAXBElement<T> element = (JAXBElement<T>) getUnmarshaller().unmarshal(is);
adopt(element);
return element;
} catch (RuntimeException ex) {
throw new SystemException(ex);
} finally {
if (is != null) {
IOUtils.closeQuietly(is);
}
}
}
public <T> JAXBElement<T> unmarshalElement(InputStream is, Class<T> type) throws SchemaException, FileNotFoundException, JAXBException {
try {
JAXBElement<T> element = (JAXBElement<T>) getUnmarshaller().unmarshal(is);
adopt(element);
return element;
} finally {
if (is != null) {
IOUtils.closeQuietly(is);
}
}
}
public <T> T unmarshalRootObject(File file, Class<T> type) throws JAXBException, FileNotFoundException, SchemaException {
Validate.notNull(file, "File must not be null.");
InputStream is = null;
try {
is = new FileInputStream(file);
T object = (T) getUnmarshaller().unmarshal(is);
adopt(object);
return object;
} finally {
if (is != null) {
IOUtils.closeQuietly(is);
}
}
}
public boolean compareAny(List<Object> a, List<Object> b) {
if (a == b) {
return true;
}
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
if (a.size() != b.size()) {
return false;
}
for (int i = 0; i < a.size(); i++) {
if (!compareElement(a.get(i), b.get(i))) {
return false;
}
}
return true;
}
@SuppressWarnings("unchecked")
private boolean compareElement(Object a, Object b) {
if (a == b) {
return true;
}
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
Document doc = null;
Element ae = null;
Element be = null;
if (a instanceof Element) {
ae = (Element) a;
} else if (a instanceof JAXBElement) {
if (doc == null) {
doc = DOMUtil.getDocument();
}
try {
ae = marshalElementToDom((JAXBElement) a, doc);
} catch (JAXBException e) {
throw new IllegalStateException("Failed to marshall element " + a, e);
}
} else {
throw new IllegalArgumentException("Got unexpected type " + a.getClass().getName() + ": " + a);
}
if (b instanceof Element) {
be = (Element) b;
} else if (a instanceof JAXBElement) {
if (doc == null) {
doc = DOMUtil.getDocument();
}
try {
be = marshalElementToDom((JAXBElement) a, doc);
} catch (JAXBException e) {
throw new IllegalStateException("Failed to marshall element " + b, e);
}
} else {
throw new IllegalArgumentException("Got unexpected type " + b.getClass().getName() + ": " + b);
}
return DOMUtil.compareElement(ae, be, true);
}
public <T> T fromElement(Object element, Class<T> type) throws SchemaException {
if (element == null) {
return null;
}
if (type.isAssignableFrom(element.getClass())) {
return (T) element;
}
if (element instanceof JAXBElement) {
if (((JAXBElement) element).getValue() == null) {
return null;
}
if (type.isAssignableFrom(((JAXBElement) element).getValue().getClass())) {
return (T) ((JAXBElement) element).getValue();
}
}
if (element instanceof Element) {
try {
JAXBElement<T> unmarshalledElement = unmarshalElement((Element) element, type);
return unmarshalledElement.getValue();
} catch (JAXBException e) {
throw new IllegalArgumentException("Unmarshall failed: " + e.getMessage(), e);
}
}
throw new IllegalArgumentException("Unknown element type " + element.getClass().getName());
}
private QName determineElementQName(Objectable objectable) {
PrismObject<?> prismObject = objectable.asPrismObject();
if (prismObject.getElementName() != null) {
return prismObject.getElementName();
}
PrismObjectDefinition<?> definition = prismObject.getDefinition();
if (definition != null) {
if (definition.getItemName() != null) {
return definition.getItemName();
}
}
throw new IllegalStateException("Cannot determine element name of " + objectable);
}
private QName determineElementQName(Containerable containerable) {
PrismContainerValue prismContainerValue = containerable.asPrismContainerValue();
PrismContainerDefinition<?> definition = prismContainerValue.getParent() != null ? prismContainerValue.getParent().getDefinition() : null;
if (definition != null) {
if (definition.getItemName() != null) {
return definition.getItemName();
}
}
throw new IllegalStateException("Cannot determine element name of " + containerable + " (parent = " + prismContainerValue.getParent() + ", definition = " + definition + ")");
}
private boolean isObjectable(Class type) {
return Objectable.class.isAssignableFrom(type);
}
private <T> void adopt(T object, Class<T> type) throws SchemaException {
if (object instanceof Objectable) {
getPrismContext().adopt(((Objectable) object));
}
}
private void adopt(Object object) throws SchemaException {
if (object instanceof JAXBElement) {
adopt(((JAXBElement) object).getValue());
} else if (object instanceof Objectable) {
getPrismContext().adopt(((Objectable) (object)));
}
}
public static String marshalWrap(Object jaxbObject) throws JAXBException {
JAXBElement<Object> jaxbElement = new JAXBElement<Object>(DEFAULT_ELEMENT_NAME, (Class) jaxbObject.getClass(), jaxbObject);
return getInstance().marshalElementToString(jaxbElement);
}
}