Coverage Report - org.apache.myfaces.view.facelets.tag.composite.CompositeResouceWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositeResouceWrapper
0%
0/26
0%
0/6
1.273
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.view.facelets.tag.composite;
 20  
 
 21  
 import java.io.Externalizable;
 22  
 import java.io.IOException;
 23  
 import java.io.InputStream;
 24  
 import java.io.ObjectInput;
 25  
 import java.io.ObjectOutput;
 26  
 import java.net.URL;
 27  
 import java.util.Map;
 28  
 
 29  
 import javax.faces.FacesWrapper;
 30  
 import javax.faces.application.Resource;
 31  
 import javax.faces.context.FacesContext;
 32  
 
 33  
 /**
 34  
  * The value inside composite component attribute map with the key
 35  
  * Resource.COMPONENT_RESOURCE_KEY should be a Serializable. This
 36  
  * wrapper add serialization to Resource instances, because 
 37  
  * ResourceImpl depends from the ResourceLoader used by it.
 38  
  * 
 39  
  * @author Leonardo Uribe (latest modification by $Author$)
 40  
  * @version $Revision$ $Date$
 41  
  */
 42  0
 public final class CompositeResouceWrapper extends Resource 
 43  
     implements FacesWrapper<Resource>, Externalizable
 44  
 {
 45  
     /**
 46  
      * 
 47  
      */
 48  
     private static final long serialVersionUID = 8067930634887545843L;
 49  
     
 50  
     private transient Resource _delegate;
 51  
     
 52  
     public CompositeResouceWrapper()
 53  
     {
 54  0
         super();
 55  0
     }
 56  
     
 57  
     public CompositeResouceWrapper(Resource delegate)
 58  
     {
 59  0
         super();
 60  0
         this._delegate = delegate;
 61  0
         setResourceName(delegate.getResourceName());
 62  0
         setLibraryName(delegate.getLibraryName());
 63  0
         setContentType(delegate.getContentType());
 64  0
     }
 65  
 
 66  
 
 67  
     public InputStream getInputStream() throws IOException
 68  
     {
 69  0
         return getWrapped().getInputStream();
 70  
     }
 71  
 
 72  
     public String getRequestPath()
 73  
     {
 74  0
         return getWrapped().getRequestPath();
 75  
     }
 76  
 
 77  
     public Map<String, String> getResponseHeaders()
 78  
     {
 79  0
         return getWrapped().getResponseHeaders();
 80  
     }
 81  
 
 82  
     public URL getURL()
 83  
     {
 84  0
         return getWrapped().getURL();
 85  
     }
 86  
 
 87  
     public boolean userAgentNeedsUpdate(FacesContext context)
 88  
     {
 89  0
         return getWrapped().userAgentNeedsUpdate(context);
 90  
     }
 91  
 
 92  
     public Resource getWrapped()
 93  
     {
 94  0
         if (_delegate == null)
 95  
         {
 96  0
             _delegate = FacesContext.getCurrentInstance().getApplication().
 97  
                             getResourceHandler().createResource(
 98  
                                     getResourceName(), 
 99  
                                     getLibraryName(),
 100  
                                     getContentType());
 101  
         }
 102  0
         return _delegate;
 103  
     }
 104  
 
 105  
     public void readExternal(ObjectInput in) throws IOException,
 106  
             ClassNotFoundException
 107  
     {
 108  0
         setResourceName((String) in.readObject());
 109  0
         setLibraryName((String) in.readObject());
 110  0
         setContentType((String) in.readObject());
 111  0
     }
 112  
 
 113  
     public void writeExternal(ObjectOutput out) throws IOException
 114  
     {
 115  0
         out.writeObject(getResourceName());
 116  0
         out.writeObject(getLibraryName());
 117  0
         out.writeObject(getContentType());
 118  0
     }
 119  
     
 120  
     @Override
 121  
     public String toString()
 122  
     {
 123  
         // Delegate resource in this case could not be available in serialization, or
 124  
         // serialization could happen in other context. So it is better to return
 125  
         // a simple String representing the object without go into delegation.
 126  0
         return ( (getLibraryName() != null) ? getLibraryName() : "") + ":"+ 
 127  
                ( (getResourceName() != null) ? getResourceName() : "") ;
 128  
     }
 129  
 }