add error handle: ElementContainer

This commit is contained in:
free will committed 2021-03-25 20:04:37 +08:00
1 parent 8a2da10583
commit 28f963c28a
14 files changed
+40 -43

No files matched your search

+10 -10
View File
@@ -64,9 +64,9 @@ class IdentifierComponentContainer {
* @param index
* @return
*/
public IdentifierComponent getElement(int index) {
public IdentifierComponent getElement(int index) throws ComponentException {
if (index >= this.length()) {
return null;
throw new ComponentException("IdentifierComponents.getElement: index is out of bound.");
}
return this.identifierComponents.get(index);
}
@@ -77,7 +77,7 @@ class IdentifierComponentContainer {
* @param num
* @return
*/
public IdentifierComponentContainer getPrefix(int num) {
public IdentifierComponentContainer getPrefix(int num) throws ComponentException {
if (num > this.length()) {
return null;
}
@@ -88,7 +88,7 @@ class IdentifierComponentContainer {
return identifierComponentContainer;
}
public IdentifierComponentContainer getSubIdentifierContainer(int startIndex, int num) {
public IdentifierComponentContainer getSubIdentifierContainer(int startIndex, int num) throws ComponentException {
if ((startIndex + num) > this.length()) {
return null;
}
@@ -131,7 +131,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
*
* @param container
*/
public Identifier(IdentifierComponentContainer container) {
public Identifier(IdentifierComponentContainer container) throws ComponentException {
this.buildIdentifierByComponents(container);
}
@@ -181,7 +181,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
* @param container
* @return
*/
public boolean buildIdentifierByComponents(IdentifierComponentContainer container) {
public boolean buildIdentifierByComponents(IdentifierComponentContainer container) throws ComponentException {
if (container.length() <= 0) {
return false;
}
@@ -281,7 +281,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
*
* @return
*/
public String toUri() {
public String toUri() throws ComponentException {
String res = "";
for (int i = 0; i < components.length(); i++) {
res += ("/" + components.getElement(i).toUri());
@@ -313,7 +313,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
* @param index
* @return
*/
public IdentifierComponent get(int index) {
public IdentifierComponent get(int index) throws ComponentException {
return this.components.getElement(index);
}
@@ -332,7 +332,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
* @param num
* @return
*/
public IdentifierComponentContainer getPrefix(int num) {
public IdentifierComponentContainer getPrefix(int num) throws ComponentException {
return this.components.getPrefix(num);
}
@@ -341,7 +341,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
*
* @return
*/
public Identifier getSubIdentifier(int startIndex, int num) {
public Identifier getSubIdentifier(int startIndex, int num) throws ComponentException {
return new Identifier(this.components.getSubIdentifierContainer(startIndex, num));
}
+7 -6
View File
@@ -2,6 +2,7 @@ package component;
import encoding.*;
import java.awt.*;
import java.util.LinkedList;
import java.util.List;
@@ -50,9 +51,9 @@ class IdentifierContainer {
* @param index
* @return
*/
public IdentifierWrapper getElement(int index) {
public IdentifierWrapper getElement(int index) throws ComponentException {
if (index >= this.length()) {
return null;
throw new ComponentException("IdentifierWrappers.getElement: index is out of bound.");
}
return this.identifierWrappers.get(index);
}
@@ -63,13 +64,13 @@ class IdentifierContainer {
* @param vlInt
* @return
*/
public IdentifierWrapper getElementByType(VlInt vlInt) {
public IdentifierWrapper getElementByType(VlInt vlInt) throws ComponentException {
for (int i = 0; i < identifierWrappers.size(); i++) {
if (identifierWrappers.get(i).getTlvType().isEqual(vlInt)) {
return identifierWrappers.get(i);
}
}
return null;
throw new ComponentException("IdentifierWrappers.getElementByType: no found the tlvType");
}
public void setElement(int index, IdentifierWrapper wrapper) {
@@ -102,7 +103,7 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
* @param tlvType
* @return
*/
public IdentifierWrapper getIdentifierByType(VlInt tlvType) {
public IdentifierWrapper getIdentifierByType(VlInt tlvType) throws ComponentException {
return this.identifiers.getElementByType(tlvType);
}
@@ -112,7 +113,7 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
* @param index
* @return
*/
public IdentifierWrapper getIdentifier(int index) {
public IdentifierWrapper getIdentifier(int index) throws ComponentException {
return this.identifiers.getElement(index);
}
@@ -122,7 +122,7 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
*
* @param container
*/
public IdentifierWrapper createCommonIdentifierByComponents(IdentifierComponentContainer container) {
public IdentifierWrapper createCommonIdentifierByComponents(IdentifierComponentContainer container) throws ComponentException {
IdentifierWrapper identifierWrapper = new IdentifierWrapper();
identifierWrapper.tlvType = new VlInt(TLV.TlvIdentifierCommon);
identifierWrapper.identifier.buildIdentifierByComponents(container);
@@ -176,7 +176,7 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
* @param container
* @return
*/
public IdentifierWrapper createContentInterestIdentifierByComponents(IdentifierComponentContainer container) {
public IdentifierWrapper createContentInterestIdentifierByComponents(IdentifierComponentContainer container) throws ComponentException {
IdentifierWrapper identifierWrapper = new IdentifierWrapper();
identifierWrapper.tlvType = new VlInt(TLV.TlvIdentifierContentInterest);
identifierWrapper.identifier.buildIdentifierByComponents(container);
@@ -230,7 +230,7 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
* @param container
* @return
*/
public IdentifierWrapper createContentDataIdentifierByComponents(IdentifierComponentContainer container) {
public IdentifierWrapper createContentDataIdentifierByComponents(IdentifierComponentContainer container) throws ComponentException {
IdentifierWrapper identifierWrapper = new IdentifierWrapper();
identifierWrapper.tlvType = new VlInt(TLV.TlvIdentifierContentData);
identifierWrapper.identifier.buildIdentifierByComponents(container);
@@ -362,7 +362,7 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
*
* @return
*/
public String toUri() {
public String toUri() throws ComponentException {
return this.identifier.toUri();
}
}
+4 -4
View File
@@ -39,7 +39,7 @@ public class KeyLocator implements TlvComponentBase, IEncodingAble {
* 根据 components 创建一个 KeyLocator
* @param container
*/
public KeyLocator(IdentifierComponentContainer container){
public KeyLocator(IdentifierComponentContainer container) throws ComponentException {
this.buildKeyLocatorByComponents(container);
}
@@ -47,7 +47,7 @@ public class KeyLocator implements TlvComponentBase, IEncodingAble {
* 根据 Identifier 创建一个 KeyLocator
* @param identifier
*/
public KeyLocator(Identifier identifier){
public KeyLocator(Identifier identifier) throws ComponentException {
this.buildKeyLocatorByIdentifier(identifier);
}
@@ -74,7 +74,7 @@ public class KeyLocator implements TlvComponentBase, IEncodingAble {
* @param container
* @return
*/
public boolean buildKeyLocatorByComponents(IdentifierComponentContainer container){
public boolean buildKeyLocatorByComponents(IdentifierComponentContainer container) throws ComponentException {
return this.identifier.buildIdentifierByComponents(container);
}
@@ -83,7 +83,7 @@ public class KeyLocator implements TlvComponentBase, IEncodingAble {
* @param identifier
* @return
*/
public boolean buildKeyLocatorByIdentifier(Identifier identifier){
public boolean buildKeyLocatorByIdentifier(Identifier identifier) throws ComponentException {
return this.identifier.buildIdentifierByComponents(identifier.getComponents());
}
@@ -57,7 +57,7 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
*/
public Block getBlockByType(VlInt tlvType) throws ComponentException {
try {
return this.blocks.getElement(tlvType);
return this.blocks.getBlockByType(tlvType);
} catch (BlockException e) {
throw new ComponentException("MutableDangerousField.getBlockByType: "+e.getMessage());
}
@@ -57,7 +57,7 @@ public class MutableProtectField implements TlvComponentBase, IEncodingAble {
*/
public Block getBlockByType(VlInt tlvType) throws ComponentException {
try {
return this.blocks.getElement(tlvType);
return this.blocks.getBlockByType(tlvType);
} catch (BlockException e) {
throw new ComponentException("MutableProtectField.getBlockByType: "+e.getMessage());
}
+1 -1
View File
@@ -61,7 +61,7 @@ public class ReadOnlyField implements TlvComponentBase, IEncodingAble {
*/
public Block getBlockByType(VlInt tlvType) throws ComponentException {
try {
return this.blocks.getElement(tlvType);
return this.blocks.getBlockByType(tlvType);
} catch (BlockException e) {
throw new ComponentException("ReadOnlyField.getBlockType: " + e.getMessage());
}
+1 -1
View File
@@ -34,7 +34,7 @@ public class Signature {
* @param identity
* @param value
*/
public Signature(Identity identity,byte[] value){
public Signature(Identity identity,byte[] value) throws ComponentException {
// 往包中添加签名
KeyLocator keyLocator=new KeyLocator(identity.getName());
this.sigInfo=new SignatureInfo(
+3 -3
View File
@@ -50,9 +50,9 @@ class SignatureContainer {
* @param index
* @return
*/
public Signature getElement(int index) {
public Signature getElement(int index) throws ComponentException {
if (index >= length()) {
return null;
throw new ComponentException("Signatures.getElement: index is out of bound.");
}
return signatures.get(index);
}
@@ -99,7 +99,7 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
* @param index
* @return
*/
public Signature getSignature(int index) {
public Signature getSignature(int index) throws ComponentException {
return signatures.getElement(index);
}
+2 -2
View File
@@ -37,7 +37,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
* @param value
* @param locator
*/
public SignatureInfo(SignatureAlgorithm value,KeyLocator locator){
public SignatureInfo(SignatureAlgorithm value,KeyLocator locator) throws ComponentException {
this.buildSignatureInfoBySignatureTypeValueAndKeyLocator(value,locator);
}
@@ -64,7 +64,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
* @param locator
* @return
*/
public boolean buildSignatureInfoBySignatureTypeValueAndKeyLocator(SignatureAlgorithm value,KeyLocator locator){
public boolean buildSignatureInfoBySignatureTypeValueAndKeyLocator(SignatureAlgorithm value,KeyLocator locator) throws ComponentException {
if(!this.signatureType.buildSignatureTypeByValue(value)){
return false;
}
+1 -5
View File
@@ -2,10 +2,6 @@ package encoding;
import component.ComponentException;
import util.ByteHelper;
import util.ByteHelperException;
import java.util.LinkedList;
import java.util.List;
/*
* @Author: Wang Feng
@@ -302,7 +298,7 @@ public class Block {
* @return
*/
public Block getElement(VlInt tlvType) throws BlockException {
return this.elements.getElement(tlvType);
return this.elements.getBlockByType(tlvType);
}
/**
+3 -3
View File
@@ -69,18 +69,18 @@ public class ElementContainer{
* @param tlvType
* @return
*/
public Block getElement(VlInt tlvType) throws BlockException {
public Block getBlockByType(VlInt tlvType) throws BlockException {
for(Block block: this.elementContainer){
if(block.getType().isEqual(tlvType)){
return block;
}
}
throw new BlockException("ReadOnlyField.getBlock: no found the tlvType");
throw new BlockException("Blocks.getBlockByType: no found the tlvType");
}
public Block getBlock(int index) throws BlockException {
if(index>=this.length()){
throw new BlockException("ReadOnlyField.getBlock: index is out of bound.");
throw new BlockException("Blocks.getBlock: index is out of bound.");
}
return this.elementContainer.get(index);
+1 -1
View File
@@ -45,7 +45,7 @@ public class Data implements IEncodingAble, InteractWithField {
*
* @return
*/
public String toUri() {
public String toUri() throws ComponentException {
if (this.name == null) {
return "";
}
+1 -1
View File
@@ -101,7 +101,7 @@ public class Interest implements InteractWithField, IEncodingAble {
*
* @return
*/
public String toUri() {
public String toUri() throws ComponentException {
return this.name.toUri();
}