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.view.facelets.tag.composite;
20  
21  import java.beans.IntrospectionException;
22  import java.beans.PropertyDescriptor;
23  import java.io.Externalizable;
24  import java.io.IOException;
25  import java.io.ObjectInput;
26  import java.io.ObjectOutput;
27  import java.util.Enumeration;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /**
32   * Serializable implementation of PropertyDescriptor
33   * 
34   * @author Leonardo Uribe (latest modification by $Author$)
35   * @version $Revision$ $Date$
36   */
37  public class CompositeComponentPropertyDescriptor extends PropertyDescriptor 
38      implements Externalizable
39  {
40      
41      /**
42       * Used for serialization only
43       * 
44       * @throws IntrospectionException
45       */
46      public CompositeComponentPropertyDescriptor() throws IntrospectionException
47      {
48          super("a",null,null);
49      }
50      
51      public CompositeComponentPropertyDescriptor(String propertyName)
52              throws IntrospectionException
53      {
54          super(propertyName, null, null);
55      }
56  
57      public void readExternal(ObjectInput in) throws IOException,
58              ClassNotFoundException
59      {
60          setName((String) in.readObject());
61          setDisplayName((String) in.readObject());
62          setExpert(in.readBoolean());
63          setPreferred(in.readBoolean());
64          setShortDescription((String)in.readObject());
65          
66          Map<String,Object> map = (Map) in.readObject();
67          
68          for (Map.Entry<String, Object> entry : map.entrySet())
69          {
70              setValue(entry.getKey(), entry.getValue());
71          }
72      }
73  
74      public void writeExternal(ObjectOutput out) throws IOException
75      {
76          out.writeObject(getName());
77          out.writeObject(getDisplayName());
78          out.writeBoolean(isExpert());
79          out.writeBoolean(isPreferred());
80          out.writeObject(getShortDescription());
81          
82          // Properties that comes here are targets, default, required,
83          // method-signature and type.
84          Map<String,Object> map = new HashMap<String, Object>(6,1);
85          
86          for (Enumeration<String> e = attributeNames(); e.hasMoreElements();)
87          {
88              String name = e.nextElement();
89              map.put(name, getValue(name));
90          }
91          out.writeObject(map);
92      }
93  }