View Javadoc

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.trinidad.component;
20  
21  import java.io.Externalizable;
22  
23  import java.io.IOException;
24  import java.io.InvalidClassException;
25  import java.io.ObjectInput;
26  import java.io.ObjectOutput;
27  
28  import javax.faces.application.FacesMessage;
29  
30  import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
31  
32  /**
33   * Wraps faces messages thrown by third party converters so that they appear as
34   * LabeledFacesMessages.
35   *
36   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/component/FacesMessageWrapper.java#0 $) $Date: 10-nov-2005.19:09:45 $
37   */
38  class FacesMessageWrapper extends LabeledFacesMessage implements Externalizable
39  {
40    public FacesMessageWrapper()
41    {
42      this(new FacesMessage(), null);
43    }
44    
45    public FacesMessageWrapper(FacesMessage wrapped, Object label)
46    {
47      _wrapped = wrapped;
48      setLabel(label);
49    }
50  
51    @Override
52    public String getDetail()
53    {
54      return _wrapped.getDetail();
55    }
56  
57    @Override
58    public FacesMessage.Severity getSeverity()
59    {
60      return _wrapped.getSeverity();
61    }
62  
63    @Override
64    public String getSummary()
65    {
66      return _wrapped.getSummary();
67    }
68  
69    @Override
70    public Object getLabel()
71    {
72      if(_wrapped instanceof LabeledFacesMessage)
73      {
74        return ((LabeledFacesMessage)_wrapped).getLabel();
75      }
76      
77      return _label;
78    }
79  
80    @Override
81    public void setDetail(String detail)
82    {
83      _wrapped.setDetail(detail);
84    }
85  
86    @Override
87    public void setSeverity(FacesMessage.Severity severity)
88    {
89      _wrapped.setSeverity(severity);
90    }
91  
92    @Override
93    public void setSummary(String summary)
94    {
95      _wrapped.setSummary(summary);
96    }
97  
98    @Override
99    public void setLabel(Object label)
100   {
101     if(_wrapped instanceof LabeledFacesMessage)
102     {
103       ((LabeledFacesMessage)_wrapped).setLabel(label);
104     }
105     else
106     {
107       _label = label;
108     }
109   }  
110 
111   /**
112    * Writes this object to the serialized stream.
113    * 
114    * @param objectOutput
115    * @throws IOException
116    */
117   public void writeExternal(ObjectOutput objectOutput)
118     throws IOException
119   {
120     objectOutput.writeLong(serialVersionUID);
121     objectOutput.writeObject(_wrapped);
122     objectOutput.writeObject(_label);
123   }
124 
125   /**
126    * Reads this object from the serialized stream.
127    * 
128    * @param objectInput
129    * @throws IOException
130    * @throws ClassNotFoundException
131    */
132   public void readExternal(ObjectInput objectInput)
133     throws IOException, ClassNotFoundException
134   {
135     Long version = objectInput.readLong();
136     
137     if(version != serialVersionUID)
138     {
139       throw new InvalidClassException("Classes are not compatible.  Received serialVersionUID = " + version + ", local serialVersionUID = "+ serialVersionUID);
140     }
141 
142     _wrapped = (FacesMessage)objectInput.readObject();
143     _label = objectInput.readObject();
144   }
145 
146   private FacesMessage _wrapped;
147   private Object _label;
148   private static final long serialVersionUID = 1L;
149 
150 }