Mercurial > hg > RemoteEditor > REPSessionManager
changeset 41:86a1553028ad
*** empty log message ***
author | pin |
---|---|
date | Sat, 10 Nov 2007 21:35:40 +0900 |
parents | 5c0cd6c01ba8 |
children | 7bf547c009ed |
files | rep/SessionList.java rep/xml/SessionXMLDecoder.java test/SessionXMLEncoder.java test/XMLTest.java |
diffstat | 4 files changed, 35 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/SessionList.java Sat Nov 10 21:12:01 2007 +0900 +++ b/rep/SessionList.java Sat Nov 10 21:35:40 2007 +0900 @@ -28,13 +28,11 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import test.SessionXMLEncoder; +import rep.xml.SessionXMLEncoder; public class SessionList { - //List<LinkedList<SocketChannel>> sessions = new LinkedList<LinkedList<SocketChannel>>(); - //Hashtable<Integer, LinkedList<SocketChannel>> sessions2 = new Hashtable<Integer, LinkedList<SocketChannel>>(); - Hashtable<Integer, Session> session3 = new Hashtable<Integer, Session>(); +// Hashtable<Integer, Session> session3 = new Hashtable<Integer, Session>(); LinkedList<Session> session4 = new LinkedList<Session>(); LinkedList<String> stringlist = new LinkedList<String>(); private int sessionID = 0; @@ -53,8 +51,8 @@ } public void makeDefaultSession(){ - session3.put(0, new Session(0, null, null)); - //session4.add(new Session(0, "defaul", smchannel)); +// session3.put(0, new Session(0, null, null)); + session4.add(0, new Session(0, null, null)); } public int getEditorNumber() { @@ -68,11 +66,7 @@ public int addSession(SocketChannel channel, String string) { sessionID++; - //sessions2.put(sessionID, new LinkedList<SocketChannel>()); - //sessions.add(new LinkedList<SocketChannel>()); - //return sessions2.size(); - session3.put(sessionID, new Session(sessionID, string, channel)); - //addEditor(channel, sid, command); +// session3.put(sessionID, new Session(sessionID, string, channel)); session4.add(new Session(sessionID, string, channel)); return sessionID; @@ -80,11 +74,9 @@ public void addEditor(SocketChannel channel, int sid, REPCommand repCmd) { int editorID = repCmd.eid; - //editorCount++; - //sessions.get(sid-1).add(channel); - //sessions2.get(sid).add(channel); - if(session3.get(sid) == null) System.out.println("ぬるぽ!"); - session3.get(sid).addEditor(editorID, channel); +// if(session3.get(sid) == null) System.out.println("ぬるぽ!"); +// session3.get(sid).addEditor(editorID, channel); + session4.get(sid).addEditor(editorID, channel); //本当はforループで検索しないといけないよ。 } public int getSessionID(SocketChannel channel) { @@ -97,9 +89,8 @@ } public void sendCmd(SocketChannel channel2, REPCommand repCmd) { - //int sessionID = repCmd.sid; - //LinkedList <SocketChannel> channelList = sessions2.get(repCmd.sid); - LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); +// LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); + LinkedList <Editor> editorList = session4.get(repCmd.sid).getEditorList(); //ここもforループで検索しないといけないよ。 for(Editor editor : editorList){ SocketChannel channel = editor.getChannel(); if(channel.equals(channel2)) { @@ -112,7 +103,8 @@ } public void sendCmd(SocketChannel channel, REPCommand repCmd, boolean ring){ - LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); +// LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); + LinkedList <Editor> editorList = session4.get(repCmd.sid).getEditorList(); //ここもforループで検索しないといけないよ。 REPPacketSend repsend = null; for(Editor editor : editorList){ SocketChannel channel2 = editor.getChannel(); @@ -124,9 +116,6 @@ repsend.send(repCmd); } } - //repsend.send(repCmd); - //repCmd.setCMD(repCmd.cmd + 1); - //repsend.send(repCmd); } public void addSessionManager(SocketChannel channel, REPCommand repCmd) { @@ -134,16 +123,19 @@ } - public void sendAddedSession(REPCommand repCmd) { - repCmd.setCMD(REP.SMCMD_SM_JOIN); - REPPacketSend repSend = new REPPacketSend(smchannel); - //repSend.send(repCmd); - } +// public void sendAddedSession(REPCommand repCmd) { +// repCmd.setCMD(REP.SMCMD_SM_JOIN); +// REPPacketSend repSend = new REPPacketSend(smchannel); +// } public String getSessionList() { - if (session3 != null) { - System.out.println(session3.toString()); - return session3.toString(); +// if (session3 != null) { +// System.out.println(session3.toString()); +// return session3.toString(); +// } + if (session4 != null) { + System.out.println(session4.toString()); + return session4.toString(); } return "{}"; } @@ -151,7 +143,8 @@ public void sendToNextEditor(SocketChannel channel, REPCommand repCmd) { Editor editor2 = null; Editor editor3; - LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); +// LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); + LinkedList <Editor> editorList = session4.get(repCmd.sid).getEditorList(); //ここもforループで検索しないといけないよ。 for(Editor editor : editorList){ SocketChannel channel2 = editor.getChannel(); if(channel.equals(channel2)){ @@ -174,12 +167,13 @@ } public void addEditor(SocketChannel editorChannel, int sid, int eid) { - - session3.get(sid).addEditor(eid, editorChannel); +// session3.get(sid).addEditor(eid, editorChannel); + session4.get(sid).addEditor(eid, editorChannel); } public void sendSelect(int sid) { - SocketChannel channel = session3.get(sid).getMaster().getChannel(); +// SocketChannel channel = session3.get(sid).getMaster().getChannel(); + SocketChannel channel = session4.get(sid).getMaster().getChannel(); REPPacketSend send = new REPPacketSend(channel); send.send(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, 0, "")); } @@ -209,7 +203,7 @@ // * </SessionManager> // * <Session> // * </Session> -// */ +// * // StringWriter str = null; // try { // str = new StringWriter(); @@ -252,7 +246,7 @@ // e.printStackTrace(); // } // return str.toString(); -// } +// }*/ public LinkedList<Session> getList() { return session4; @@ -266,11 +260,8 @@ public int addSession(Session session) { sessionID++; - //sessions2.put(sessionID, new LinkedList<SocketChannel>()); - //sessions.add(new LinkedList<SocketChannel>()); - //return sessions2.size(); - session3.put(sessionID, session); - //addEditor(channel, sid, command); +// session3.put(sessionID, session); + session4.add(session); session4.add(session); return sessionID; }
--- a/rep/xml/SessionXMLDecoder.java Sat Nov 10 21:12:01 2007 +0900 +++ b/rep/xml/SessionXMLDecoder.java Sat Nov 10 21:35:40 2007 +0900 @@ -1,5 +1,5 @@ package rep.xml; public class SessionXMLDecoder { - + }
--- a/test/SessionXMLEncoder.java Sat Nov 10 21:12:01 2007 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -package test; - -import java.io.StringWriter; -import java.util.LinkedList; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import rep.Editor; -import rep.Session; -import rep.SessionList; - -public class SessionXMLEncoder { - private LinkedList<Session> list; - - public SessionXMLEncoder(SessionList list) { - } - - public SessionXMLEncoder(LinkedList<Session> session) { - this.list = session; - } - - public SessionXMLEncoder() { - // TODO Auto-generated constructor stub - } - - public String sessionListToXML() { - /* SessionListをXMLに書き出す。ときの形式 - * <Session> - * <editor> - * <sid/> - * <host/> - * <port/> - * <filename/> - * </editor> - * <editor> - * <sid/> - * <host/> - * <port/> - * </editor> - * </Session> - * <SessionManager> - * <host/> - * <port/> - * </SessionManager> - * <Session> - * </Session> - */ - StringWriter str = null; - try { - str = new StringWriter(); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.newDocument(); - Element root = doc.getDocumentElement(); - root = doc.createElement("SessionList"); - for(Session session : list){ - Element elementSession = doc.createElement("Session"); - root.appendChild(elementSession); -// Element elementeditor = doc.createElement("editor"); -// elementSession.appendChild(elementeditor); -// Editor editor = session.getMaster(); -// Element element3 = doc.createElement(editor.getHost()); -// Element element4 = doc.createElement(editor.getPort()); -// Element element5 = doc.createElement(editor.getName()); - //element5 = doc.createElement(session.getName()); -// elementeditor.appendChild(element3); -// elementeditor.appendChild(element4); -// elementeditor.appendChild(element5); - LinkedList <Editor> editorlist = session.getEditorList(); - for(Editor editor : editorlist){ - Element elementEditor = doc.createElement("Editor"); - Element elementHost = doc.createElement(editor.getHost()); - Element elementPort = doc.createElement(editor.getPort()); - Element elementName = null; - if(editor.getName() != null) { - elementName = doc.createElement(editor.getName()); - elementEditor.appendChild(elementName); - } - elementEditor.appendChild(elementHost); - elementEditor.appendChild(elementPort); -// elementEditor.appendChild(elementName); - elementSession.appendChild(elementEditor); - } - - } - doc.appendChild(root); - - TransformerFactory tfactory = TransformerFactory.newInstance(); - Transformer transformer = tfactory.newTransformer(); - StreamResult result = new StreamResult(str); - //transformer.transform(new DOMSource(doc), new StreamResult(System.out)); - transformer.transform(new DOMSource(doc), result); - System.out.println(str); - - }catch (Exception e){ - e.printStackTrace(); - } - return str.toString(); - } -}
--- a/test/XMLTest.java Sat Nov 10 21:12:01 2007 +0900 +++ b/test/XMLTest.java Sat Nov 10 21:35:40 2007 +0900 @@ -3,6 +3,7 @@ import rep.Editor; import rep.Session; import rep.SessionList; +import rep.xml.SessionXMLEncoder; public class XMLTest { @@ -16,10 +17,6 @@ Editor editor2 = new Editor(1, null); editor2.setHost("testhost2"); editor2.setPort("testport2"); - //editor2.setName("null"); - - //Session session = new Session(0, "file", null); - //session.addEditor(editor); Session session = new Session(editor); session.addEditor(editor);