239 * but does not imply any non-null member.
240 */
241 private transient String member;
242
243 /**
244 * The objectName that must match. If null, is implied by any
245 * objectName but does not imply any non-null objectName.
246 */
247 private transient ObjectName objectName;
248
249 /**
250 * Parse <code>actions</code> parameter.
251 */
252 private void parseActions() {
253
254 int mask;
255
256 if (actions == null)
257 throw new IllegalArgumentException("MBeanPermission: " +
258 "actions can't be null");
259 if (actions.equals(""))
260 throw new IllegalArgumentException("MBeanPermission: " +
261 "actions can't be empty");
262
263 mask = getMask(actions);
264
265 if ((mask & ALL) != mask)
266 throw new IllegalArgumentException("Invalid actions mask");
267 if (mask == NONE)
268 throw new IllegalArgumentException("Invalid actions mask");
269 this.mask = mask;
270 }
271
272 /**
273 * Parse <code>name</code> parameter.
274 */
275 private void parseName() {
276 String name = getName();
277
278 if (name == null)
279 throw new IllegalArgumentException("MBeanPermission name " +
280 "cannot be null");
281
282 if (name.equals(""))
283 throw new IllegalArgumentException("MBeanPermission name " +
284 "cannot be empty");
285
286 /* The name looks like "class#member[objectname]". We subtract
287 elements from the right as we parse, so after parsing the
288 objectname we have "class#member" and after parsing the
289 member we have "class". Each element is optional. */
290
291 // Parse ObjectName
292
293 int openingBracket = name.indexOf('[');
294 if (openingBracket == -1) {
295 // If "[on]" missing then ObjectName("*:*")
296 //
297 objectName = ObjectName.WILDCARD;
298 } else {
299 if (!name.endsWith("]")) {
300 throw new IllegalArgumentException("MBeanPermission: " +
301 "The ObjectName in the " +
302 "target name must be " +
303 "included in square " +
304 "brackets");
305 } else {
306 // Create ObjectName
307 //
308 try {
309 // If "[]" then ObjectName("*:*")
310 //
311 String on = name.substring(openingBracket + 1,
312 name.length() - 1);
313 if (on.equals(""))
314 objectName = ObjectName.WILDCARD;
315 else if (on.equals("-"))
316 objectName = null;
317 else
318 objectName = new ObjectName(on);
319 } catch (MalformedObjectNameException e) {
320 throw new IllegalArgumentException("MBeanPermission: " +
321 "The target name does " +
322 "not specify a valid " +
323 "ObjectName", e);
324 }
325 }
326
327 name = name.substring(0, openingBracket);
328 }
329
330 // Parse member
331
332 int poundSign = name.indexOf('#');
333
342 // Parse className
343
344 setClassName(name);
345 }
346
347 /**
348 * Assign fields based on className, member, and objectName
349 * parameters.
350 */
351 private void initName(String className, String member,
352 ObjectName objectName) {
353 setClassName(className);
354 setMember(member);
355 this.objectName = objectName;
356 }
357
358 private void setClassName(String className) {
359 if (className == null || className.equals("-")) {
360 classNamePrefix = null;
361 classNameExactMatch = false;
362 } else if (className.equals("") || className.equals("*")) {
363 classNamePrefix = "";
364 classNameExactMatch = false;
365 } else if (className.endsWith(".*")) {
366 // Note that we include the "." in the required prefix
367 classNamePrefix = className.substring(0, className.length() - 1);
368 classNameExactMatch = false;
369 } else {
370 classNamePrefix = className;
371 classNameExactMatch = true;
372 }
373 }
374
375 private void setMember(String member) {
376 if (member == null || member.equals("-"))
377 this.member = null;
378 else if (member.equals(""))
379 this.member = "*";
380 else
381 this.member = member;
382 }
383
384 /**
385 * <p>Create a new MBeanPermission object with the specified target name
386 * and actions.</p>
387 *
388 * <p>The target name is of the form
389 * "<code>className#member[objectName]</code>" where each part is
390 * optional. It must not be empty or null.</p>
391 *
392 * <p>The actions parameter contains a comma-separated list of the
393 * desired actions granted on the target name. It must not be
394 * empty or null.</p>
395 *
396 * @param name the triplet "className#member[objectName]".
397 * @param actions the action string.
398 *
|
239 * but does not imply any non-null member.
240 */
241 private transient String member;
242
243 /**
244 * The objectName that must match. If null, is implied by any
245 * objectName but does not imply any non-null objectName.
246 */
247 private transient ObjectName objectName;
248
249 /**
250 * Parse <code>actions</code> parameter.
251 */
252 private void parseActions() {
253
254 int mask;
255
256 if (actions == null)
257 throw new IllegalArgumentException("MBeanPermission: " +
258 "actions can't be null");
259 if (actions.isEmpty())
260 throw new IllegalArgumentException("MBeanPermission: " +
261 "actions can't be empty");
262
263 mask = getMask(actions);
264
265 if ((mask & ALL) != mask)
266 throw new IllegalArgumentException("Invalid actions mask");
267 if (mask == NONE)
268 throw new IllegalArgumentException("Invalid actions mask");
269 this.mask = mask;
270 }
271
272 /**
273 * Parse <code>name</code> parameter.
274 */
275 private void parseName() {
276 String name = getName();
277
278 if (name == null)
279 throw new IllegalArgumentException("MBeanPermission name " +
280 "cannot be null");
281
282 if (name.isEmpty())
283 throw new IllegalArgumentException("MBeanPermission name " +
284 "cannot be empty");
285
286 /* The name looks like "class#member[objectname]". We subtract
287 elements from the right as we parse, so after parsing the
288 objectname we have "class#member" and after parsing the
289 member we have "class". Each element is optional. */
290
291 // Parse ObjectName
292
293 int openingBracket = name.indexOf('[');
294 if (openingBracket == -1) {
295 // If "[on]" missing then ObjectName("*:*")
296 //
297 objectName = ObjectName.WILDCARD;
298 } else {
299 if (!name.endsWith("]")) {
300 throw new IllegalArgumentException("MBeanPermission: " +
301 "The ObjectName in the " +
302 "target name must be " +
303 "included in square " +
304 "brackets");
305 } else {
306 // Create ObjectName
307 //
308 try {
309 // If "[]" then ObjectName("*:*")
310 //
311 String on = name.substring(openingBracket + 1,
312 name.length() - 1);
313 if (on.isEmpty())
314 objectName = ObjectName.WILDCARD;
315 else if (on.equals("-"))
316 objectName = null;
317 else
318 objectName = new ObjectName(on);
319 } catch (MalformedObjectNameException e) {
320 throw new IllegalArgumentException("MBeanPermission: " +
321 "The target name does " +
322 "not specify a valid " +
323 "ObjectName", e);
324 }
325 }
326
327 name = name.substring(0, openingBracket);
328 }
329
330 // Parse member
331
332 int poundSign = name.indexOf('#');
333
342 // Parse className
343
344 setClassName(name);
345 }
346
347 /**
348 * Assign fields based on className, member, and objectName
349 * parameters.
350 */
351 private void initName(String className, String member,
352 ObjectName objectName) {
353 setClassName(className);
354 setMember(member);
355 this.objectName = objectName;
356 }
357
358 private void setClassName(String className) {
359 if (className == null || className.equals("-")) {
360 classNamePrefix = null;
361 classNameExactMatch = false;
362 } else if (className.isEmpty() || className.equals("*")) {
363 classNamePrefix = "";
364 classNameExactMatch = false;
365 } else if (className.endsWith(".*")) {
366 // Note that we include the "." in the required prefix
367 classNamePrefix = className.substring(0, className.length() - 1);
368 classNameExactMatch = false;
369 } else {
370 classNamePrefix = className;
371 classNameExactMatch = true;
372 }
373 }
374
375 private void setMember(String member) {
376 if (member == null || member.equals("-"))
377 this.member = null;
378 else if (member.isEmpty())
379 this.member = "*";
380 else
381 this.member = member;
382 }
383
384 /**
385 * <p>Create a new MBeanPermission object with the specified target name
386 * and actions.</p>
387 *
388 * <p>The target name is of the form
389 * "<code>className#member[objectName]</code>" where each part is
390 * optional. It must not be empty or null.</p>
391 *
392 * <p>The actions parameter contains a comma-separated list of the
393 * desired actions granted on the target name. It must not be
394 * empty or null.</p>
395 *
396 * @param name the triplet "className#member[objectName]".
397 * @param actions the action string.
398 *
|