Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Header.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 
00026 package org.openmobileis.synchro.openmsp.protocol;
00027 
00036 public class Header implements Element {
00041   final static long serialVersionUID = 1L;
00042 
00043 
00044   private static String version = "1.0";
00045   protected String target;
00046   protected String source;
00047   protected long sessionID;
00048   // not used in the current version
00049   protected int msgID = 1;
00050   // credential : String[0] : Meta information and String[1] : data authentification
00051   protected String[] credential;
00052 
00053   protected Header() {}
00054 
00055   public Header(long sessionID, String source, String target) {
00056     this.target = target;
00057     this.sessionID = sessionID;
00058     this.source = source;
00059   }
00060 
00061   public Header( long sessionID, String source, String target, String credentialMeta, String credentialData) {
00062       this(sessionID, source, target);
00063       credential = new String[2];
00064       credential[0] = credentialMeta;
00065       credential[1] = credentialData;
00066   }
00067 
00068   public boolean hasCommmandId() {
00069     return false;
00070   }
00071 
00072   public int getElementType() {
00073     return Element.HEADER;
00074   }
00075 
00076   public int getCmdId() {
00077     return 0;
00078   }
00079 
00080 
00081   public int getMsgId() {
00082     return msgID;
00083     }
00084 
00085   public long getSessionID() {
00086     return sessionID;
00087     }
00088 
00089   public String getSource() {
00090     return source;
00091     }
00092 
00093   public String getTarget() {
00094     return target;
00095     }
00096 
00097   public void setCredential (String meta, String data) {
00098     credential = new String[2];
00099     credential[0] = meta;
00100     credential[1] = data;
00101   }
00102 
00103   public String[] getCredential() {
00104     return credential;
00105    }
00106 
00107   public String getVersion() {
00108     return version;
00109     }
00110 
00111   public String toString() {
00112     return " header : sessionID " + sessionID + " source : " + source + " target : " + target;
00113   }
00114 
00115   //************ implements Element inferface **********
00116 
00117    public void setCmdId (int cmdId) {}
00118 
00119    public void setElementType(int elementType) {}
00120 
00121    public void setCredentialData (String data) {
00122      if (credential == null)
00123         credential = new String[2];
00124     credential[1] = data;
00125    }
00126 
00127    public void setCredentialMeta (String meta){
00128       if (credential == null)
00129           credential = new String[2];
00130       credential[0] = meta;
00131    }
00132 
00133    public void setSource(String source){
00134       this.source = source;
00135    }
00136 
00137    public void setTarget (String target){
00138       this.target = target;
00139    }
00140 
00141    public void setMetaInformation (String meta){}
00142 
00143    public void setCmdRef (int cmdRef){}
00144 
00145    public void setSourceRef(String source){}
00146 
00147    public void setSourceSessionID(long sessionid){
00148    // do nothing by default
00149    }
00150 
00151    public void setTargetRef(String target){}
00152 
00153    public void setData (String data){ }
00154 
00155   public void setSessionID(long ns) {
00156     sessionID = ns;
00157   }
00158 
00159   public void writeBeginTag(StringBuffer buffer) {
00160     MessageFactory.writeBeginTag(buffer, MessageFactory.TAG_HEADER);
00161     buffer.append("\n");
00162   }
00163 
00164    public void writeEndTag(StringBuffer buffer) {
00165      MessageFactory.writeEndTag(buffer, MessageFactory.TAG_HEADER);
00166      buffer.append("\n");
00167   }
00168 
00169  public void writeContent(StringBuffer buffer) {
00170     MessageFactory.writeElement(buffer, MessageFactory.TAG_VERSION, version);
00171     buffer.append("\n");
00172     MessageFactory.writeElement(buffer, MessageFactory.TAG_SESSION, String.valueOf(sessionID));
00173     buffer.append("\n");
00174     MessageFactory.writeElement(buffer, MessageFactory.TAG_MSGID, String.valueOf(msgID));
00175     buffer.append("\n");
00176     MessageFactory.writeSource(buffer, source, -1);
00177     buffer.append("\n");
00178     MessageFactory.writeTarget(buffer, target);
00179     buffer.append("\n");
00180     if (credential != null) {
00181         MessageFactory.writeCredential(buffer, credential[0], credential[1]);
00182         buffer.append("\n");
00183     }
00184  }
00185 
00186 }

Generated on Wed Dec 14 21:05:33 2005 for OpenMobileIS by  doxygen 1.4.4