Revision 386 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynClassName.java

View differences:

DefaultDynClassName.java
36 36
	private String namespace;
37 37
	
38 38
	public DefaultDynClassName(String namespace, String name) {
39
		this.namespace = namespace;
40
		this.name = name;
39
		setNamespace(namespace);
40
		setName(name);
41 41
	}
42 42
	
43 43
	public DefaultDynClassName(String fullname) {
44 44
		int x=fullname.indexOf(SEPARATOR);
45
		int y=fullname.lastIndexOf(SEPARATOR);
45 46
		if( x>-1 ) {
46
			namespace = fullname.substring(0, x);
47
			name = fullname.substring(x+1);
47
			// Separator should only be present once
48
			if (x==y){
49
				setNamespace(fullname.substring(0, x));
50
				setName(fullname.substring(x+1));				
51
			}else{
52
				throw new IllegalArgumentException("Fullname '" + fullname + "' not allowed. Only one '" + SEPARATOR + "' is possible.");				
53
			}
48 54
		} else {
49 55
			this.namespace = null;
50
			this.name = fullname;
56
			setName(fullname);
51 57
		}
52 58
	}
53 59
	
54 60
	public DefaultDynClassName(String[] name) {
55
		this.namespace = name[0];
56
		this.name = name[1];
61
		setNamespace(name[0]);
62
		setName(name[1]);
57 63
	}
58 64
	
59 65
	public String getName() {
......
72 78
	}
73 79

  
74 80
	public void setNamespace(String namespace) {
75
		this.namespace = namespace;
81
		if(namespace!=null){
82
			if (!namespace.contains(SEPARATOR)){
83
				this.namespace = namespace;
84
			}else{
85
				throw new IllegalArgumentException("Namespace '" + namespace + "' not allowed. Character " + SEPARATOR + " forbidden whithin a dynClass' namespace'");
86
			}
87
		}else{
88
			this.namespace = null;
89
		}
76 90
	}
77 91

  
78 92
	public void setName(String name) {
79
		this.name = name;
93
		if(name!=null){
94
			if (!name.contains(SEPARATOR)){
95
				this.name = name;
96
			}else{
97
				throw new IllegalArgumentException("Name '" + name + "' not allowed. Character " + SEPARATOR + " forbidden whithin a dynClass' name.");
98
			}
99
		}else{
100
			throw new IllegalArgumentException("Null value unsupported for a dynClass' name.");
101
		}
80 102
	}
81 103

  
82 104
	public int hashCode() {

Also available in: Unified diff