View Javadoc

1   package org.apache.maven.doxia.wrapper;
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 java.io.Serializable;
23  
24  import org.codehaus.plexus.util.StringUtils;
25  
26  /**
27   * Abstract wrapper for Doxia converter.
28   *
29   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
30   * @version $Id: AbstractWrapper.java 786981 2009-06-21 10:01:58Z ltheussl $
31   */
32  abstract class AbstractWrapper
33      implements Serializable
34  {
35      public static final String AUTO_FORMAT = "auto";
36  
37      private String format;
38  
39      private String[] supportedFormat;
40  
41      /**
42       * @param format could be null.
43       * @param supportedFormat not null.
44       * @throws IllegalArgumentException if supportedFormat is null.
45       */
46      AbstractWrapper( String format, String[] supportedFormat )
47      {
48          this.format = ( StringUtils.isNotEmpty( format ) ? format : AUTO_FORMAT );
49          if ( supportedFormat == null )
50          {
51              throw new IllegalArgumentException( "supportedFormat is required" );
52          }
53          this.supportedFormat = supportedFormat;
54      }
55  
56      /**
57       * @return the wanted format.
58       */
59      public String getFormat()
60      {
61          return this.format;
62      }
63  
64      /**
65       * @param format The wanted format.
66       */
67      void setFormat( String format )
68      {
69          this.format = format;
70      }
71  
72      /**
73       * @return the supportedFormat
74       */
75      public String[] getSupportedFormat()
76      {
77          return supportedFormat;
78      }
79  
80      /**
81       * @param supportedFormat the supportedFormat to set
82       */
83      void setSupportedFormat( String[] supportedFormat )
84      {
85          this.supportedFormat = supportedFormat;
86      }
87  
88      /** {@inheritDoc} */
89      public boolean equals( Object other )
90      {
91          if ( this == other )
92          {
93              return true;
94          }
95  
96          if ( !( other instanceof AbstractWrapper ) )
97          {
98              return false;
99          }
100 
101         AbstractWrapper that = (AbstractWrapper) other;
102         boolean result = true;
103         result =
104             result && ( getFormat() == null ? that.getFormat() == null : getFormat().equals( that.getFormat() ) );
105         return result;
106     }
107 
108     /** {@inheritDoc} */
109     public int hashCode()
110     {
111         final int result = 17;
112         final int hash = 37;
113 
114         return hash * result + ( format != null ? format.hashCode() : 0 );
115     }
116 
117     /** {@inheritDoc} */
118     public java.lang.String toString()
119     {
120         StringBuffer buf = new StringBuffer();
121         buf.append( "format = '" );
122         buf.append( getFormat() + "'" );
123         return buf.toString();
124     }
125 }