001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.axis.client;
018    
019    import java.io.Serializable;
020    import java.util.Iterator;
021    import java.util.List;
022    
023    import javax.xml.namespace.QName;
024    import javax.xml.rpc.encoding.DeserializerFactory;
025    import javax.xml.rpc.encoding.SerializerFactory;
026    import javax.xml.rpc.encoding.TypeMapping;
027    
028    import org.apache.axis.description.FieldDesc;
029    import org.apache.axis.description.TypeDesc;
030    import org.apache.axis.encoding.ser.BaseDeserializerFactory;
031    import org.apache.axis.encoding.ser.BaseSerializerFactory;
032    
033    /**
034     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
035     */
036    public class TypeInfo implements Serializable {
037        private final Class clazz;
038        private final QName qName;
039        private final Class serFactoryClass;
040        private final Class deserFactoryClass;
041        private final boolean canSearchParents;
042        private final FieldDesc[] fields;
043    
044        public static void register(List typeInfo, TypeMapping typeMapping) {
045            for (Iterator iter = typeInfo.iterator(); iter.hasNext();) {
046                TypeInfo info = (TypeInfo) iter.next();
047                info.register(typeMapping);
048            }
049        }
050    
051        public TypeInfo(Class clazz, QName qName, Class serializerClass, Class deserializerClass, boolean canSearchParents, FieldDesc[] fields) {
052            this.clazz = clazz;
053            this.qName = qName;
054            this.serFactoryClass = serializerClass;
055            this.deserFactoryClass = deserializerClass;
056            this.canSearchParents =canSearchParents;
057            this.fields = fields;
058        }
059    
060        public Class getClazz() {
061            return clazz;
062        }
063    
064        public QName getqName() {
065            return qName;
066        }
067    
068        public Class getSerFactoryClass() {
069            return serFactoryClass;
070        }
071    
072        public Class getDeserFactoryClass() {
073            return deserFactoryClass;
074        }
075    
076        public boolean isCanSearchParents() {
077            return canSearchParents;
078        }
079    
080        public FieldDesc[] getFields() {
081            return fields;
082        }
083    
084        public TypeDesc buildTypeDesc() {
085            TypeDesc typeDesc = new TypeDesc(clazz, canSearchParents);
086            typeDesc.setXmlType(qName);
087            typeDesc.setFields(fields);
088            return typeDesc;
089        }
090    
091        public void register(TypeMapping typeMapping) {
092            SerializerFactory ser = BaseSerializerFactory.createFactory(serFactoryClass, clazz, qName);
093            DeserializerFactory deser = BaseDeserializerFactory.createFactory(deserFactoryClass, clazz, qName);
094    
095            typeMapping.register(clazz, qName, ser, deser);
096        }
097    
098        public static class UpdatableTypeInfo {
099            protected Class clazz;
100            protected QName qName;
101            protected Class serializerClass;
102            protected Class deserializerClass;
103            protected boolean canSearchParents;
104            protected FieldDesc[] fields;
105    
106            public TypeInfo buildTypeInfo() {
107                if (null == clazz) {
108                    throw new IllegalStateException("clazz is null");
109                } else if (null == qName) {
110                    throw new IllegalStateException("qName is null");
111                } else if (null == serializerClass) {
112                    throw new IllegalStateException("serializerClass is null");
113                } else if (null == deserializerClass) {
114                    throw new IllegalStateException("deserializerClass is null");
115                } else if (null == fields) {
116                    throw new IllegalStateException("fields is null");
117                }
118                return new TypeInfo(clazz, qName, serializerClass, deserializerClass, canSearchParents, fields);
119            }
120    
121            public void setClazz(Class clazz) {
122                this.clazz = clazz;
123            }
124    
125            public void setDeserializerClass(Class deserializerClass) {
126                this.deserializerClass = deserializerClass;
127            }
128    
129            public void setFields(FieldDesc[] fields) {
130                this.fields = fields;
131            }
132    
133            public void setQName(QName name) {
134                qName = name;
135            }
136    
137            public void setSerializerClass(Class serializerClass) {
138                this.serializerClass = serializerClass;
139            }
140    
141            public void setCanSearchParents(boolean canSearchParents) {
142                this.canSearchParents = canSearchParents;
143            }
144        }
145    }