1// =================================================================================================
2// ADOBE SYSTEMS INCORPORATED
3// Copyright 2006 Adobe Systems Incorporated
4// All Rights Reserved
5//
6// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
7// of the Adobe license agreement accompanying it.
8// =================================================================================================
9
10package com.adobe.xmp.impl;
11
12import com.adobe.xmp.XMPConst;
13import com.adobe.xmp.XMPError;
14import com.adobe.xmp.XMPException;
15import com.adobe.xmp.XMPMeta;
16
17
18/**
19 * @since   11.08.2006
20 */
21class ParameterAsserts implements XMPConst
22{
23	/**
24	 * private constructor
25	 */
26	private ParameterAsserts()
27	{
28		// EMPTY
29	}
30
31
32	/**
33	 * Asserts that an array name is set.
34	 * @param arrayName an array name
35	 * @throws XMPException Array name is null or empty
36	 */
37	public static void assertArrayName(String arrayName) throws XMPException
38	{
39		if (arrayName == null  ||  arrayName.length() == 0)
40		{
41			throw new XMPException("Empty array name", XMPError.BADPARAM);
42		}
43	}
44
45
46	/**
47	 * Asserts that a property name is set.
48	 * @param propName a property name or path
49	 * @throws XMPException Property name is null or empty
50	 */
51	public static void assertPropName(String propName) throws XMPException
52	{
53		if (propName == null  ||  propName.length() == 0)
54		{
55			throw new XMPException("Empty property name", XMPError.BADPARAM);
56		}
57	}
58
59
60	/**
61	 * Asserts that a schema namespace is set.
62	 * @param schemaNS a schema namespace
63	 * @throws XMPException Schema is null or empty
64	 */
65	public static void assertSchemaNS(String schemaNS) throws XMPException
66	{
67		if (schemaNS == null  ||  schemaNS.length() == 0)
68		{
69			throw new XMPException("Empty schema namespace URI", XMPError.BADPARAM);
70		}
71	}
72
73
74	/**
75	 * Asserts that a prefix is set.
76	 * @param prefix a prefix
77	 * @throws XMPException Prefix is null or empty
78	 */
79	public static void assertPrefix(String prefix) throws XMPException
80	{
81		if (prefix == null  ||  prefix.length() == 0)
82		{
83			throw new XMPException("Empty prefix", XMPError.BADPARAM);
84		}
85	}
86
87
88	/**
89	 * Asserts that a specific language is set.
90	 * @param specificLang a specific lang
91	 * @throws XMPException Specific language is null or empty
92	 */
93	public static void assertSpecificLang(String specificLang) throws XMPException
94	{
95		if (specificLang == null  ||  specificLang.length() == 0)
96		{
97			throw new XMPException("Empty specific language", XMPError.BADPARAM);
98		}
99	}
100
101
102	/**
103	 * Asserts that a struct name is set.
104	 * @param structName a struct name
105	 * @throws XMPException Struct name is null or empty
106	 */
107	public static void assertStructName(String structName) throws XMPException
108	{
109		if (structName == null  ||  structName.length() == 0)
110		{
111			throw new XMPException("Empty array name", XMPError.BADPARAM);
112		}
113	}
114
115
116	/**
117	 * Asserts that any string parameter is set.
118	 * @param param any string parameter
119	 * @throws XMPException Thrown if the parameter is null or has length 0.
120	 */
121	public static void assertNotNull(Object param) throws XMPException
122	{
123		if (param == null)
124		{
125			throw new XMPException("Parameter must not be null", XMPError.BADPARAM);
126		}
127		else if ((param instanceof String)  &&  ((String) param).length() == 0)
128		{
129			throw new XMPException("Parameter must not be null or empty", XMPError.BADPARAM);
130		}
131	}
132
133
134	/**
135	 * Asserts that the xmp object is of this implemention
136	 * ({@link XMPMetaImpl}).
137	 * @param xmp the XMP object
138	 * @throws XMPException A wrong implentaion is used.
139	 */
140	public static void assertImplementation(XMPMeta xmp) throws XMPException
141	{
142		if (xmp == null)
143		{
144			throw new XMPException("Parameter must not be null",
145					XMPError.BADPARAM);
146		}
147		else if (!(xmp instanceof XMPMetaImpl))
148		{
149			throw new XMPException("The XMPMeta-object is not compatible with this implementation",
150					XMPError.BADPARAM);
151		}
152	}
153}