Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencloud/slee/services/sip/registrar/RegistrationBinding.java


1   package com.opencloud.slee.services.sip.registrar;
2   
3   import java.io.Serializable;
4   import java.util.Calendar;
5   import java.util.Date;
6   
7   import javax.sip.address.Address;
8   import javax.sip.address.URI;
9   import javax.sip.header.ContactHeader;
10  
11  public class RegistrationBinding implements Serializable {
12  
13      // This date stores the absolute time when this entry will expire
14      private Date expiry;
15  
16      private float qValue;
17      private String callId;
18      private long cSeq;
19      
20      private String comment;
21      private String contactAddress;
22  
23      public RegistrationBinding(String contactAddress, String comment, long expiresDelta, float q, String id, long seq) {
24          this.comment = comment;
25          this.contactAddress = contactAddress;
26          setExpiryDelta(expiresDelta);
27          this.qValue = q;
28          this.callId = id;
29          this.cSeq = seq;
30      }
31  
32      public long getExpiryAbsolute() { return (expiry.getTime()/1000); }
33  
34      /**
35       * Returns number of seconds till this entry expires
36       * May be 0 or -ve if already expired
37       */
38      public int getExpiryDelta() {
39          int expiryDelta = (int)(expiry.getTime() - System.currentTimeMillis());
40          return (expiryDelta / 1000) + 1;  // +1 to round up to nearest second...
41      }
42      
43      public String getContactAddress() { return contactAddress; }
44      public float getQValue() { return qValue; }
45      public String getCallId() { return callId; }
46      public long getCSeq() { return cSeq; }
47      public String getComment() { return comment; }
48  
49      public void setExpiryAbsolute(long exp) {
50      
51          this.expiry = new Date(exp * 1000);
52      }
53  
54      public void setExpiryDelta(long exp) {
55          Calendar now = Calendar.getInstance();
56          now.add(Calendar.SECOND, (int)exp);
57          expiry = now.getTime();
58      }
59  
60      public void setContactAddress(String address) {
61          this.contactAddress = address;
62      }
63  
64      public void setQValue(float q) {
65          this.qValue = q;
66      }
67  
68      public void setCallId(String id) {
69          this.callId = id;
70      }
71  
72      public void setCSeq(long seq) {
73          this.cSeq = seq;
74      }
75  
76      public void setComment(String comment) {
77          this.comment = comment;
78      }
79      
80      private String getScheme(String contactAddress) {
81          int i = contactAddress.indexOf(':');
82          if (i != -1) {
83              return contactAddress.substring(0, i);
84          }
85          else {
86              return null;
87          }
88      }
89  
90      private String getSchemeData(String contactAddress) {
91          int i = contactAddress.indexOf(':');
92          if (i != -1) {  
93              return contactAddress.substring(i + 1, contactAddress.length());
94          }
95          else {
96              return null;
97          }
98      }  
99      
100     public ContactHeader getContactHeader(javax.sip.address.AddressFactory af, javax.sip.header.HeaderFactory hf) {
101         try {
102             long expires = getExpiryDelta();
103             if (expires <= 0) {
104                 // This binding has expired
105                 return null;
106             }
107             
108             String contactAddress = getContactAddress();
109 
110             URI uri = af.createURI(contactAddress);                 // todo : needs scheme:address
111             Address nameAddress = af.createAddress(uri);
112 
113             javax.sip.header.ContactHeader contact = hf.createContactHeader(nameAddress);
114             // String comment = getComment();
115             contact.setExpires(getExpiryDelta());
116             contact.setQValue(getQValue());
117             
118             return contact;
119 
120         } catch (Exception e) {
121             System.out.println(e.toString());
122             return null;
123         }
124 
125     }
126 
127 
128   public String toString() {
129     return "[" + contactAddress + "," + comment + "," +
130       expiry + "," + qValue + "," + callId + "," + cSeq + "]";
131   }
132     
133 }