001/**************************************************************** 002 * Licensed to the Apache Software Foundation (ASF) under one * 003 * or more contributor license agreements. See the NOTICE file * 004 * distributed with this work for additional information * 005 * regarding copyright ownership. The ASF licenses this file * 006 * to you under the Apache License, Version 2.0 (the * 007 * "License"); you may not use this file except in compliance * 008 * with the License. You may obtain a copy of the License at * 009 * * 010 * http://www.apache.org/licenses/LICENSE-2.0 * 011 * * 012 * Unless required by applicable law or agreed to in writing, * 013 * software distributed under the License is distributed on an * 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 015 * KIND, either express or implied. See the License for the * 016 * specific language governing permissions and limitations * 017 * under the License. * 018 ****************************************************************/ 019 020package org.apache.james.mime4j.stream; 021 022import org.apache.james.mime4j.MimeException; 023 024/** 025 * Body descriptor builders are intended to construct {@link BodyDescriptor} instances from 026 * multiple unstructured {@link RawField}s. 027 * <p/> 028 * Body descriptor builders are stateful and modal as they have to store intermediate results 029 * between method invocations and also rely on a particular sequence of method invocations 030 * (the mode of operation). 031 * <p/> 032 * Consumers are expected to interact with body descriptor builders in the following way: 033 * <ul> 034 * <li>Invoke {@link #reset()} method in order to reset builder's internal state and make it 035 * ready to start the process of building a new {@link BodyDescriptor}.</li> 036 * <li>Invoke {@link #addField(RawField)} multiple times method in order to collect 037 * necessary details for building a body descriptor. The builder can optionally 038 * transform the unstructured field given an an input into a structured one and return 039 * an instance {@link Field} that also implements a richer interface for a particular type 040 * of fields such as <code>Content-Type</code>. The builder can also return <code>null</code> 041 * if the field is to be ignored</li> 042 * <li>Optionally invoke {@link #newChild()} for each embedded body of content. Please note that 043 * the resultant {@link BodyDescriptorBuilder}} child instance can inherit some its parent 044 * properties such as MIME type.</li> 045 * <li>Invoke {@link #build()()} method in order to generate a {@link BodyDescriptor}} instance 046 * based on the internal state of the builder.</li> 047 * </ul> 048 */ 049public interface BodyDescriptorBuilder { 050 051 /** 052 * Resets the internal state of the builder making it ready to process new input. 053 */ 054 void reset(); 055 056 /** 057 * Updates builder's internal state by adding a new field. The builder can optionally 058 * transform the unstructured field given an an input into a structured one and return 059 * an instance {@link Field} that also implements a richer interface for a particular type 060 * of fields such as <code>Content-Type</code>. The builder can also return <code>null</code> 061 * if the field is to be ignored. 062 */ 063 Field addField(RawField field) throws MimeException; 064 065 /** 066 * Builds an instance of {@link BodyDescriptor} based on the internal state. 067 */ 068 BodyDescriptor build(); 069 070 /** 071 * Creates an instance of {@link BodyDescriptorBuilder} to be used for processing of an 072 * embedded content body. Please the child instance can inherit some of its parent properties 073 * such as MIME type. 074 */ 075 BodyDescriptorBuilder newChild(); 076 077}