org.apache.cxf.sdo.SDODataBinding Maven / Gradle / Ivy
/**
* 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.sdo;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.w3c.dom.Node;
import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
import org.apache.cxf.databinding.AbstractDataBinding;
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.databinding.WrapperCapableDatabinding;
import org.apache.cxf.databinding.WrapperHelper;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.tuscany.sdo.api.SDOUtil;
import org.apache.ws.commons.schema.XmlSchema;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.helper.HelperContext;
import commonj.sdo.impl.HelperProvider;
/**
*
*/
public class SDODataBinding extends AbstractDataBinding
implements WrapperCapableDatabinding {
private final class SDOWrapperHelper implements WrapperHelper {
private final List partNames;
private Method fact;
private Object factory;
private QName wrapperName;
private SDOWrapperHelper(List partNames, Class> wrapperType, QName wrapperName) {
this.partNames = partNames;
if (DataObject.class != wrapperType) {
try {
String s = wrapperType.getPackage().getName() + ".SdoFactory";
Class> cls = Class.forName(s, false, wrapperType.getClassLoader());
for (Method m : cls.getMethods()) {
if (m.getReturnType() == wrapperType) {
fact = m;
break;
}
}
factory = cls.getField("INSTANCE").get(null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
this.wrapperName = wrapperName;
}
public Object createWrapperObject(List> lst) throws Fault {
DataObject o;
if (fact != null) {
try {
o = (DataObject)fact.invoke(factory);
} catch (Exception e) {
throw new Fault(e);
}
} else {
o = context.getDataFactory().create(wrapperName.getNamespaceURI(),
wrapperName.getLocalPart());
}
for (int x = 0; x < lst.size(); x++) {
o.set(partNames.get(x), lst.get(x));
}
return o;
}
public String getSignature() {
return "" + System.identityHashCode(this);
}
public List