@Test public void testBasicServiceMetadata() { HashMap<String, List<String>> metadata = new HashMap<String, List<String>>(); ReflectionHelper.parseServiceMetadataString(GOOD_METADATA, metadata); Assert.assertEquals(metadata.get(KEY1).get(0), VALUE1); Assert.assertEquals(metadata.get(KEY1).get(1), VALUE2); Assert.assertEquals(metadata.get(KEY2).get(0), VALUE2); Assert.assertEquals(metadata.get(MULTI_KEY).get(0), NAKED_MULTI_VALUE); }
public static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata) { StringBuffer sb = new StringBuffer(metadataField); int dot = 0; int nextEquals = sb.indexOf(EQUALS_STRING, dot); while (nextEquals > 0) { String key = sb.substring(dot, nextEquals); dot = nextEquals + 1; int commaPlace; String value = null; if (sb.charAt(dot) == '\"') { dot++; int nextQuote = sb.indexOf(QUOTE_STRING, dot); if (nextQuote < 0) { throw new IllegalStateException("Badly formed metadata \"" + metadataField + "\" for key " + key + " has a leading quote but no trailing quote"); } value = sb.substring(dot, nextQuote); dot = nextQuote + 1; commaPlace = sb.indexOf(COMMA_STRING, dot); } else { commaPlace = sb.indexOf(COMMA_STRING, dot); if (commaPlace < 0) { value = sb.substring(dot); } else { value = sb.substring(dot, commaPlace); } } List<String> addToMe = metadata.get(key); if (addToMe == null) { addToMe = new LinkedList<String>(); metadata.put(key, addToMe); } addToMe.add(value); if (commaPlace >= 0) { dot = commaPlace + 1; nextEquals = sb.indexOf(EQUALS_STRING, dot); } else { nextEquals = -1; } } }
ReflectionHelper { public static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata) { StringBuffer sb = new StringBuffer(metadataField); int dot = 0; int nextEquals = sb.indexOf(EQUALS_STRING, dot); while (nextEquals > 0) { String key = sb.substring(dot, nextEquals); dot = nextEquals + 1; int commaPlace; String value = null; if (sb.charAt(dot) == '\"') { dot++; int nextQuote = sb.indexOf(QUOTE_STRING, dot); if (nextQuote < 0) { throw new IllegalStateException("Badly formed metadata \"" + metadataField + "\" for key " + key + " has a leading quote but no trailing quote"); } value = sb.substring(dot, nextQuote); dot = nextQuote + 1; commaPlace = sb.indexOf(COMMA_STRING, dot); } else { commaPlace = sb.indexOf(COMMA_STRING, dot); if (commaPlace < 0) { value = sb.substring(dot); } else { value = sb.substring(dot, commaPlace); } } List<String> addToMe = metadata.get(key); if (addToMe == null) { addToMe = new LinkedList<String>(); metadata.put(key, addToMe); } addToMe.add(value); if (commaPlace >= 0) { dot = commaPlace + 1; nextEquals = sb.indexOf(EQUALS_STRING, dot); } else { nextEquals = -1; } } } }
ReflectionHelper { public static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata) { StringBuffer sb = new StringBuffer(metadataField); int dot = 0; int nextEquals = sb.indexOf(EQUALS_STRING, dot); while (nextEquals > 0) { String key = sb.substring(dot, nextEquals); dot = nextEquals + 1; int commaPlace; String value = null; if (sb.charAt(dot) == '\"') { dot++; int nextQuote = sb.indexOf(QUOTE_STRING, dot); if (nextQuote < 0) { throw new IllegalStateException("Badly formed metadata \"" + metadataField + "\" for key " + key + " has a leading quote but no trailing quote"); } value = sb.substring(dot, nextQuote); dot = nextQuote + 1; commaPlace = sb.indexOf(COMMA_STRING, dot); } else { commaPlace = sb.indexOf(COMMA_STRING, dot); if (commaPlace < 0) { value = sb.substring(dot); } else { value = sb.substring(dot, commaPlace); } } List<String> addToMe = metadata.get(key); if (addToMe == null) { addToMe = new LinkedList<String>(); metadata.put(key, addToMe); } addToMe.add(value); if (commaPlace >= 0) { dot = commaPlace + 1; nextEquals = sb.indexOf(EQUALS_STRING, dot); } else { nextEquals = -1; } } }  }
ReflectionHelper { public static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata) { StringBuffer sb = new StringBuffer(metadataField); int dot = 0; int nextEquals = sb.indexOf(EQUALS_STRING, dot); while (nextEquals > 0) { String key = sb.substring(dot, nextEquals); dot = nextEquals + 1; int commaPlace; String value = null; if (sb.charAt(dot) == '\"') { dot++; int nextQuote = sb.indexOf(QUOTE_STRING, dot); if (nextQuote < 0) { throw new IllegalStateException("Badly formed metadata \"" + metadataField + "\" for key " + key + " has a leading quote but no trailing quote"); } value = sb.substring(dot, nextQuote); dot = nextQuote + 1; commaPlace = sb.indexOf(COMMA_STRING, dot); } else { commaPlace = sb.indexOf(COMMA_STRING, dot); if (commaPlace < 0) { value = sb.substring(dot); } else { value = sb.substring(dot, commaPlace); } } List<String> addToMe = metadata.get(key); if (addToMe == null) { addToMe = new LinkedList<String>(); metadata.put(key, addToMe); } addToMe.add(value); if (commaPlace >= 0) { dot = commaPlace + 1; nextEquals = sb.indexOf(EQUALS_STRING, dot); } else { nextEquals = -1; } } }  static Class<?> getRawClass(Type type); static Type resolveField(Class<?> topclass, Field field); static Type resolveMember(Class<?> topclass, Type lookingForType, Class<?> declaringClass); static Type resolveKnownType(TypeVariable<?> userType, ParameterizedType knownType, Class<?> knownDeclaringClass); static Type getFirstTypeArgument(Type type); static String getName(Class<?> implClass); static Set<Type> getTypeClosure(Type ofType, Set<String> contracts); static Set<Type> getAdvertisedTypesFromClass(Type type, Class<? extends Annotation> markerAnnotation); static Set<Type> getAdvertisedTypesFromObject(Object t, Class<? extends Annotation> markerAnnotation); static Set<String> getContractsFromClass(Class<?> clazz, Class<? extends Annotation> markerAnnotation); static Annotation getScopeAnnotationFromObject(Object t); static Annotation getScopeAnnotationFromClass(Class<?> clazz); static Annotation getScopeFromObject(Object t, Annotation annoDefault); static Annotation getScopeFromClass(Class<?> clazz, Annotation annoDefault); static boolean isAnnotationAQualifier(Annotation anno); static Set<Annotation> getQualifiersFromObject(Object t); static Set<String> getQualifiersFromClass(Class<?> clazz); static Set<Annotation> getQualifierAnnotations(final AnnotatedElement annotatedGuy); static String writeSet(Set<?> set); static String writeSet(Set<?> set, Object excludeMe); static void readSet(String line, Collection<String> addToMe); static void readMetadataMap(String line, Map<String, List<String>> addToMe); static String writeMetadata(Map<String, List<String>> metadata); static void addMetadata(Map<String, List<String>> metadatas, String key, String value); static boolean removeMetadata(Map<String, List<String>> metadatas, String key, String value); static boolean removeAllMetadata(Map<String, List<String>> metadatas, String key); static Map<String, List<String>> deepCopyMetadata(Map<String, List<String>> copyMe); static void setField(Field field, Object instance, Object value); static Object invoke(Object o, Method m, Object args[], boolean neutralCCL); static boolean isStatic(Member member); static Object makeMe(Constructor<?> c, Object args[], boolean neutralCCL); static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata); static String getNameFromAllQualifiers(Set<Annotation> qualifiers, AnnotatedElement parent); static boolean annotationContainsAll(final Set<Annotation> candidateAnnotations, final Set<Annotation> requiredAnnotations); static Class<?> translatePrimitiveType(Class<?> type); static boolean isPrivate(Member member); static Set<Type> getAllTypes(Type t); static MethodWrapper createMethodWrapper(Method wrapMe); @SuppressWarnings("unchecked") static T cast(Object o); }
ReflectionHelper { public static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata) { StringBuffer sb = new StringBuffer(metadataField); int dot = 0; int nextEquals = sb.indexOf(EQUALS_STRING, dot); while (nextEquals > 0) { String key = sb.substring(dot, nextEquals); dot = nextEquals + 1; int commaPlace; String value = null; if (sb.charAt(dot) == '\"') { dot++; int nextQuote = sb.indexOf(QUOTE_STRING, dot); if (nextQuote < 0) { throw new IllegalStateException("Badly formed metadata \"" + metadataField + "\" for key " + key + " has a leading quote but no trailing quote"); } value = sb.substring(dot, nextQuote); dot = nextQuote + 1; commaPlace = sb.indexOf(COMMA_STRING, dot); } else { commaPlace = sb.indexOf(COMMA_STRING, dot); if (commaPlace < 0) { value = sb.substring(dot); } else { value = sb.substring(dot, commaPlace); } } List<String> addToMe = metadata.get(key); if (addToMe == null) { addToMe = new LinkedList<String>(); metadata.put(key, addToMe); } addToMe.add(value); if (commaPlace >= 0) { dot = commaPlace + 1; nextEquals = sb.indexOf(EQUALS_STRING, dot); } else { nextEquals = -1; } } }  static Class<?> getRawClass(Type type); static Type resolveField(Class<?> topclass, Field field); static Type resolveMember(Class<?> topclass, Type lookingForType, Class<?> declaringClass); static Type resolveKnownType(TypeVariable<?> userType, ParameterizedType knownType, Class<?> knownDeclaringClass); static Type getFirstTypeArgument(Type type); static String getName(Class<?> implClass); static Set<Type> getTypeClosure(Type ofType, Set<String> contracts); static Set<Type> getAdvertisedTypesFromClass(Type type, Class<? extends Annotation> markerAnnotation); static Set<Type> getAdvertisedTypesFromObject(Object t, Class<? extends Annotation> markerAnnotation); static Set<String> getContractsFromClass(Class<?> clazz, Class<? extends Annotation> markerAnnotation); static Annotation getScopeAnnotationFromObject(Object t); static Annotation getScopeAnnotationFromClass(Class<?> clazz); static Annotation getScopeFromObject(Object t, Annotation annoDefault); static Annotation getScopeFromClass(Class<?> clazz, Annotation annoDefault); static boolean isAnnotationAQualifier(Annotation anno); static Set<Annotation> getQualifiersFromObject(Object t); static Set<String> getQualifiersFromClass(Class<?> clazz); static Set<Annotation> getQualifierAnnotations(final AnnotatedElement annotatedGuy); static String writeSet(Set<?> set); static String writeSet(Set<?> set, Object excludeMe); static void readSet(String line, Collection<String> addToMe); static void readMetadataMap(String line, Map<String, List<String>> addToMe); static String writeMetadata(Map<String, List<String>> metadata); static void addMetadata(Map<String, List<String>> metadatas, String key, String value); static boolean removeMetadata(Map<String, List<String>> metadatas, String key, String value); static boolean removeAllMetadata(Map<String, List<String>> metadatas, String key); static Map<String, List<String>> deepCopyMetadata(Map<String, List<String>> copyMe); static void setField(Field field, Object instance, Object value); static Object invoke(Object o, Method m, Object args[], boolean neutralCCL); static boolean isStatic(Member member); static Object makeMe(Constructor<?> c, Object args[], boolean neutralCCL); static void parseServiceMetadataString(String metadataField, Map<String, List<String>> metadata); static String getNameFromAllQualifiers(Set<Annotation> qualifiers, AnnotatedElement parent); static boolean annotationContainsAll(final Set<Annotation> candidateAnnotations, final Set<Annotation> requiredAnnotations); static Class<?> translatePrimitiveType(Class<?> type); static boolean isPrivate(Member member); static Set<Type> getAllTypes(Type t); static MethodWrapper createMethodWrapper(Method wrapMe); @SuppressWarnings("unchecked") static T cast(Object o);  }