1*650b9f74SAndroid Build Coastguard Worker /* 2*650b9f74SAndroid Build Coastguard Worker * Copyright (C) 2010 Google Inc. 3*650b9f74SAndroid Build Coastguard Worker * 4*650b9f74SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*650b9f74SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*650b9f74SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*650b9f74SAndroid Build Coastguard Worker * 8*650b9f74SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*650b9f74SAndroid Build Coastguard Worker * 10*650b9f74SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*650b9f74SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*650b9f74SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*650b9f74SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*650b9f74SAndroid Build Coastguard Worker * limitations under the License. 15*650b9f74SAndroid Build Coastguard Worker */ 16*650b9f74SAndroid Build Coastguard Worker 17*650b9f74SAndroid Build Coastguard Worker package org.clearsilver; 18*650b9f74SAndroid Build Coastguard Worker 19*650b9f74SAndroid Build Coastguard Worker import java.io.IOException; 20*650b9f74SAndroid Build Coastguard Worker 21*650b9f74SAndroid Build Coastguard Worker /** 22*650b9f74SAndroid Build Coastguard Worker * Utility class that delegates all methods of an CS object. Made to 23*650b9f74SAndroid Build Coastguard Worker * facilitate the transition to CS being an interface and thus not 24*650b9f74SAndroid Build Coastguard Worker * extensible in the same way as it was. 25*650b9f74SAndroid Build Coastguard Worker * <p> 26*650b9f74SAndroid Build Coastguard Worker * This class, and its subclasses must take care to wrap or unwrap HDF and CS 27*650b9f74SAndroid Build Coastguard Worker * objects as they are passed through from the callers to the delegate object. 28*650b9f74SAndroid Build Coastguard Worker * 29*650b9f74SAndroid Build Coastguard Worker */ 30*650b9f74SAndroid Build Coastguard Worker public abstract class DelegatedCs implements CS { 31*650b9f74SAndroid Build Coastguard Worker private final CS cs; 32*650b9f74SAndroid Build Coastguard Worker DelegatedCs(CS cs)33*650b9f74SAndroid Build Coastguard Worker public DelegatedCs(CS cs) { 34*650b9f74SAndroid Build Coastguard Worker // Give it an empty HDF. We aren't going to be using the super object anyways. 35*650b9f74SAndroid Build Coastguard Worker this.cs = cs; 36*650b9f74SAndroid Build Coastguard Worker } 37*650b9f74SAndroid Build Coastguard Worker getCs()38*650b9f74SAndroid Build Coastguard Worker public CS getCs() { 39*650b9f74SAndroid Build Coastguard Worker return cs; 40*650b9f74SAndroid Build Coastguard Worker } 41*650b9f74SAndroid Build Coastguard Worker 42*650b9f74SAndroid Build Coastguard Worker /** 43*650b9f74SAndroid Build Coastguard Worker * Method subclasses are required to override with a method that returns a 44*650b9f74SAndroid Build Coastguard Worker * new DelegatedHdf object that wraps the specified HDF object. 45*650b9f74SAndroid Build Coastguard Worker * 46*650b9f74SAndroid Build Coastguard Worker * @param hdf an HDF object that should be wrapped in a new DelegatedHdf 47*650b9f74SAndroid Build Coastguard Worker * object of the same type as this current object. 48*650b9f74SAndroid Build Coastguard Worker * @return an object that is a subclass of DelegatedHdf and which wraps the 49*650b9f74SAndroid Build Coastguard Worker * given HDF object. 50*650b9f74SAndroid Build Coastguard Worker */ newDelegatedHdf(HDF hdf)51*650b9f74SAndroid Build Coastguard Worker protected abstract DelegatedHdf newDelegatedHdf(HDF hdf); 52*650b9f74SAndroid Build Coastguard Worker setGlobalHDF(HDF global)53*650b9f74SAndroid Build Coastguard Worker public void setGlobalHDF(HDF global) { 54*650b9f74SAndroid Build Coastguard Worker if (global != null && global instanceof DelegatedHdf) { 55*650b9f74SAndroid Build Coastguard Worker global = ((DelegatedHdf)global).getHdf(); 56*650b9f74SAndroid Build Coastguard Worker } 57*650b9f74SAndroid Build Coastguard Worker getCs().setGlobalHDF(global); 58*650b9f74SAndroid Build Coastguard Worker } 59*650b9f74SAndroid Build Coastguard Worker getGlobalHDF()60*650b9f74SAndroid Build Coastguard Worker public HDF getGlobalHDF() { 61*650b9f74SAndroid Build Coastguard Worker HDF hdf = getCs().getGlobalHDF(); 62*650b9f74SAndroid Build Coastguard Worker return hdf != null ? newDelegatedHdf(hdf) : null; 63*650b9f74SAndroid Build Coastguard Worker } 64*650b9f74SAndroid Build Coastguard Worker close()65*650b9f74SAndroid Build Coastguard Worker public void close() { 66*650b9f74SAndroid Build Coastguard Worker getCs().close(); 67*650b9f74SAndroid Build Coastguard Worker } 68*650b9f74SAndroid Build Coastguard Worker parseFile(String filename)69*650b9f74SAndroid Build Coastguard Worker public void parseFile(String filename) throws IOException { 70*650b9f74SAndroid Build Coastguard Worker getCs().parseFile(filename); 71*650b9f74SAndroid Build Coastguard Worker } parseStr(String content)72*650b9f74SAndroid Build Coastguard Worker public void parseStr(String content) { 73*650b9f74SAndroid Build Coastguard Worker getCs().parseStr(content); 74*650b9f74SAndroid Build Coastguard Worker } 75*650b9f74SAndroid Build Coastguard Worker render()76*650b9f74SAndroid Build Coastguard Worker public String render() { 77*650b9f74SAndroid Build Coastguard Worker return getCs().render(); 78*650b9f74SAndroid Build Coastguard Worker } 79*650b9f74SAndroid Build Coastguard Worker getFileLoader()80*650b9f74SAndroid Build Coastguard Worker public CSFileLoader getFileLoader() { 81*650b9f74SAndroid Build Coastguard Worker return getCs().getFileLoader(); 82*650b9f74SAndroid Build Coastguard Worker } 83*650b9f74SAndroid Build Coastguard Worker setFileLoader(CSFileLoader fileLoader)84*650b9f74SAndroid Build Coastguard Worker public void setFileLoader(CSFileLoader fileLoader) { 85*650b9f74SAndroid Build Coastguard Worker getCs().setFileLoader(fileLoader); 86*650b9f74SAndroid Build Coastguard Worker } 87*650b9f74SAndroid Build Coastguard Worker 88*650b9f74SAndroid Build Coastguard Worker } 89