1 /* 2 * Copyright 2004-2008 the Seasar Foundation and the Others. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 * either express or implied. See the License for the specific language 14 * governing permissions and limitations under the License. 15 */ 16 package org.seasar.uruma.rcp.configuration.writer; 17 18 import java.io.IOException; 19 import java.io.Writer; 20 21 import org.seasar.framework.exception.IORuntimeException; 22 import org.seasar.uruma.rcp.configuration.ConfigurationElement; 23 import org.seasar.uruma.rcp.configuration.ConfigurationWriter; 24 25 /** 26 * {@link ConfigurationWriter} のための基底クラスです。<br /> 27 * 28 * @author y-komori 29 * 30 * @param <ELEMENT_TYPE> 31 * 対応する {@link ConfigurationElement} の型 32 */ 33 public abstract class AbstractConfigurationWriter<ELEMENT_TYPE extends ConfigurationElement> 34 implements ConfigurationWriter { 35 36 /* 37 * @see org.seasar.uruma.rcp.configuration.ConfigurationWriter#writeStartTag(org.seasar.uruma.rcp.configuration.ConfigurationElement, 38 * java.io.Writer) 39 */ 40 public final Class<? extends ConfigurationElement> getSupportType() { 41 return doGetSupportType(); 42 } 43 44 /* 45 * @see org.seasar.uruma.rcp.configuration.ConfigurationWriter#writeStartTag(org.seasar.uruma.rcp.configuration.ConfigurationElement, 46 * java.io.Writer) 47 */ 48 public final void writeStartTag(final ConfigurationElement element, 49 final Writer writer) { 50 writeStartTag(element, writer, 0); 51 } 52 53 /* 54 * @see org.seasar.uruma.rcp.configuration.ConfigurationWriter#writeStartTag(org.seasar.uruma.rcp.configuration.ConfigurationElement, 55 * java.io.Writer, int) 56 */ 57 public void writeStartTag(final ConfigurationElement element, 58 final Writer writer, final int level) { 59 try { 60 doWriteStartTag(doGetSupportType().cast(element), writer, level); 61 } catch (IOException ex) { 62 throw new IORuntimeException(ex); 63 } 64 } 65 66 /* 67 * @see org.seasar.uruma.rcp.configuration.ConfigurationWriter#writeEndTag(org.seasar.uruma.rcp.configuration.ConfigurationElement, 68 * java.io.Writer) 69 */ 70 public final void writeEndTag(final ConfigurationElement element, 71 final Writer writer) { 72 writeEndTag(element, writer, 0); 73 } 74 75 /* 76 * @see org.seasar.uruma.rcp.configuration.ConfigurationWriter#writeEndTag(org.seasar.uruma.rcp.configuration.ConfigurationElement, 77 * java.io.Writer, int) 78 */ 79 public void writeEndTag(final ConfigurationElement element, 80 final Writer writer, final int level) { 81 try { 82 doWriteEndTag(doGetSupportType().cast(element), writer, level); 83 } catch (IOException ex) { 84 throw new IORuntimeException(ex); 85 } 86 } 87 88 /** 89 * 出力対象とする {@link ConfigurationElement} クラスを返します。<br /> 90 * 本メソッドはサブクラスでオーバーライドしてください。 91 * 92 * @return {@link ConfigurationElement} クラス 93 */ 94 public abstract Class<ELEMENT_TYPE> doGetSupportType(); 95 96 /** 97 * 開始タグを出力します。<br /> 98 * 本メソッドはサブクラスでオーバーライドしてください。 99 * 100 * @param element 101 * 出力対象の {@link ConfigurationElement} 102 * @param writer 103 * 出力対象の {@link Writer} オブジェクト 104 * @param level 105 * インデントレベル 106 * @throws IOException 107 */ 108 public abstract void doWriteStartTag(final ELEMENT_TYPE element, 109 final Writer writer, int level) throws IOException; 110 111 /** 112 * 終了タグを出力します。<br /> 113 * 本メソッドはサブクラスでオーバーライドしてください。 114 * 115 * @param element 116 * 出力対象の {@link ConfigurationElement} 117 * @param writer 118 * 出力対象の {@link Writer} オブジェクト 119 * @param level 120 * インデントレベル 121 * @throws IOException 122 */ 123 public abstract void doWriteEndTag(ELEMENT_TYPE element, Writer writer, 124 int level) throws IOException; 125 }