@SuppressWarnings({ "rawtypes", "unchecked" })
	private void writeComponent(ICalComponent component) throws IOException {
		ICalComponentScribe componentScribe = index.getComponentScribe(component);
		writer.writeStartComponent(componentScribe.getComponentName().toLowerCase());

		List propertyObjs = componentScribe.getProperties(component);
		if (component instanceof ICalendar && component.getProperty(Version.class) == null) {
			propertyObjs.add(0, new Version(targetVersion));
		}

		//write properties
		for (Object propertyObj : propertyObjs) {
			context.setParent(component); //set parent here incase a scribe resets the parent
			ICalProperty property = (ICalProperty) propertyObj;
			ICalPropertyScribe propertyScribe = index.getPropertyScribe(property);

			//marshal property
			ICalParameters parameters;
			JCalValue value;
			try {
				parameters = propertyScribe.prepareParameters(property, context);
				value = propertyScribe.writeJson(property, context);
			} catch (SkipMeException e) {
				continue;
			}

			//write property
			String propertyName = propertyScribe.getPropertyName(targetVersion).toLowerCase();
			ICalDataType dataType = propertyScribe.dataType(property, targetVersion);
			writer.writeProperty(propertyName, parameters, dataType, value);
		}

		//write sub-components
		List subComponents = componentScribe.getComponents(component);
		if (component instanceof ICalendar) {
			//add the VTIMEZONE components that were auto-generated by TimezoneOptions
			Collection<VTimezone> tzs = getTimezoneComponents();
			for (VTimezone tz : tzs) {
				if (!subComponents.contains(tz)) {
					subComponents.add(0, tz);
				}
			}
		}
		for (Object subComponentObj : subComponents) {
			ICalComponent subComponent = (ICalComponent) subComponentObj;
			writeComponent(subComponent);
		}

		writer.writeEndComponent();
	}
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private void writeComponent ( ICalComponent component ) throws IOException { ICalComponentScribe componentScribe = index . getComponentScribe ( component ) ; writer . writeStartComponent ( componentScribe . getComponentName ( ) . toLowerCase ( ) ) ; List propertyObjs = componentScribe . getProperties ( component ) ; if ( component instanceof ICalendar && component . getProperty ( Version . class ) == null ) { propertyObjs . add ( 0 , new Version ( targetVersion ) ) ; } for ( Object propertyObj : propertyObjs ) { context . setParent ( component ) ; ICalProperty property = ( ICalProperty ) propertyObj ; ICalPropertyScribe propertyScribe = index . getPropertyScribe ( property ) ; ICalParameters parameters ; JCalValue value ; try { parameters = propertyScribe . prepareParameters ( property , context ) ; value = propertyScribe . writeJson ( property , context ) ; } catch ( SkipMeException e ) { continue ; } String propertyName = propertyScribe . getPropertyName ( targetVersion ) . toLowerCase ( ) ; ICalDataType dataType = propertyScribe . dataType ( property , targetVersion ) ; writer . writeProperty ( propertyName , parameters , dataType , value ) ; } List subComponents = componentScribe . getComponents ( component ) ; if ( component instanceof ICalendar ) { Collection < VTimezone > tzs = getTimezoneComponents ( ) ; for ( VTimezone tz : tzs ) { if ( ! subComponents . contains ( tz ) ) { subComponents . add ( 0 , tz ) ; } } } for ( Object subComponentObj : subComponents ) { ICalComponent subComponent = ( ICalComponent ) subComponentObj ; writeComponent ( subComponent ) ; } writer . writeEndComponent ( ) ; }
Writes a component to the data stream.
@param component the component to write
@throws IllegalArgumentException if the scribe class for a component or
property object cannot be found (only happens when an experimental
property/component scribe is not registered with the
{@code registerScribe} method.)
@throws IOException if there's a problem writing to the data stream