KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jaxb > skeleton > CollectionComponentAccessor


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

29
30 package com.caucho.jaxb.skeleton;
31
32 import com.caucho.jaxb.JAXBContextImpl;
33 import com.caucho.util.L10N;
34
35 import javax.xml.bind.JAXBException;
36 import javax.xml.bind.annotation.XmlAttribute;
37 import javax.xml.bind.annotation.XmlElement;
38 import javax.xml.bind.annotation.XmlType;
39 import javax.xml.namespace.QName JavaDoc;
40 import java.beans.PropertyDescriptor JavaDoc;
41 import java.lang.annotation.Annotation JavaDoc;
42 import java.lang.reflect.Field JavaDoc;
43 import java.lang.reflect.GenericArrayType JavaDoc;
44 import java.lang.reflect.Method JavaDoc;
45 import java.lang.reflect.ParameterizedType JavaDoc;
46 import java.lang.reflect.Type JavaDoc;
47 import java.util.Map JavaDoc;
48
49 public class CollectionComponentAccessor extends Accessor {
50   private Accessor _accessor;
51   private Class JavaDoc _type;
52   private Type _genericType;
53
54   public CollectionComponentAccessor(Accessor a)
55   {
56     super(a.getContext());
57
58     _accessor = a;
59
60     Type collectionGenericType = a.getGenericType();
61
62     if (collectionGenericType instanceof ParameterizedType JavaDoc) {
63       ParameterizedType JavaDoc pType = (ParameterizedType JavaDoc) collectionGenericType;
64
65       Type[] parameters = pType.getActualTypeArguments();
66
67       if (parameters.length < 1)
68         throw new UnsupportedOperationException JavaDoc(L.l("Unsupported type {0}", pType));
69
70       _genericType = parameters[0];
71
72       try {
73         if (_genericType instanceof ParameterizedType JavaDoc)
74           _type = (Class JavaDoc) ((ParameterizedType JavaDoc) _genericType).getRawType();
75         else
76           _type = (Class JavaDoc) _genericType;
77       }
78       catch (ClassCastException JavaDoc e) {
79         throw new UnsupportedOperationException JavaDoc(L.l("Unsupported type {0}", pType));
80       }
81     }
82   }
83
84   public Object JavaDoc get(Object JavaDoc o) throws JAXBException
85   {
86     throw new JAXBException("can't invoke CollectionComponentAccessor.get()");
87   }
88
89   public void set(Object JavaDoc o, Object JavaDoc value) throws JAXBException
90   {
91     throw new JAXBException("can't invoke CollectionComponentAccessor.set()");
92   }
93
94   public String JavaDoc getName()
95   {
96     return _accessor.getName();
97   }
98
99   public Class JavaDoc getType()
100   {
101     return _type;
102   }
103
104   public Type getGenericType()
105   {
106     return _genericType;
107   }
108
109   public <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> c)
110   {
111     return null;
112   }
113 }
114
Popular Tags