001/* 002 * Visitor.java January 2010 003 * 004 * Copyright (C) 2010, Niall Gallagher <niallg@users.sf.net> 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * 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, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 015 * implied. See the License for the specific language governing 016 * permissions and limitations under the License. 017 */ 018 019package org.simpleframework.xml.strategy; 020 021import org.simpleframework.xml.stream.InputNode; 022import org.simpleframework.xml.stream.NodeMap; 023import org.simpleframework.xml.stream.OutputNode; 024 025/** 026 * The <code>Visitor</code> interface represents an object that is 027 * used to visit each XML element during serialization. For the 028 * deserialization process each XML element is visited before 029 * control is returned to the serializer. This allows a visitor 030 * implementation to perform some operation based on the node 031 * that is being deserialized. Typically a visitor is used to 032 * edit the node, for example it may remove or insert attributes. 033 * <p> 034 * In effect this can act much like a transformer that sits 035 * between a <code>Strategy</code> implementation and the core 036 * serializer. It enables interception and manipulation of the 037 * node so that the resulting XML document can be customized in 038 * a way that can not be performed by the underlying strategy. 039 * 040 * @author Niall Gallagher 041 * 042 * @see org.simpleframework.xml.strategy.VisitorStrategy 043 */ 044public interface Visitor { 045 046 /** 047 * This is used to intercept an XML element before it is read 048 * by the underlying <code>Strategy</code> implementation. When 049 * a node is intercepted it can be manipulated in such a way 050 * that its semantics change. For example, this could be used 051 * to change the way a "class" attribute is represented, which 052 * would allow the XML to appear in a language neutral format. 053 * 054 * @param type this is the type that represents the element 055 * @param node this is the XML element to be intercepted 056 */ 057 void read(Type type, NodeMap<InputNode> node) throws Exception; 058 059 /** 060 * This is used to intercept an XML element after it is written 061 * by the underlying <code>Strategy</code> implementation. When 062 * a node is intercepted it can be manipulated in such a way 063 * that its semantics change. For example, this could be used 064 * to change the way a "class" attribute is represented, which 065 * would allow the XML to appear in a language neutral format. 066 * 067 * @param type this is the type that represents the element 068 * @param node this is the XML element to be intercepted 069 */ 070 void write(Type type, NodeMap<OutputNode> node) throws Exception; 071}