1 49 50 package org.apache.avalon.meta.info.builder.tags; 51 52 import java.util.ArrayList ; 53 import java.util.HashSet ; 54 import java.util.Set ; 55 import java.util.Properties ; 56 57 import com.thoughtworks.qdox.model.DocletTag; 58 import com.thoughtworks.qdox.model.JavaClass; 59 import com.thoughtworks.qdox.model.JavaMethod; 60 import org.apache.avalon.meta.info.ContextDescriptor; 61 import org.apache.avalon.meta.info.EntryDescriptor; 62 import org.apache.avalon.meta.info.ReferenceDescriptor; 63 64 70 public class ContextTag extends AbstractTag 71 { 72 75 protected static final String CONTEXT_CLASS = 76 "org.apache.avalon.framework.context.Context"; 77 78 81 public static final String KEY = "context"; 82 83 86 public static final String STRATEGY_PARAM = "strategy"; 87 88 91 public static final String KEY_PARAM = "key"; 92 93 96 public static final String VOLATILE_PARAM = "volatile"; 97 98 101 public static final String ALIAS_PARAM = "alias"; 102 103 106 public static final String OPTIONAL_PARAM = "optional"; 107 108 111 public static final String ENTRY = "entry"; 112 113 117 public ContextTag( final JavaClass clazz ) 118 { 119 super( clazz ); 120 } 121 122 126 public ContextDescriptor getContext() 127 { 128 JavaMethod[] methods = findTaggedMethods( 129 getJavaClass(), getNS() + Tags.DELIMITER + ENTRY ); 130 if( methods.length == 0 ) 131 { 132 return new ContextDescriptor( new EntryDescriptor[0] ); 133 } 134 else 135 { 136 137 142 final ArrayList list = new ArrayList (); 143 final Set marked = new HashSet ( 10 ); 144 for( int j = 0; j < methods.length; j++ ) 145 { 146 final DocletTag[] tags = 147 methods[j].getTagsByName( getNS() + Tags.DELIMITER + ENTRY ); 148 for( int i = 0; i < tags.length; i++ ) 149 { 150 final String key = getNamedParameter( tags[i], KEY_PARAM ); 151 if( !marked.contains( key ) ) 152 { 153 list.add( getEntry( tags[i] ) ); 154 marked.add( key ); 155 } 156 } 157 } 158 159 final EntryDescriptor[] entries = 160 (EntryDescriptor[])list.toArray( new EntryDescriptor[ list.size() ] ); 161 162 String type = null; 163 String strategy = null; 164 for( int j = 0; j < methods.length; j++ ) 165 { 166 JavaMethod method = methods[j]; 167 final DocletTag tag = method.getTagByName( getNS() + Tags.DELIMITER + KEY ); 168 if( tag != null ) 169 { 170 type = 171 resolveType( getNamedParameter( tag, TYPE_PARAM, CONTEXT_CLASS ) ); 172 strategy = getNamedParameter( tag, STRATEGY_PARAM, null ); 173 break; 174 } 175 } 176 177 Properties properties = null; 178 if( strategy != null ) 179 { 180 properties = new Properties (); 181 properties.setProperty( 182 ContextDescriptor.STRATEGY_KEY, strategy ); 183 } 184 185 return new ContextDescriptor( type, entries, properties ); 186 } 187 } 188 189 private EntryDescriptor getEntry( DocletTag tag ) 190 { 191 final String key = getNamedParameter( tag, KEY_PARAM ); 192 final String alias = getNamedParameter( tag, ALIAS_PARAM, null ); 193 final String entryType = getNamedParameter( tag, TYPE_PARAM, "java.lang.String" ); 194 final String optional = getNamedParameter( tag, OPTIONAL_PARAM, "false" ); 195 final boolean isOptional = "true".equals( optional ); 196 final String volatileValue = getNamedParameter( tag, VOLATILE_PARAM, "false" ); 197 final boolean isVolatile = "true".equals( volatileValue ); 198 return new EntryDescriptor( key, entryType, isOptional, isVolatile, alias ); 199 } 200 } 201 | Popular Tags |