summaryrefslogtreecommitdiff
path: root/XMPCore/src/com/adobe/xmp/impl/ParameterAsserts.java
blob: 78ae5d6a20d872e5cef547517abb3f7a43cb0e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// =================================================================================================
// ADOBE SYSTEMS INCORPORATED
// Copyright 2006 Adobe Systems Incorporated
// All Rights Reserved
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================

package com.adobe.xmp.impl;

import com.adobe.xmp.XMPConst;
import com.adobe.xmp.XMPError;
import com.adobe.xmp.XMPException;
import com.adobe.xmp.XMPMeta;


/**
 * @since   11.08.2006
 */
class ParameterAsserts implements XMPConst
{
	/**
	 * private constructor
	 */
	private ParameterAsserts()
	{
		// EMPTY
	}

	
	/**
	 * Asserts that an array name is set.
	 * @param arrayName an array name
	 * @throws XMPException Array name is null or empty
	 */
	public static void assertArrayName(String arrayName) throws XMPException
	{
		if (arrayName == null  ||  arrayName.length() == 0)
		{
			throw new XMPException("Empty array name", XMPError.BADPARAM);
		}
	}

	
	/**
	 * Asserts that a property name is set.
	 * @param propName a property name or path
	 * @throws XMPException Property name is null or empty
	 */
	public static void assertPropName(String propName) throws XMPException
	{
		if (propName == null  ||  propName.length() == 0)
		{
			throw new XMPException("Empty property name", XMPError.BADPARAM);
		}
	}

	
	/**
	 * Asserts that a schema namespace is set.
	 * @param schemaNS a schema namespace
	 * @throws XMPException Schema is null or empty
	 */
	public static void assertSchemaNS(String schemaNS) throws XMPException
	{
		if (schemaNS == null  ||  schemaNS.length() == 0)
		{
			throw new XMPException("Empty schema namespace URI", XMPError.BADPARAM);
		}
	}

	
	/**
	 * Asserts that a prefix is set.
	 * @param prefix a prefix
	 * @throws XMPException Prefix is null or empty
	 */
	public static void assertPrefix(String prefix) throws XMPException
	{
		if (prefix == null  ||  prefix.length() == 0)
		{
			throw new XMPException("Empty prefix", XMPError.BADPARAM);
		}
	}
	
	
	/**
	 * Asserts that a specific language is set.
	 * @param specificLang a specific lang
	 * @throws XMPException Specific language is null or empty
	 */
	public static void assertSpecificLang(String specificLang) throws XMPException
	{
		if (specificLang == null  ||  specificLang.length() == 0)
		{
			throw new XMPException("Empty specific language", XMPError.BADPARAM);
		}
	}

	
	/**
	 * Asserts that a struct name is set.
	 * @param structName a struct name
	 * @throws XMPException Struct name is null or empty
	 */
	public static void assertStructName(String structName) throws XMPException
	{
		if (structName == null  ||  structName.length() == 0)
		{
			throw new XMPException("Empty array name", XMPError.BADPARAM);
		}
	}


	/**
	 * Asserts that any string parameter is set.
	 * @param param any string parameter
	 * @throws XMPException Thrown if the parameter is null or has length 0.
	 */
	public static void assertNotNull(Object param) throws XMPException
	{
		if (param == null)
		{
			throw new XMPException("Parameter must not be null", XMPError.BADPARAM);
		}
		else if ((param instanceof String)  &&  ((String) param).length() == 0)
		{
			throw new XMPException("Parameter must not be null or empty", XMPError.BADPARAM);
		}
	}


	/**
	 * Asserts that the xmp object is of this implemention
	 * ({@link XMPMetaImpl}). 
	 * @param xmp the XMP object
	 * @throws XMPException A wrong implentaion is used.
	 */
	public static void assertImplementation(XMPMeta xmp) throws XMPException
	{
		if (xmp == null)
		{
			throw new XMPException("Parameter must not be null",
					XMPError.BADPARAM);
		}
		else if (!(xmp instanceof XMPMetaImpl))
		{
			throw new XMPException("The XMPMeta-object is not compatible with this implementation",
					XMPError.BADPARAM);
		}
	}
}