001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.hivemind.schema.rules;
016    
017    import org.apache.hivemind.Element;
018    import org.apache.hivemind.schema.Rule;
019    import org.apache.hivemind.schema.SchemaProcessor;
020    import org.apache.hivemind.schema.Translator;
021    
022    /**
023     * A rule that reads the element's content, passes it through the content translator, then pushes
024     * the result onto the processor stack.
025     * 
026     * @since 1.1
027     * @author Knut Wannheden
028     */
029    public class PushContentRule extends BaseRule implements Rule
030    {
031        /**
032         * Uses the content translator to convert the element content into an object and pushes that
033         * object onto the processor stack.
034         */
035        public void begin(SchemaProcessor processor, Element element)
036        {
037            Translator t = processor.getContentTranslator();
038    
039            String value = RuleUtils.processText(processor, element, element.getContent());
040    
041            Object finalValue = t.translate(
042                    processor.getContributingModule(),
043                    Object.class,
044                    value,
045                    element.getLocation());
046    
047            processor.push(finalValue);
048        }
049    
050        /**
051         * Invokes {@link SchemaProcessor#pop()}.
052         */
053        public void end(SchemaProcessor processor, Element element)
054        {
055            processor.pop();
056        }
057    }