0
|
1 package rep;
|
|
2
|
|
3 import java.util.LinkedList;
|
130
|
4
|
|
5 import rep.channel.REPSocketChannel;
|
41
|
6 import rep.xml.SessionXMLEncoder;
|
39
|
7
|
0
|
8 public class SessionList {
|
|
9
|
56
|
10 LinkedList<Session> sessionLinkedList = new LinkedList<Session>();
|
38
|
11 LinkedList<String> stringlist = new LinkedList<String>();
|
1
|
12 private int sessionID = 0;
|
|
13 private int editorCount = 0;
|
80
|
14 private String maxHost;
|
120
|
15
|
0
|
16
|
130
|
17 public int addSession(REPSocketChannel<REPCommand> channel, String string) {
|
0
|
18 sessionID++;
|
|
19 return sessionID;
|
|
20
|
|
21 }
|
|
22
|
|
23 public int getNumberOfEditor() {
|
|
24 editorCount++;
|
|
25 return editorCount;
|
|
26 }
|
130
|
27
|
3
|
28 public String getSessionList() {
|
56
|
29 if (sessionLinkedList != null) {
|
337
|
30 SessionManager.logger.writeLog(
|
|
31 sessionLinkedList.toString());
|
56
|
32 return sessionLinkedList.toString();
|
3
|
33 }
|
|
34 return "{}";
|
|
35 }
|
|
36
|
8
|
37 public void sendSelect(int sid) {
|
158
|
38 REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel();
|
284
|
39 channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, ""));
|
8
|
40 }
|
|
41
|
39
|
42 // public String getXML() {
|
122
|
43 ///* SessionListをXMLに書き出す。ときの形式
|
39
|
44 // * <Session>
|
|
45 // * <editor>
|
|
46 // * <sid/>
|
|
47 // * <host/>
|
|
48 // * <port/>
|
|
49 // * <filename/>
|
|
50 // * </editor>
|
|
51 // * <editor>
|
|
52 // * <sid/>
|
|
53 // * <host/>
|
|
54 // * <port/>
|
|
55 // * </editor>
|
|
56 // * </Session>
|
|
57 // * <SessionManager>
|
|
58 // * <host/>
|
|
59 // * <port/>
|
|
60 // * </SessionManager>
|
|
61 // * <Session>
|
|
62 // * </Session>
|
41
|
63 // *
|
39
|
64 // StringWriter str = null;
|
|
65 // try {
|
|
66 // str = new StringWriter();
|
|
67 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
68 // DocumentBuilder builder = factory.newDocumentBuilder();
|
|
69 // Document doc = builder.newDocument();
|
|
70 // Element root = doc.getDocumentElement();
|
|
71 // root = doc.createElement("SessionList");
|
|
72 // for(Session session : session4){
|
|
73 // Element element = doc.createElement("Session");
|
|
74 // root.appendChild(element);
|
|
75 // Element element2 = doc.createElement("editor");
|
|
76 // element.appendChild(element2);
|
|
77 // Editor editor = session.getMaster();
|
|
78 // Element element3 = doc.createElement(editor.getHost());
|
|
79 // Element element4 = doc.createElement(editor.getPort());
|
|
80 // Element element5 = doc.createElement(editor.getName());
|
|
81 // element5 = doc.createElement(session.getName());
|
|
82 // element2.appendChild(element3);
|
|
83 // element2.appendChild(element4);
|
|
84 // element2.appendChild(element5);
|
|
85 //
|
|
86 // }
|
|
87 // doc.appendChild(root);
|
38
|
88 //
|
39
|
89 // TransformerFactory tfactory = TransformerFactory.newInstance();
|
|
90 // Transformer transformer = tfactory.newTransformer();
|
|
91 // StreamResult result = new StreamResult(str);
|
|
92 // //transformer.transform(new DOMSource(doc), new StreamResult(System.out));
|
|
93 // transformer.transform(new DOMSource(doc), result);
|
|
94 // System.out.println(str);
|
|
95 ////
|
|
96 //// XMLEncoder e = new XMLEncoder(System.out);
|
|
97 //// e.writeObject(session4);
|
|
98 //// e.writeObject(stringlist);
|
|
99 //// e.close();
|
|
100 //
|
|
101 // //System.out.println(doc);
|
|
102 // }catch (Exception e){
|
|
103 // e.printStackTrace();
|
|
104 // }
|
|
105 // return str.toString();
|
41
|
106 // }*/
|
39
|
107
|
|
108 public LinkedList<Session> getList() {
|
56
|
109 return sessionLinkedList;
|
39
|
110 }
|
|
111
|
|
112 public String toXML() {
|
56
|
113 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionLinkedList);
|
39
|
114 encoder.sessionListToXML();
|
|
115 return null;
|
|
116 }
|
|
117
|
|
118 public int addSession(Session session) {
|
|
119 sessionID++;
|
56
|
120 session.setSID(sessionID);
|
|
121 sessionLinkedList.add(session);
|
39
|
122 return sessionID;
|
38
|
123 }
|
|
124
|
66
|
125 public Session getSession(int sid) {
|
120
|
126 for(Session session : sessionLinkedList){
|
|
127 if(session.getSID() == sid){
|
|
128 return session;
|
|
129 }
|
|
130 }
|
66
|
131 return sessionLinkedList.get(sid - 1);
|
|
132 }
|
|
133
|
80
|
134 public void setMaxHost(String myHost) {
|
|
135 maxHost = myHost;
|
77
|
136 }
|
|
137
|
82
|
138 public String getMaxHost() {
|
80
|
139 return maxHost;
|
77
|
140 }
|
|
141
|
|
142 public void setList(LinkedList<Session> list) {
|
|
143 sessionLinkedList = list;
|
|
144 }
|
|
145
|
0
|
146 }
|