View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.ear;
20  
21  import org.codehaus.plexus.util.xml.XMLWriter;
22  
23  /**
24   * The representation of a security-role entry within an application.xml file.
25   *
26   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
27   */
28  class SecurityRole {
29  
30      protected static final String SECURITY_ROLE = "security-role";
31  
32      protected static final String ID_ATTRIBUTE = "id";
33  
34      protected static final String DESCRIPTION = "description";
35  
36      protected static final String ROLE_NAME = "role-name";
37  
38      private final String roleName;
39  
40      private final String roleNameId;
41  
42      private final String roleId;
43  
44      private final String description;
45  
46      private final String descriptionId;
47  
48      SecurityRole(String roleName, String roleNameId, String roleId, String description, String descriptionId) {
49          if (roleName == null) {
50              throw new NullPointerException("role-name in security-role element could not be null.");
51          }
52          this.roleName = roleName;
53          this.roleNameId = roleNameId;
54          this.roleId = roleId;
55          this.description = description;
56          this.descriptionId = descriptionId;
57      }
58  
59      public String getRoleName() {
60          return roleName;
61      }
62  
63      public String getRoleNameId() {
64          return roleNameId;
65      }
66  
67      public String getRoleId() {
68          return roleId;
69      }
70  
71      public String getDescription() {
72          return description;
73      }
74  
75      public String getDescriptionId() {
76          return descriptionId;
77      }
78  
79      /**
80       * Appends the {@code XML} representation of this security role.
81       *
82       * @param writer the writer to use
83       */
84      public void appendSecurityRole(XMLWriter writer) {
85          writer.startElement(SECURITY_ROLE);
86  
87          // role id
88          if (getRoleId() != null) {
89              writer.addAttribute(ID_ATTRIBUTE, getRoleId());
90          }
91  
92          // description
93          if (getDescription() != null) {
94              writer.startElement(DESCRIPTION);
95              if (getDescriptionId() != null) {
96                  writer.addAttribute(ID_ATTRIBUTE, getDescriptionId());
97              }
98              writer.writeText(getDescription());
99              writer.endElement();
100         }
101 
102         // role name
103         writer.startElement(ROLE_NAME);
104         if (getRoleNameId() != null) {
105             writer.addAttribute(ID_ATTRIBUTE, getRoleNameId());
106         }
107         writer.writeText(getRoleName());
108         writer.endElement();
109 
110         // end of security-role
111         writer.endElement();
112     }
113 
114     public String toString() {
115         return "Security role " + getRoleName();
116     }
117 }