View Javadoc

1   package org.apache.maven.plugin.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
26   * application.xml file.
27   *
28   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
29   * @version $Id: SecurityRole.java 728546 2008-12-21 22:56:51Z bentmann $
30   */
31  class SecurityRole
32  {
33  
34      protected static final String SECURITY_ROLE = "security-role";
35  
36      protected static final String ID_ATTRIBUTE = "id";
37  
38      protected static final String DESCRIPTION = "description";
39  
40      protected static final String ROLE_NAME = "role-name";
41  
42      private final String roleName;
43  
44      private final String roleNameId;
45  
46      private final String roleId;
47  
48      private final String description;
49  
50      private final String descriptionId;
51  
52      public SecurityRole( String roleName, String roleNameId, String roleId, String description, String descriptionId )
53      {
54          if ( roleName == null )
55          {
56              throw new NullPointerException( "role-name in security-role element could not be null." );
57          }
58          this.roleName = roleName;
59          this.roleNameId = roleNameId;
60          this.roleId = roleId;
61          this.description = description;
62          this.descriptionId = descriptionId;
63      }
64  
65      public String getRoleName()
66      {
67          return roleName;
68      }
69  
70      public String getRoleNameId()
71      {
72          return roleNameId;
73      }
74  
75      public String getRoleId()
76      {
77          return roleId;
78      }
79  
80      public String getDescription()
81      {
82          return description;
83      }
84  
85      public String getDescriptionId()
86      {
87          return descriptionId;
88      }
89  
90      /**
91       * Appends the <tt>XML</tt> representation of this security role.
92       *
93       * @param writer the writer to use
94       */
95      public void appendSecurityRole( XMLWriter writer )
96      {
97          writer.startElement( SECURITY_ROLE );
98  
99          // role id
100         if ( getRoleId() != null )
101         {
102             writer.addAttribute( ID_ATTRIBUTE, getRoleId() );
103         }
104 
105         // description
106         if ( getDescription() != null )
107         {
108             writer.startElement( DESCRIPTION );
109             if ( getDescriptionId() != null )
110             {
111                 writer.addAttribute( ID_ATTRIBUTE, getDescriptionId() );
112             }
113             writer.writeText( getDescription() );
114             writer.endElement();
115 
116         }
117 
118         // role name
119         writer.startElement( ROLE_NAME );
120         if ( getRoleNameId() != null )
121         {
122             writer.addAttribute( ID_ATTRIBUTE, getRoleNameId() );
123         }
124         writer.writeText( getRoleName() );
125         writer.endElement();
126 
127         // end of security-role
128         writer.endElement();
129     }
130 
131     public String toString()
132     {
133         return "Security role " + getRoleName();
134     }
135 
136 
137 }