Apache CXF example source code file (SoapArrayType.java)
This example Apache CXF source code file (SoapArrayType.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.aegis.type.encoded;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.apache.cxf.aegis.Context;
import org.apache.cxf.aegis.DatabindingException;
import org.apache.cxf.aegis.type.AegisType;
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.cxf.aegis.type.TypeUtil;
import org.apache.cxf.aegis.type.basic.BeanType;
import org.apache.cxf.aegis.xml.MessageReader;
import org.apache.cxf.aegis.xml.MessageWriter;
import org.apache.cxf.binding.soap.Soap11;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.ws.commons.schema.XmlSchema;
import static org.apache.cxf.aegis.type.encoded.SoapEncodingUtil.readAttributeValue;
public class SoapArrayType extends AegisType {
private static final Logger LOG = LogUtils.getL7dLogger(SoapArrayType.class);
private static final String SOAP_ENCODING_NS_1_1 = Soap11.getInstance().getSoapEncodingStyle();
private static final QName SOAP_ARRAY_POSITION = new QName(SOAP_ENCODING_NS_1_1, "position");
private QName componentName;
@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
try {
// get the encoded array type info
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(reader, tm);
// verify arrayType dimensions are the same as this type class's array dimensions
if (getDimensions() != arrayTypeInfo.getTotalDimensions()) {
throw new DatabindingException("In " + getSchemaType() + " expected array with "
+ getDimensions() + " dimensions, but arrayType has "
+ arrayTypeInfo.getTotalDimensions() + " dimensions: "
+ arrayTypeInfo.toString());
}
// calculate max size
int maxSize = 1;
for (int dimension : arrayTypeInfo.getDimensions()) {
maxSize *= dimension;
}
// verify offset doesn't exceed maximum size
if (arrayTypeInfo.getOffset() >= maxSize) {
throw new DatabindingException("The array offset " + arrayTypeInfo.getOffset() + " in "
+ getSchemaType() + " exceeds the expecte size of " + maxSize);
}
// read the values
List<Object> values = readCollection(reader,
context,
arrayTypeInfo,
maxSize - arrayTypeInfo.getOffset());
// if it is a partially transmitted array offset the array values
if (arrayTypeInfo.getOffset() > 0) {
List<Object> list = new ArrayList