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.StringUtils;
23  import org.codehaus.plexus.util.xml.XMLWriter;
24  
25  /**
26   * Representation of {@code ejb-ref} element in {@code application.xml} file.
27   * 
28   * @author Karl Heinz Marbaise
29   * @since 2.10
30   */
31  public class EjbRef
32  {
33      static final String DESCRIPTION = "description";
34  
35      static final String EJB_REF = "ejb-ref";
36  
37      static final String EJB_NAME = "ejb-ref-name";
38  
39      static final String EJB_TYPE = "ejb-ref-type";
40  
41      static final String EJB_LOOKUP_NAME = "lookup-name";
42  
43      private final String description;
44  
45      private String name;
46  
47      private String type;
48  
49      private String lookupName;
50  
51      /**
52       * @param description The ejb-ref description.
53       * @param name The ejb-ref-name.
54       * @param type The ejb-ref-type
55       * @param lookupName The lookupname.
56       */
57      public EjbRef( String description, String name, String type, String lookupName )
58      {
59          if ( StringUtils.isEmpty( name ) )
60          {
61              throw new IllegalArgumentException( EJB_NAME + " in " + EJB_REF + " element cannot be null." );
62          }
63          else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( lookupName ) )
64          {
65              throw new IllegalArgumentException( EJB_TYPE + " in " + EJB_REF + " element cannot be null if no "
66                  + EJB_LOOKUP_NAME + " was specified." );
67  
68          }
69  
70          this.description = description;
71          this.name = name;
72          this.type = type;
73          this.lookupName = lookupName;
74  
75      }
76  
77      /**
78       * Appends the {@code XML} representation of this env-entry.
79       * 
80       * @param writer the writer to use
81       */
82      public void appendEjbRefEntry( XMLWriter writer )
83      {
84          writer.startElement( EJB_REF );
85  
86          // description
87          if ( getDescription() != null )
88          {
89              doWriteElement( writer, DESCRIPTION, getDescription() );
90          }
91  
92          // ejb name
93          doWriteElement( writer, EJB_NAME, getName() );
94  
95          // ejb-type
96          if ( getType() != null )
97          {
98              doWriteElement( writer, EJB_TYPE, getType() );
99          }
100 
101         // lookup-name
102         if ( getLookupName() != null )
103         {
104             doWriteElement( writer, EJB_LOOKUP_NAME, getLookupName() );
105         }
106 
107         // end of ejb-ref
108         writer.endElement();
109     }
110 
111     private void doWriteElement( XMLWriter writer, String element, String text )
112     {
113         writer.startElement( element );
114         writer.writeText( text );
115         writer.endElement();
116     }
117 
118     /**
119      * @return {@link #name}
120      */
121     public String getName()
122     {
123         return name;
124     }
125 
126     /**
127      * @param name {@link #name}
128      */
129     public void setName( String name )
130     {
131         this.name = name;
132     }
133 
134     /**
135      * @return {@link #type}
136      */
137     public String getType()
138     {
139         return type;
140     }
141 
142     /**
143      * @param type {@link #type}
144      */
145     public void setType( String type )
146     {
147         this.type = type;
148     }
149 
150     /**
151      * @return {@link #lookupName}
152      */
153     public String getLookupName()
154     {
155         return lookupName;
156     }
157 
158     /**
159      * @param lookupName {@link #lookupName}
160      */
161     public void setLookupName( String lookupName )
162     {
163         this.lookupName = lookupName;
164     }
165 
166     /**
167      * @return {@link #description}
168      */
169     public String getDescription()
170     {
171         return description;
172     }
173 }