001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.aegis.databinding;
019:
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Map;
023: import java.util.logging.Logger;
024:
025: import javax.xml.namespace.QName;
026: import javax.xml.stream.XMLStreamReader;
027: import javax.xml.validation.Schema;
028:
029: import org.apache.cxf.aegis.Context;
030: import org.apache.cxf.aegis.DatabindingException;
031: import org.apache.cxf.aegis.type.Type;
032: import org.apache.cxf.aegis.type.TypeUtil;
033: import org.apache.cxf.aegis.xml.stax.ElementReader;
034: import org.apache.cxf.common.i18n.Message;
035: import org.apache.cxf.databinding.DataReader;
036: import org.apache.cxf.helpers.CastUtils;
037: import org.apache.cxf.interceptor.Fault;
038: import org.apache.cxf.message.Attachment;
039: import org.apache.cxf.service.model.MessagePartInfo;
040:
041: public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
042:
043: private static final Logger LOG = Logger
044: .getLogger(XMLStreamDataReader.class.getName());
045:
046: private AegisDatabinding databinding;
047:
048: private Context context = new Context();
049:
050: private Map<String, Object> properties;
051:
052: public XMLStreamDataReader(AegisDatabinding databinding) {
053: this .databinding = databinding;
054: }
055:
056: public Object read(MessagePartInfo part, XMLStreamReader input) {
057: Type type = databinding.getType(part);
058:
059: type = TypeUtil.getReadType(input, context, type);
060:
061: if (type == null) {
062: throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG));
063: }
064:
065: // I don't think this is the right type mapping
066: context.setTypeMapping(type.getTypeMapping());
067: context.setOverrideTypes(CastUtils.cast(databinding
068: .getOverrideTypes(), String.class));
069: context.setFault((Fault) getProperty(DataReader.FAULT));
070: Object val = databinding.getService().get(
071: AegisDatabinding.READ_XSI_TYPE_KEY);
072: if ("false".equals(val) || Boolean.FALSE.equals(val)) {
073: context.setReadXsiTypes(false);
074: }
075:
076: ElementReader elReader = new ElementReader(input);
077: if (elReader.isXsiNil()) {
078: elReader.readToEnd();
079: return null;
080: }
081:
082: try {
083: return type.readObject(elReader, context);
084: } catch (DatabindingException e) {
085: throw new RuntimeException(e);
086: }
087: }
088:
089: public Object getProperty(String key) {
090: if (properties == null) {
091: return null;
092: }
093: return properties.get(key);
094: }
095:
096: public Object read(QName name, XMLStreamReader input, Class type) {
097: // TODO Auto-generated method stub
098: return null;
099: }
100:
101: public Object read(XMLStreamReader input) {
102: // TODO Auto-generated method stub
103: return null;
104: }
105:
106: public void setAttachments(Collection<Attachment> attachments) {
107: context.setAttachments(attachments);
108: }
109:
110: public void setProperty(String prop, Object value) {
111: if (properties == null) {
112: properties = new HashMap<String, Object>();
113: }
114:
115: properties.put(prop, value);
116: }
117:
118: public void setSchema(Schema s) {
119: // TODO Auto-generated method stub
120:
121: }
122:
123: }
|