1 /* 2 * Conditions Of Use 3 * 4 * This software was developed by employees of the National Institute of 5 * Standards and Technology (NIST), an agency of the Federal Government. 6 * Pursuant to title 15 Untied States Code Section 105, works of NIST 7 * employees are not subject to copyright protection in the United States 8 * and are considered to be in the public domain. As a result, a formal 9 * license is not needed to use the software. 10 * 11 * This software is provided by NIST as a service and is expressly 12 * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15 * AND DATA ACCURACY. NIST does not warrant or make any representations 16 * regarding the use of the software or the results thereof, including but 17 * not limited to the correctness, accuracy, reliability or usefulness of 18 * the software. 19 * 20 * Permission to use this software is contingent upon your acceptance 21 * of the terms of this agreement 22 * 23 * . 24 * 25 */ 26 /******************************************* 27 * PRODUCT OF PT INOVACAO - EST DEPARTMENT * 28 *******************************************/ 29 30 package gov.nist.javax.sip.header.ims; 31 32 import java.text.ParseException; 33 34 import javax.sip.header.ExtensionHeader; 35 import javax.sip.header.Parameters; 36 37 import gov.nist.core.Token; 38 39 /** 40 * P-Visited-Network-ID SIP Private Header: RFC 3455. 41 * 42 * 43 * @author ALEXANDRE MIGUEL SILVA SANTOS - Nú 10045401 44 */ 45 46 47 48 public class PVisitedNetworkID 49 extends gov.nist.javax.sip.header.ParametersHeader 50 implements PVisitedNetworkIDHeader, SIPHeaderNamesIms, ExtensionHeader { 51 52 /** 53 * visited Network ID 54 */ 55 private String networkID; 56 57 // issued by Miguel Freitas 58 private boolean isQuoted; 59 60 PVisitedNetworkID()61 public PVisitedNetworkID() { 62 63 super(P_VISITED_NETWORK_ID); 64 65 } 66 PVisitedNetworkID(String networkID)67 public PVisitedNetworkID(String networkID) { 68 69 super(P_VISITED_NETWORK_ID); 70 setVisitedNetworkID(networkID); 71 72 } 73 PVisitedNetworkID(Token tok)74 public PVisitedNetworkID(Token tok) { 75 76 super(P_VISITED_NETWORK_ID); 77 setVisitedNetworkID(tok.getTokenValue()); 78 79 } 80 encodeBody()81 protected String encodeBody() { 82 83 StringBuffer retval = new StringBuffer(); 84 85 if (getVisitedNetworkID() != null) 86 { 87 // issued by Miguel Freitas 88 if (isQuoted) 89 retval.append(DOUBLE_QUOTE + getVisitedNetworkID() + DOUBLE_QUOTE); 90 else 91 retval.append(getVisitedNetworkID()); 92 } 93 94 if (!parameters.isEmpty()) 95 retval.append(SEMICOLON + this.parameters.encode()); 96 97 return retval.toString(); 98 99 } 100 101 /** 102 * Set the visited network ID as a string. The value will be quoted in the header. 103 * @param networkID - string value 104 */ setVisitedNetworkID(String networkID)105 public void setVisitedNetworkID(String networkID) { 106 if (networkID == null) 107 throw new NullPointerException(" the networkID parameter is null"); 108 109 this.networkID = networkID; 110 111 // issued by Miguel Freitas 112 this.isQuoted = true; 113 } 114 115 /** 116 * Set the visited network ID as a token 117 * @param networkID - token value 118 */ setVisitedNetworkID(Token networkID)119 public void setVisitedNetworkID(Token networkID) { 120 if (networkID == null) 121 throw new NullPointerException(" the networkID parameter is null"); 122 123 this.networkID = networkID.getTokenValue(); 124 125 // issued by Miguel Freitas 126 this.isQuoted = false; 127 } 128 129 /** 130 * Get the visited network ID value of this header 131 */ getVisitedNetworkID()132 public String getVisitedNetworkID() { 133 return networkID; 134 } 135 136 setValue(String value)137 public void setValue(String value) throws ParseException { 138 throw new ParseException (value,0); 139 140 } 141 142 equals(Object other)143 public boolean equals(Object other) 144 { 145 if (other instanceof PVisitedNetworkIDHeader) 146 { 147 PVisitedNetworkIDHeader o = (PVisitedNetworkIDHeader) other; 148 return (this.getVisitedNetworkID().equals( o.getVisitedNetworkID() ) 149 && this.equalParameters( (Parameters) o )); 150 } 151 return false; 152 } 153 154 clone()155 public Object clone() { 156 PVisitedNetworkID retval = (PVisitedNetworkID) super.clone(); 157 if (this.networkID != null) 158 retval.networkID = this.networkID; 159 retval.isQuoted = this.isQuoted; 160 return retval; 161 } 162 163 164 } 165