-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
81 lines (53 loc) · 3.02 KB
/
Solution.java
File metadata and controls
81 lines (53 loc) · 3.02 KB
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
//And I saw the dead, small and great, stand before God; and the books were opened: and another book was opened, which is the book of life: and the dead were judged out of those things which were written in the books, according to their works. (Revelation 20:12)
package com.javarush.task.task33.task3308;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
/*
Создание класса по строке xml
*/
public class Solution {
public static void main(String[] args) throws JAXBException {
String xmlData =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<shop>\n" +
" <goods>\n" +
" <names>S1</names>\n" +
" <names>S2</names>\n" +
" </goods>\n" +
" <count>12</count>\n" +
" <profit>123.4</profit>\n" +
" <secretData>String1</secretData>\n" +
" <secretData>String2</secretData>\n" +
" <secretData>String3</secretData>\n" +
" <secretData>String4</secretData>\n" +
" <secretData>String5</secretData>\n" +
"</shop>";
StringReader reader = new StringReader(xmlData);
JAXBContext context = JAXBContext.newInstance(getClassName());
Unmarshaller unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(reader);
System.out.println(o.toString());
}
public static Class getClassName() {
return new Shop ().getClass();
}
}
/*
Создание класса по строке xml
Восстанови класс по переданной строке xml.
Класс должен быть в отдельном файле.
Метод getClassName должен возвращать восстановленный класс.
Метод main не участвует в тестировании.
Требования:
1. Класс Shop должен быть создан в отдельном файле.
2. В классе Shop должно быть создано поле goods типа Goods.
3. В классе Shop должно быть создано поле count типа int.
4. В классе Shop должно быть создано поле profit типа double.
5. В классе Shop должен быть создан массив строк secretData.
6. В классе Shop должен содержаться вложенный статический класс Goods.
7. В классе Shop.Goods должен быть создан список строк names.
8. Все поля класса Shop должны быть публичными.
9. Метод getClassName класса Solution должен возвращать класс Shop.
*/