01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.loader;
06:
07: import org.w3c.dom.Element;
08:
09: import java.io.PrintWriter;
10:
11: /**
12: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
13: */
14: public class PermissionDescriptor extends AbstractDescriptor {
15: //~ Instance fields ////////////////////////////////////////////////////////
16:
17: protected RestrictionDescriptor restriction;
18: protected String name;
19:
20: //~ Constructors ///////////////////////////////////////////////////////////
21:
22: /**
23: * @deprecated use {@link DescriptorFactory} instead
24: */
25: PermissionDescriptor() {
26: }
27:
28: /**
29: * @deprecated use {@link DescriptorFactory} instead
30: */
31: PermissionDescriptor(Element permission) {
32: init(permission);
33: }
34:
35: //~ Methods ////////////////////////////////////////////////////////////////
36:
37: public void setName(String name) {
38: this .name = name;
39: }
40:
41: public String getName() {
42: return name;
43: }
44:
45: public void setRestriction(RestrictionDescriptor restriction) {
46: this .restriction = restriction;
47: }
48:
49: public RestrictionDescriptor getRestriction() {
50: return restriction;
51: }
52:
53: public void writeXML(PrintWriter out, int indent) {
54: XMLUtil.printIndent(out, indent++);
55: out.print("<permission ");
56:
57: if (hasId()) {
58: out.print("id=\"" + getId() + "\" ");
59: }
60:
61: out.println("name=\"" + name + "\">");
62: restriction.writeXML(out, indent);
63: XMLUtil.printIndent(out, --indent);
64: out.println("</permission>");
65: }
66:
67: protected void init(Element permission) {
68: name = permission.getAttribute("name");
69:
70: try {
71: setId(Integer.parseInt(permission.getAttribute("id")));
72: } catch (NumberFormatException e) {
73: }
74:
75: restriction = new RestrictionDescriptor(XMLUtil
76: .getChildElement(permission, "restrict-to"));
77: }
78: }
|