KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > loader > PermissionDescriptor


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.loader;
6
7 import org.w3c.dom.Element JavaDoc;
8
9 import java.io.PrintWriter JavaDoc;
10
11
12 /**
13  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
14  * @version $Revision: 1.2 $
15  */

16 public class PermissionDescriptor extends AbstractDescriptor {
17     //~ Instance fields ////////////////////////////////////////////////////////
18

19     protected RestrictionDescriptor restriction;
20     protected String JavaDoc name;
21
22     //~ Constructors ///////////////////////////////////////////////////////////
23

24     public PermissionDescriptor() {
25     }
26
27     public PermissionDescriptor(Element JavaDoc permission) {
28         init(permission);
29     }
30
31     //~ Methods ////////////////////////////////////////////////////////////////
32

33     public void setName(String JavaDoc name) {
34         this.name = name;
35     }
36
37     public String JavaDoc getName() {
38         return name;
39     }
40
41     public void setRestriction(RestrictionDescriptor restriction) {
42         this.restriction = restriction;
43     }
44
45     public RestrictionDescriptor getRestriction() {
46         return restriction;
47     }
48
49     public void writeXML(PrintWriter JavaDoc out, int indent) {
50         XMLUtil.printIndent(out, indent++);
51         out.print("<permission ");
52
53         if (hasId()) {
54             out.print("id=\"" + getId() + "\" ");
55         }
56
57         out.println("name=\"" + name + "\">");
58         restriction.writeXML(out, indent);
59         XMLUtil.printIndent(out, --indent);
60         out.println("</permission>");
61     }
62
63     protected void init(Element JavaDoc permission) {
64         name = permission.getAttribute("name");
65
66         try {
67             setId(Integer.parseInt(permission.getAttribute("id")));
68         } catch (NumberFormatException JavaDoc e) {
69         }
70
71         restriction = new RestrictionDescriptor(XMLUtil.getChildElement(permission, "restrict-to"));
72     }
73 }
74
Popular Tags