⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdu.java

📁 Logica lastest SMPP API
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	}	/** Returns the command status of the PDU. */	public int getCommandStatus()	{		checkHeader();		return header.getCommandStatus();	}	/**	 * Returns the sequence number of the PDU.	 * If the PDU is created by yourself and not parsed from binary data	 * received from SMSC, then the sequence number will be very likely	 * incorrect until you didn't set it previously by calling function	 * <code>assignSequenceNumber</code> or <code>setSequenceNumber</code>.	 * @see #assignSequenceNumber()	 * @see #setSequenceNumber(int)	 */	public int getSequenceNumber()	{		checkHeader();		return header.getSequenceNumber();	}	/**	 * Sets the length of the PDU. Don't do it manually, it won't have	 * any wffect.	 */	public void setCommandLength(int cmdLen)	{		checkHeader();		header.setCommandLength(cmdLen);	}	/** Sets the command id. */	public void setCommandId(int cmdId)	{		checkHeader();		header.setCommandId(cmdId);	}	/**	 * Sets the command status, i.e. error status of the PDU.	 */	public void setCommandStatus(int cmdStatus)	{		checkHeader();		header.setCommandStatus(cmdStatus);	}	/**	 * Sets the sequence number of the PDU.	 * For PDUs whic are about to be sent to SMSC the sequence number is	 * generated automatically in the <code>Transmitter</code> class and	 * under normal cicumstances there is no need to set it explicitly.	 */	public void setSequenceNumber(int seqNr)	{		checkHeader();		header.setSequenceNumber(seqNr);		sequenceNumberChanged = true;	}	/** If the command status of the PDU is ESME_ROK. */	public boolean isOk() { return getCommandStatus() == Data.ESME_ROK; }	/**	 * If the PDU carries generic_nack despite of the class of the object.<br>	 * Under some wierd conditions there is need to "encapsulate" generic	 * negative acknowledge information into instance of class different	 * from <code>GenericNack</code> class. For example synchronous	 * call to the <code>Session</code>'s <code>submit</code> method	 * should return instance of <code>SubmitSMResp</code> class.	 * If the from some reason the SMSC returns generic_nack as a response	 * to the submit_sm, then the library must somehow overcome the type	 * checking for the return type and thus it creates instance of	 * <code>SubmitSMResp</code> but then it sets the command id	 * the id for generic_nack.	 * @return of the object carries generic_nack pdu rather than pdu	 *         as could be indicated from the object's class	 * @see com.logica.smpp.Session#checkResponse(PDU,Response)	 */	public boolean isGNack() { return getCommandId() == Data.GENERIC_NACK; }	/**	 * This method gets the buffer and returns an instance of class	 * corresponding to the type of the PDU which was in the buffer; the	 * fields of the returned PDU are set to the data from the buffer.<br>	 * Cool, isn't it.	 * @see #createPDU(int)	 */	public static final PDU createPDU(ByteBuffer buffer)	throws HeaderIncompleteException,		   MessageIncompleteException,		   UnknownCommandIdException,		   InvalidPDUException,		   TLVException,		   PDUException	{		ByteBuffer headerBuf = null;		try {			// readBytes just reads bytes from the buffer but			// doesn't alter the buffer			headerBuf = buffer.readBytes(Data.PDU_HEADER_SIZE);		} catch (NotEnoughDataInByteBufferException e) {			// incomplete header			throw new HeaderIncompleteException();		}		PDUHeader header = new PDUHeader();		try {			header.setData(headerBuf);		} catch (NotEnoughDataInByteBufferException e) {			// must be enough, we've checked it above		}		if (buffer.length() < header.getCommandLength()) {			// not enough data in the buffer => throwing			// Receiver must wait for more data			throw new MessageIncompleteException();		}		PDU pdu = createPDU(header.getCommandId());		if (pdu != null) {			// paolo@bulksms.com: more consistent & safe to remove whatever we plan			// to read from the buffer here already - stops problems with our parsing,			// for instance, reading _too much_ data from the buffer because of an			// invalid PDU.			ByteBuffer thisMessageBuffer = null;			try {				thisMessageBuffer = buffer.removeBuffer(header.getCommandLength());			} catch (NotEnoughDataInByteBufferException e) {} // can't fail			pdu.setData(thisMessageBuffer);			//pdu.setData(buffer);			return pdu;		} else {			// if not found, throw			throw new UnknownCommandIdException(header);		}	}	/**	 * Creates an empty instance of class which represents the PDU	 * with given command id.	 */	public static final PDU createPDU(int commandId)	{		int size = pduList.size();		PDU pdu = null;		PDU newInstance = null;		for (int i = 0; i < size; i++) {			pdu = (PDU)pduList.get(i);			if (pdu != null) {				if (pdu.getCommandId() == commandId) {					try {						newInstance = (PDU)(pdu.getClass().newInstance());					} catch (IllegalAccessException e) {						// can't be illegal access, we initialised						// the list with instances of our classes					} catch (InstantiationException e) {						// can't be instantiation as we already instantiated						// at least once, for both exception see help						// for Class.newInstance()					}					return newInstance;				}			}		}		return null;	}	/**	 * Creates a list of instancies of classes which can represent a PDU.	 * This list is used in <code>createPDU</code> to create a PDU	 * from a binary buffer.	 * @see #createPDU(ByteBuffer)	 * @see #createPDU(int)	 */	static {		pduList = new Vector(30,4);		pduList.add(new BindTransmitter());		pduList.add(new BindTransmitterResp());		pduList.add(new BindReceiver());		pduList.add(new BindReceiverResp());		pduList.add(new BindTransciever());		pduList.add(new BindTranscieverResp());		pduList.add(new Unbind());		pduList.add(new UnbindResp());		pduList.add(new Outbind());		pduList.add(new SubmitSM());		pduList.add(new SubmitSMResp());		pduList.add(new SubmitMultiSM());		pduList.add(new SubmitMultiSMResp());		pduList.add(new DeliverSM());		pduList.add(new DeliverSMResp());		pduList.add(new DataSM());		pduList.add(new DataSMResp());		pduList.add(new QuerySM());		pduList.add(new QuerySMResp());		pduList.add(new CancelSM());		pduList.add(new CancelSMResp());		pduList.add(new ReplaceSM());		pduList.add(new ReplaceSMResp());		pduList.add(new EnquireLink());		pduList.add(new EnquireLinkResp());		pduList.add(new AlertNotification());		pduList.add(new GenericNack());	}	public String debugString()	{		String dbgs = "(pdu: ";		dbgs += super.debugString();		dbgs += Integer.toString(getCommandLength()); dbgs += " ";		dbgs += Integer.toHexString(getCommandId()); dbgs += " ";		dbgs += Integer.toHexString(getCommandStatus()); dbgs += " ";		if (sequenceNumberChanged) {			dbgs += Integer.toString(getSequenceNumber());		} else {			// it's likely that this will be the assigned seq number			// (in simple cases :-)			dbgs += "[" + (sequenceNumber+1) + "]";		}		dbgs += ") ";				return dbgs;	}	/** Returns debug string from provided optional parameters. */	protected String debugStringOptional(String label, Vector optionalParameters)	{		String dbgs = "";		int size = optionalParameters.size();		if (size > 0) {			dbgs += "("+label+": ";			TLV tlv = null;			for (int i = 0; i < size; i++) {				tlv = (TLV)optionalParameters.get(i);				if ((tlv != null) && (tlv.hasValue())) {					dbgs += tlv.debugString();					dbgs += " ";				}			}			dbgs += ") ";		}		return dbgs;	}	/** Returns debug string of all optional parameters. */	protected String debugStringOptional()	{		String dbgs = "";		dbgs += debugStringOptional("opt",optionalParameters);		dbgs += debugStringOptional("extraopt",extraOptionalParameters);		return dbgs;	}	/**	 * Compares two PDU. Two PDUs are equal if their sequence number is equal.	 */	public boolean equals(Object object)	{		if ((object != null) && (object instanceof PDU)) {			PDU pdu = (PDU)object;			return pdu.getSequenceNumber() == getSequenceNumber();		} else {			return false;		}	}	/**	 * Sets the PDU extra information <code>value</code> with key	 * <code>key</code>.	 * This information is not sent anywhere nor the library uses this information	 * in any means. It's intended for use by applicaitons to pass	 * information about the PDU from one part of the application to another	 * without need of extra PDU management.	 */	public void setApplicationSpecificInfo(Object key, Object value)	{		if (applicationSpecificInfo==null) {			applicationSpecificInfo = new java.util.Hashtable();		}		debug.write(DPDU,"setting app spec info key=\""+					key+"\" value=\""+(value==null?"null":value)+"\"");		applicationSpecificInfo.put(key,value);	}	/**	 * Sets the PDU extra information as a copy of existing Dictionary.	 * The Dictionary is shallow copied, i.e. new container is created for the PDU	 * and elements are put into the new container without copying.	 * @see #setApplicationSpecificInfo(Object,Object)	 * @see #cloneApplicationSpecificInfo(Dictionary)	 */	public void setApplicationSpecificInfo(Dictionary applicationSpecificInfo)	{		this.applicationSpecificInfo =			cloneApplicationSpecificInfo(applicationSpecificInfo);	}	/**	 * Returns extra information with key <code>key</code>. If the information	 * is not found for this PDU, returns <code>null</code>.	 * @see #setApplicationSpecificInfo(Object,Object)	 */	public Object getApplicationSpecificInfo(Object key)	{		Object value = null;		if (applicationSpecificInfo!=null) {			value = applicationSpecificInfo.get(key);		}		debug.write(DPDU,"getting app spec info key=\""+					key+"\" value=\""+(value==null?"null":value)+"\"");		return value;	}	/**	 * Returns all the extra information related to this PDU. If there is no	 * information found for this PDU, returns <code>null</code>.	 * @see #setApplicationSpecificInfo(Object,Object)	 */	public Dictionary getApplicationSpecificInfo()	{		return cloneApplicationSpecificInfo(applicationSpecificInfo);	}	/**	 * Removes an extra information with the given <code>key</code>	 * from this PDU.	 * @see #setApplicationSpecificInfo(Object,Object)	 */	public void removeApplicationSpecificInfo(Object key)	{		if (applicationSpecificInfo!=null) {			applicationSpecificInfo.remove(key);		}	}	/**	 * Creates a shallow copy of the provided Dictionary, i.e. new container	 * structure is created, but the keys and elements from the original	 * Dictionary aren't cloned, htey are only put to the new structure.	 */	private Dictionary cloneApplicationSpecificInfo(Dictionary info)	{		Dictionary newInfo = null;		if (info != null) {			newInfo = new java.util.Hashtable();			Enumeration keys = info.keys();			Object key;			Object value;			while (keys.hasMoreElements()) {				key = keys.nextElement();				value = info.get(key);				newInfo.put(key,value);			}		}		return newInfo;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -