1 49 50 package org.apache.avalon.meta.info.builder.tags; 51 52 53 import com.thoughtworks.qdox.model.DocletTag; 54 import com.thoughtworks.qdox.model.JavaClass; 55 import com.thoughtworks.qdox.model.JavaMethod; 56 import org.apache.avalon.framework.Version; 57 import org.apache.avalon.meta.info.DependencyDescriptor; 58 import org.apache.avalon.meta.info.ReferenceDescriptor; 59 60 import java.util.ArrayList ; 61 import java.util.HashSet ; 62 import java.util.Set ; 63 64 70 public class DependencyTag extends AbstractTag 71 { 72 75 public static final String KEY = "dependency"; 76 77 80 public static final String KEY_PARAM = "key"; 81 82 85 public static final String OPTIONAL_PARAM = "optional"; 86 87 90 protected static final String COMPONENT_MANAGER_CLASS = 91 "org.apache.avalon.framework.component.ComponentManager"; 92 93 96 protected static final String SERVICE_MANAGER_CLASS = 97 "org.apache.avalon.framework.service.ServiceManager"; 98 99 private JavaMethod[] m_methods; 100 101 105 public DependencyTag( final JavaClass clazz ) 106 { 107 super( clazz ); 108 setMethods(); 109 } 110 111 116 public DependencyDescriptor[] getDependencies() 117 { 118 final ArrayList deps = new ArrayList (); 119 final Set marked = new HashSet ( 10 ); 120 for ( int j = 0; j < m_methods.length; j++ ) 121 { 122 final DocletTag[] tags = 123 m_methods[j].getTagsByName( getNS() 124 + Tags.DELIMITER + KEY ); 125 126 for ( int i = 0; i < tags.length; i++ ) 127 { 128 DocletTag tag = tags[i]; 129 DependencyDescriptor dep = getDependency( tag ); 130 final String key = dep.getKey(); 131 if ( !marked.contains( key ) ) 132 { 133 deps.add( dep ); 134 marked.add( key ); 135 } 136 } 137 } 138 return (DependencyDescriptor[]) deps.toArray( 139 new DependencyDescriptor[deps.size()] ); 140 } 141 142 private DependencyDescriptor getDependency( DocletTag tag ) 143 { 144 final String value = getNamedParameter( tag, TYPE_PARAM ); 145 final String type = resolveType( value ); 146 final String versionString = getNamedParameter( tag, VERSION_PARAM, null ); 147 final Version version = resolveVersion( versionString, value ); 148 final String key = getNamedParameter( tag, KEY_PARAM, type ); 149 final String optional = getNamedParameter( tag, OPTIONAL_PARAM, "false" ); 150 final boolean isOptional = "true".equals( optional.toLowerCase() ); 151 final ReferenceDescriptor ref = new ReferenceDescriptor( type, version ); 152 return new DependencyDescriptor( key, ref, isOptional, null ); 153 } 154 155 158 private void setMethods() 159 { 160 m_methods = getLifecycleMethods( "compose", COMPONENT_MANAGER_CLASS ); 161 if ( m_methods.length == 0 ) 162 { 163 m_methods = getLifecycleMethods( "service", SERVICE_MANAGER_CLASS ); 164 } 165 } 166 } 167 | Popular Tags |