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.util.List;
21: import javax.xml.namespace.QName;
22: import javax.xml.stream.XMLStreamReader;
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.apache.cxf.aegis.Context;
26: import org.apache.cxf.aegis.util.NamespaceHelper;
27: import org.apache.cxf.aegis.util.XmlConstants;
28:
29: /**
30: * Static methods/constants for Aegis.
31: *
32: * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
33: */
34: public final class TypeUtil {
35: public static final Log LOG = LogFactory.getLog(TypeUtil.class);
36:
37: private TypeUtil() {
38: //utility class
39: }
40:
41: public static Type getReadType(XMLStreamReader xsr,
42: Context context, Type type) {
43: if (!context.isReadXsiTypes()) {
44: return type;
45: }
46:
47: String overrideType = xsr.getAttributeValue(
48: XmlConstants.XSI_NS, "type");
49: if (overrideType != null) {
50: QName overrideTypeName = NamespaceHelper.createQName(xsr
51: .getNamespaceContext(), overrideType);
52: if (!overrideTypeName.equals(type.getSchemaType())) {
53: Type type2 = type.getTypeMapping().getType(
54: overrideTypeName);
55: if (type2 == null) {
56: LOG
57: .info("xsi:type=\""
58: + overrideTypeName
59: + "\" was specified, but no corresponding Type was registered; defaulting to "
60: + type.getSchemaType());
61: } else {
62: type = type2;
63: }
64: }
65: }
66: return type;
67: }
68:
69: public static Type getWriteType(Context context, Object value,
70: Type type) {
71: if (value != null && type != null
72: && type.getTypeClass() != value.getClass()) {
73: List<String> l = context.getOverrideTypes();
74: if (l != null && l.contains(value.getClass().getName())) {
75: type = type.getTypeMapping().getType(value.getClass());
76: }
77: }
78: return type;
79: }
80:
81: }
|