01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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: */package org.apache.cxf.aegis.type;
19:
20: import java.beans.PropertyDescriptor;
21: import java.lang.reflect.Method;
22:
23: import org.apache.cxf.aegis.DatabindingException;
24: import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
25: import org.apache.cxf.aegis.type.basic.BeanType;
26: import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
27:
28: public class DefaultTypeCreator extends AbstractTypeCreator {
29: public DefaultTypeCreator() {
30: }
31:
32: public DefaultTypeCreator(Configuration configuration) {
33: setConfiguration(configuration);
34: }
35:
36: @Override
37: public TypeClassInfo createClassInfo(Method m, int index) {
38: TypeClassInfo info = new TypeClassInfo();
39:
40: if (index >= 0) {
41: info.setTypeClass(m.getParameterTypes()[index]);
42: } else {
43: info.setTypeClass(m.getReturnType());
44: }
45:
46: return info;
47: }
48:
49: @Override
50: public TypeClassInfo createClassInfo(PropertyDescriptor pd) {
51: return createBasicClassInfo(pd.getPropertyType());
52: }
53:
54: @Override
55: public Type createCollectionType(TypeClassInfo info) {
56: if (info.getGenericType() == null) {
57: throw new DatabindingException("Cannot create mapping for "
58: + info.getTypeClass().getName()
59: + ", unspecified component type for "
60: + info.getDescription());
61: }
62:
63: return createCollectionTypeFromGeneric(info);
64: }
65:
66: @Override
67: public Type createDefaultType(TypeClassInfo info) {
68: BeanType type = new BeanType();
69: type.setSchemaType(createQName(info.getTypeClass()));
70: type.setTypeClass(info.getTypeClass());
71: type.setTypeMapping(getTypeMapping());
72:
73: BeanTypeInfo typeInfo = type.getTypeInfo();
74: typeInfo.setDefaultMinOccurs(getConfiguration()
75: .getDefaultMinOccurs());
76: typeInfo.setExtensibleAttributes(getConfiguration()
77: .isDefaultExtensibleAttributes());
78: typeInfo.setExtensibleElements(getConfiguration()
79: .isDefaultExtensibleElements());
80:
81: return type;
82: }
83:
84: protected Type getOrCreateMapKeyType(TypeClassInfo info) {
85: return createObjectType();
86: }
87:
88: protected Type getOrCreateMapValueType(TypeClassInfo info) {
89: return createObjectType();
90: }
91: }
|