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