List<Converter> getConverters() { List<Converter> converters = new LinkedList<>(); converters.addAll(ConverterFactory.getHighPriorityConverters()); converters.addAll(this.converters); converters.addAll(ConverterFactory.getLowPriorityConverters()); return Collections.unmodifiableList(converters); }
/** * 将旧的 serializedObject converter为 新的 serializedObject,如果expectedContentType 和旧的一致,那么直接返回 只是一个确认操作 * * @param serializedObject The object to convert * @param expectedContentType The content type of the SerializedObject to return * @return a SerializedObject containing data in the expected content type */ @SuppressWarnings("unchecked") protected <S, T> SerializedObject<T> ensureCorrectContentType( SerializedObject<S> serializedObject, Class<T> expectedContentType) { if (!expectedContentType.isAssignableFrom(serializedObject.getContentType())) { ContentTypeConverter<S, T> converter = converterFactory.getConverter(serializedObject.getContentType(), expectedContentType); return converter.convert(serializedObject); } return (SerializedObject<T>) serializedObject; }
@SuppressWarnings("unchecked") @Override public <R> SerializedObject<R> serializeMetaData( Serializer serializer, Class<R> expectedRepresentation) { if (serializer.equals(serializedMetaData.getSerializer())) { final SerializedObject serializedObject = serializedMetaData.getSerializedObject(); return CONVERTER_FACTORY .getConverter(serializedObject.getContentType(), expectedRepresentation) .convert(serializedObject); } return serializer.serialize(serializedMetaData.getObject(), expectedRepresentation); }
public void testSetConvertedWithCustomConverter() { // save old converter for restore Converter<Date> oldConverter = ConverterFactory.factory.getConverter(Date.class); try { ConverterFactory.addConverter( Date.class, new Converter<Date>() { @Override protected Date convert(Object value, Class<Date> type) { if (value == null) return null; if (value instanceof Date) { return (Date) value; } if (value instanceof String) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { return format.parse((String) value); } catch (ParseException e) { throw new CayenneRuntimeException( "Unable to convert '" + value + "' to a Date", e); } } throw new CayenneRuntimeException("Unable to convert '" + value + "' to a Date"); } }); TstJavaBean o1 = new TstJavaBean(); // String to date PropertyUtils.setProperty(o1, "dateField", "2013-08-01"); Calendar cal = new GregorianCalendar(2013, 7, 1, 0, 0, 0); assertEquals(cal.getTime(), o1.getDateField()); } finally { // restore global date converter ConverterFactory.addConverter(Date.class, oldConverter); } }
@Override public PMML encodePMML() { RGenericVector train = getObject(); RExp finalModel = train.getValue("finalModel"); RGenericVector preProcess = (RGenericVector) train.getValue("preProcess"); ConverterFactory converterFactory = ConverterFactory.newInstance(); ModelConverter<RExp> converter = (ModelConverter<RExp>) converterFactory.newConverter(finalModel); FeatureMapper featureMapper; if (preProcess != null) { featureMapper = new PreProcessFeatureMapper(preProcess); } else { featureMapper = new FeatureMapper(); } return converter.encodePMML(featureMapper); }
/** * Creates, binds and configures the UI components. * * <p>If possible, the components are created using the BasicComponentFactory, or the Bindings * class. */ private void initComponents() { // Text Components textField = BasicComponentFactory.createTextField( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); textArea = BasicComponentFactory.createTextArea( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); passwordField = BasicComponentFactory.createPasswordField( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); textLabel = BasicComponentFactory.createLabel( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); // Formatted Input dateField = BasicComponentFactory.createDateField( presentationModel.getModel(ExampleBean.PROPERTYNAME_DATE)); integerField = BasicComponentFactory.createIntegerField( presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_VALUE)); longField = BasicComponentFactory.createLongField( presentationModel.getModel(ExampleBean.PROPERTYNAME_LONG_VALUE)); // Choice ValueModel intChoiceModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_CHOICE); leftIntRadio = BasicComponentFactory.createRadioButton(intChoiceModel, ExampleBean.LEFT_INTEGER, "Left"); centerIntRadio = BasicComponentFactory.createRadioButton( intChoiceModel, ExampleBean.CENTER_INTEGER, "Center"); rightIntRadio = BasicComponentFactory.createRadioButton(intChoiceModel, ExampleBean.RIGHT_INTEGER, "Right"); alignmentIntCombo = BasicComponentFactory.createComboBox( new SelectionInList(ExampleBean.INTEGER_CHOICES, intChoiceModel)); ValueModel objectChoiceModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_OBJECT_CHOICE); leftObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.LEFT, "Left"); centerObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.CENTER, "Center"); rightObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.RIGHT, "Right"); alignmentObjectCombo = BasicComponentFactory.createComboBox( new SelectionInList(ExampleBean.OBJECT_CHOICES, objectChoiceModel)); // Lists comboBox = BasicComponentFactory.createComboBox( presentationModel.getSelectionInList(), TutorialUtils.createAlbumListCellRenderer()); list = BasicComponentFactory.createList( presentationModel.getSelectionInList(), TutorialUtils.createAlbumListCellRenderer()); table = new JTable(); table.setModel(TutorialUtils.createAlbumTableModel(presentationModel.getSelectionInList())); table.setSelectionModel( new SingleListSelectionAdapter( presentationModel.getSelectionInList().getSelectionIndexHolder())); // Misc checkBox = BasicComponentFactory.createCheckBox( presentationModel.getModel(ExampleBean.PROPERTYNAME_BOOLEAN_VALUE), "available"); colorPreview = new JPanel(); colorPreview.setBorder(new LineBorder(Color.GRAY)); updatePreviewPanel(); ValueModel floatModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_FLOAT_VALUE); slider = new JSlider(); slider.setModel( new BoundedRangeAdapter( ConverterFactory.createFloatToIntegerConverter(floatModel, 100), 0, 0, 100)); floatLabel = BasicComponentFactory.createLabel( ConverterFactory.createStringConverter(floatModel, NumberFormat.getPercentInstance())); spinner = new JSpinner(); spinner.setModel( SpinnerAdapterFactory.createNumberAdapter( presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_LIMITED), 0, // defaultValue 0, // minValue 100, // maxValue 5)); // step }