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 extends JComponentizedType { 26 // -------------------------------------------------------------------------- 27 28 /** Name of the actual collection instance to be used, e.g. java.util.ArrayList. */ 29 private String _instanceName; 30 31 // -------------------------------------------------------------------------- 32 33 /** 34 * Creates an instance of a collection type, of type 'collectionName'. 35 * 36 * @param typeName Name of the collection type interface. 37 * @param componentType Component type. 38 * @param useJava50 True if Java 5.0 should be used. 39 */ 40 public JCollectionType(final String typeName, final JType componentType, final boolean useJava50) { 41 super(typeName, componentType, useJava50); 42 } 43 44 /** 45 * Creates an instance of a collection type, of type 'collectionName'. 46 * 47 * @param typeName Name of the collection type interface. 48 * @param instanceName Name of the actual collection type instance. 49 * @param componentType Component type. 50 * @param useJava50 True if Java 5.0 should be used. 51 */ 52 public JCollectionType( 53 final String typeName, final String instanceName, final JType componentType, final boolean useJava50) { 54 super(typeName, componentType, useJava50); 55 _instanceName = instanceName; 56 } 57 58 // -------------------------------------------------------------------------- 59 60 /** 61 * Returns the instance name of this collection type. 62 * 63 * @return The instance name of this collection type. 64 */ 65 public String getInstanceName() { 66 if (_instanceName != null) { 67 if (isUseJava50()) { 68 return _instanceName + "<" + getComponentType().toString() + ">"; 69 } 70 71 return _instanceName + "/*<" + getComponentType().toString() + ">*/"; 72 } 73 74 return toString(); 75 } 76 77 /** 78 * Returns the String representation of this JType. 79 */ 80 public String toString() { 81 if (isUseJava50()) { 82 return getName() + "<" + getComponentType().toString() + ">"; 83 } 84 85 return getName() + "/*<" + getComponentType().toString() + ">*/"; 86 } 87 88 // -------------------------------------------------------------------------- 89 }