View Javadoc

1   /*
2    * Copyright 2006 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.codehaus.modello.plugin.java.javasource;
17  
18  /**
19   * JType sub-class for collections.
20   *
21   * @author Werner Guttman
22   * @version $Revision$ $Date$
23   * @since 1.0.4
24   */
25  public final class JCollectionType
26      extends JComponentizedType
27  {
28      // --------------------------------------------------------------------------
29  
30      /** Name of the actual collection instance to be used, e.g. java.util.ArrayList. */
31      private String _instanceName;
32  
33      // --------------------------------------------------------------------------
34  
35      /**
36       * Creates an instance of a collection type, of type 'collectionName'.
37       *
38       * @param typeName Name of the collection type interface.
39       * @param componentType Component type.
40       * @param useJava50 True if Java 5.0 should be used.
41       */
42      public JCollectionType( final String typeName, final JType componentType, final boolean useJava50 )
43      {
44          super( typeName, componentType, useJava50 );
45      }
46  
47      /**
48       * Creates an instance of a collection type, of type 'collectionName'.
49       *
50       * @param typeName Name of the collection type interface.
51       * @param instanceName Name of the actual collection type instance.
52       * @param componentType Component type.
53       * @param useJava50 True if Java 5.0 should be used.
54       */
55      public JCollectionType( final String typeName, final String instanceName, final JType componentType,
56                              final boolean useJava50 )
57      {
58          super( typeName, componentType, useJava50 );
59          _instanceName = instanceName;
60      }
61  
62      // --------------------------------------------------------------------------
63  
64      /**
65       * Returns the instance name of this collection type.
66       *
67       * @return The instance name of this collection type.
68       */
69      public String getInstanceName()
70      {
71          if ( _instanceName != null )
72          {
73              if ( isUseJava50() )
74              {
75                  return _instanceName + "<" + getComponentType().toString() + ">";
76              }
77  
78              return _instanceName + "/*<" + getComponentType().toString() + ">*/";
79          }
80  
81          return toString();
82      }
83  
84      /**
85       * Returns the String representation of this JType.
86       */
87      public String toString()
88      {
89          if ( isUseJava50() )
90          {
91              return getName() + "<" + getComponentType().toString() + ">";
92          }
93  
94          return getName() + "/*<" + getComponentType().toString() + ">*/";
95      }
96  
97      // --------------------------------------------------------------------------
98  }