this.tokenClass = ReflectionUtil.<Class<? extends TOP>> uncheckedCast(ReflectionUtil .getTypeArgument(PosAnnotator.class, "TOKEN_TYPE", this)); this.sentenceClass = ReflectionUtil.<Class<? extends TOP>> uncheckedCast(ReflectionUtil .getTypeArgument(PosAnnotator.class, "SENTENCE_TYPE", this)); ReflectionUtil.checkTypeParameterIsAssignable( PosFeatureExtractor.class, "TOKEN_TYPE", "TOKEN_TYPE", this); ReflectionUtil.checkTypeParameterIsAssignable( PosFeatureExtractor.class, "SENTENCE_TYPE", this.featureExtractor = ReflectionUtil.uncheckedCast(untypedExtractor);
private static Map<String, Type> getTypeArguments( Class<?> genericType, Type type, Map<String, Type> typeMap) { if (type instanceof ParameterizedType) { return getTypeArguments(genericType, (ParameterizedType) type, typeMap); } else if (type instanceof Class<?>) { return getTypeArguments(genericType, (Class<?>) type, typeMap); } else { throw new IllegalArgumentException("type must be a ParameterizedType or Class"); } }
@SuppressWarnings("unchecked") private FeaturesEncoder<ENCODED_FEATURES_TYPE> featuresEncoderCast(Object object) { FeaturesEncoder<ENCODED_FEATURES_TYPE> encoder = (FeaturesEncoder<ENCODED_FEATURES_TYPE>) object; ReflectionUtil.checkTypeParametersAreEqual( EncodingJarClassifierBuilder.class, "ENCODED_FEATURES_TYPE", this, FeaturesEncoder.class, "ENCODED_FEATURES_TYPE", encoder, ClassCastException.class); return encoder; }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); String className = String.format("org.tartarus.snowball.ext.%sStemmer", stemmerName); this.stemmer = InitializableFactory.create(null, className, SnowballProgram.class); this.tokenClass = ReflectionUtil.<Class<? extends Annotation>> uncheckedCast(ReflectionUtil.getTypeArgument( SnowballStemmer.class, "TOKEN_TYPE", this)); }
ReflectionUtil.checkTypeParameterIsAssignable( FeaturesEncoder.class, "ENCODED_FEATURES_TYPE", ReflectionUtil.checkTypeParameterIsAssignable( OutcomeEncoder.class, "OUTCOME_TYPE", "OUTCOME_TYPE", this); ReflectionUtil.checkTypeParameterIsAssignable( OutcomeEncoder.class, "ENCODED_OUTCOME_TYPE", this.featuresEncoder = ReflectionUtil.uncheckedCast(untypedFeaturesEncoder); this.outcomeEncoder = ReflectionUtil.uncheckedCast(untypedOutcomeEncoder); is.close(); } catch (Exception e) {
Annotation.class); Class<? extends AnnotationWriter<ANNOTATION_TYPE>> annotationWriterClass = ReflectionUtil.uncheckedCast(Class.forName( annotationWriterClassName).asSubclass(AnnotationWriter.class)); annotationWriter = InitializableFactory.create( java.lang.reflect.Type annotationType = ReflectionUtil.getTypeArgument( AnnotationWriter.class, "ANNOTATION_TYPE", this.annotationWriter); if (!ReflectionUtil.isAssignableFrom(annotationType, outputAnnotationClass)) { throw CleartkInitializationException.incompatibleTypeParameterAndType( this.annotationWriter, Class<? extends BlockWriter<BLOCK_TYPE>> blockWriterClass = ReflectionUtil.uncheckedCast(Class.forName( blockWriterClassName).asSubclass(BlockWriter.class)); this.blockWriter = InitializableFactory.create( java.lang.reflect.Type blockType = ReflectionUtil.getTypeArgument( BlockWriter.class, "BLOCK_TYPE", this.blockWriter); if (!ReflectionUtil.isAssignableFrom(blockType, blockAnnotationClass)) { throw CleartkInitializationException.incompatibleTypeParameterAndType( this.blockWriter,
private Class<ClassifierTrainerFactory<?>> createTrainerFactory(String className) { try { return ReflectionUtil.uncheckedCast(Class.forName(className)); } catch (ClassNotFoundException cnfe) { return null; } }
java.lang.reflect.Type type1 = ReflectionUtil.getTypeArgument( paramDefiningClass1, paramName1, object1); java.lang.reflect.Type type2 = ReflectionUtil.getTypeArgument( paramDefiningClass2, paramName2, if (type1 == null || type2 == null || !ReflectionUtil.isAssignableFrom(type1, type2)) { throw CleartkInitializationException.incompatibleTypeParameters( object1,
private static Map<String, Type> getTypeArguments( Class<?> genericType, ParameterizedType paramType, Map<String, Type> typeMap) { Class<?> rawType = (Class<?>) paramType.getRawType(); if (rawType == genericType) { // found it! TypeVariable<?> typeVars[] = rawType.getTypeParameters(); Type actualTypes[] = paramType.getActualTypeArguments(); Map<String, Type> result = new TreeMap<String, Type>(); for (int i = 0; i < actualTypes.length; i++) { while (actualTypes[i] != null && actualTypes[i] instanceof TypeVariable<?>) { String key = typevarString((TypeVariable<?>) actualTypes[i]); if (typeMap.containsKey(key)) actualTypes[i] = typeMap.get(key); else actualTypes[i] = null; } result.put(typeVars[i].getName(), actualTypes[i]); } return result; } else { TypeVariable<?> typeVars[] = rawType.getTypeParameters(); Type actualTypes[] = paramType.getActualTypeArguments(); for (int i = 0; i < typeVars.length; i++) typeMap.put(typevarString(typeVars[i]), actualTypes[i]); return getTypeArguments(genericType, paramType.getRawType(), typeMap); } }
java.lang.reflect.Type type1 = ReflectionUtil.getTypeArgument( paramDefiningClass1, paramName1, object1); java.lang.reflect.Type type2 = ReflectionUtil.getTypeArgument( paramDefiningClass2, paramName2,
Classifier<OUTCOME_TYPE> classifier = ReflectionUtil.uncheckedCast(untypedClassifier); ReflectionUtil.checkTypeParameterIsAssignable( CleartkMultiAnnotator.class, "OUTCOME_TYPE",
Annotation.class); Class<? extends AnnotationWriter<ANNOTATION_TYPE>> annotationWriterClass = ReflectionUtil.uncheckedCast(Class.forName( annotationWriterClassName).asSubclass(AnnotationWriter.class)); annotationWriter = InitializableFactory.create( java.lang.reflect.Type annotationType = ReflectionUtil.getTypeArgument( AnnotationWriter.class, "ANNOTATION_TYPE", this.annotationWriter); if (!ReflectionUtil.isAssignableFrom(annotationType, outputAnnotationClass)) { throw CleartkInitializationException.incompatibleTypeParameterAndType( this.annotationWriter, Class<? extends BlockWriter<BLOCK_TYPE>> blockWriterClass = ReflectionUtil.uncheckedCast(Class.forName( blockWriterClassName).asSubclass(BlockWriter.class)); this.blockWriter = InitializableFactory.create( java.lang.reflect.Type blockType = ReflectionUtil.getTypeArgument( BlockWriter.class, "BLOCK_TYPE", this.blockWriter); if (!ReflectionUtil.isAssignableFrom(blockType, blockAnnotationClass)) { throw CleartkInitializationException.incompatibleTypeParameterAndType( this.blockWriter,
private Class<ClassifierTrainerFactory<?>> createTrainerFactory(String className) { try { return ReflectionUtil.uncheckedCast(Class.forName(className)); } catch (ClassNotFoundException cnfe) { return null; } }
java.lang.reflect.Type type1 = ReflectionUtil.getTypeArgument( paramDefiningClass1, paramName1, object1); java.lang.reflect.Type type2 = ReflectionUtil.getTypeArgument( paramDefiningClass2, paramName2, if (type1 == null || type2 == null || !ReflectionUtil.isAssignableFrom(type1, type2)) { throw CleartkInitializationException.incompatibleTypeParameters( object1,
private static Map<String, Type> getTypeArguments( Class<?> genericType, ParameterizedType paramType, Map<String, Type> typeMap) { Class<?> rawType = (Class<?>) paramType.getRawType(); if (rawType == genericType) { // found it! TypeVariable<?> typeVars[] = rawType.getTypeParameters(); Type actualTypes[] = paramType.getActualTypeArguments(); Map<String, Type> result = new TreeMap<String, Type>(); for (int i = 0; i < actualTypes.length; i++) { while (actualTypes[i] != null && actualTypes[i] instanceof TypeVariable<?>) { String key = typevarString((TypeVariable<?>) actualTypes[i]); if (typeMap.containsKey(key)) actualTypes[i] = typeMap.get(key); else actualTypes[i] = null; } result.put(typeVars[i].getName(), actualTypes[i]); } return result; } else { TypeVariable<?> typeVars[] = rawType.getTypeParameters(); Type actualTypes[] = paramType.getActualTypeArguments(); for (int i = 0; i < typeVars.length; i++) typeMap.put(typevarString(typeVars[i]), actualTypes[i]); return getTypeArguments(genericType, paramType.getRawType(), typeMap); } }
java.lang.reflect.Type type1 = ReflectionUtil.getTypeArgument( paramDefiningClass1, paramName1, object1); java.lang.reflect.Type type2 = ReflectionUtil.getTypeArgument( paramDefiningClass2, paramName2,
this.dataWriter = ReflectionUtil.uncheckedCast(untypedDataWriter); } else { this.classifier = ReflectionUtil.uncheckedCast(untypedClassifier); ReflectionUtil.checkTypeParameterIsAssignable( CleartkSequenceAnnotator.class, "OUTCOME_TYPE",
/** * Gets the {@link DataWriter} associated with name. If it does not exist, this method will use * the {@link DataWriterFactory} specified during initialization to create a dataWriter associated * with the name parameter. * * @param name * The name of the {@link DataWriter} * @return The {@link DataWriter} associated with the name */ protected DataWriter<OUTCOME_TYPE> getDataWriter(String name) throws ResourceInitializationException { if (dataWriters.containsKey(name)) { return dataWriters.get(name); } DataWriter<?> untypedDataWriter; File dataWriterPath = new File(this.outputDirectoryRoot, name); UimaContextAdmin contextAdmin = (UimaContextAdmin) this.uimaContext; ConfigurationManager manager = contextAdmin.getConfigurationManager(); manager.setConfigParameterValue(contextAdmin.getQualifiedContextName() + DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, dataWriterPath); try { untypedDataWriter = this.dataWriterFactory.createDataWriter(); } catch (IOException e) { throw new ResourceInitializationException(e); } InitializableFactory.initialize(untypedDataWriter, uimaContext); DataWriter<OUTCOME_TYPE> dataWriter = ReflectionUtil.uncheckedCast(untypedDataWriter); this.dataWriters.put(name, dataWriter); return dataWriter; }
private static Map<String, Type> getTypeArguments( Class<?> genericType, Type type, Map<String, Type> typeMap) { if (type instanceof ParameterizedType) { return getTypeArguments(genericType, (ParameterizedType) type, typeMap); } else if (type instanceof Class<?>) { return getTypeArguments(genericType, (Class<?>) type, typeMap); } else { throw new IllegalArgumentException("type must be a ParameterizedType or Class"); } }
@SuppressWarnings("unchecked") private OutcomeEncoder<OUTCOME_TYPE, ENCODED_OUTCOME_TYPE> outcomeEncoderCast(Object object) { OutcomeEncoder<OUTCOME_TYPE, ENCODED_OUTCOME_TYPE> encoder; encoder = (OutcomeEncoder<OUTCOME_TYPE, ENCODED_OUTCOME_TYPE>) object; ReflectionUtil.checkTypeParametersAreEqual( EncodingJarClassifierBuilder.class, "OUTCOME_TYPE", this, OutcomeEncoder.class, "OUTCOME_TYPE", encoder, ClassCastException.class); ReflectionUtil.checkTypeParametersAreEqual( EncodingJarClassifierBuilder.class, "ENCODED_OUTCOME_TYPE", this, OutcomeEncoder.class, "ENCODED_OUTCOME_TYPE", encoder, ClassCastException.class); return encoder; } }