You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2007/03/07 21:20:15 UTC
svn commit: r515734 [5/11] - in /incubator/cxf/trunk/rt: ./
core/src/main/java/org/apache/cxf/endpoint/ databinding/aegis/
databinding/aegis/src/ databinding/aegis/src/main/
databinding/aegis/src/main/java/ databinding/aegis/src/main/java/org/
databind...
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,138 @@
+/**
+ * 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.java5;
+
+import java.beans.PropertyDescriptor;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.TypeMapping;
+import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
+import org.apache.cxf.aegis.util.NamespaceHelper;
+
+public class AnnotatedTypeInfo extends BeanTypeInfo {
+ public AnnotatedTypeInfo(TypeMapping tm, Class typeClass, String ns) {
+ super(typeClass, ns);
+ setTypeMapping(tm);
+ initialize();
+ }
+
+ /**
+ * Override from parent in order to check for IgnoreProperty annotation.
+ */
+ protected void mapProperty(PropertyDescriptor pd) {
+ if (isIgnored(pd))
+ return; // do not map ignored properties
+
+ String name = pd.getName();
+ if (isAttribute(pd)) {
+ mapAttribute(name, createMappedName(pd));
+ } else if (isElement(pd)) {
+ mapElement(name, createMappedName(pd));
+ }
+ }
+
+ @Override
+ protected boolean registerType(PropertyDescriptor desc) {
+ XmlAttribute att = desc.getReadMethod().getAnnotation(XmlAttribute.class);
+ if (att != null && att.type() != Type.class)
+ return false;
+
+ XmlElement el = desc.getReadMethod().getAnnotation(XmlElement.class);
+ if (el != null && el.type() != Type.class)
+ return false;
+
+ return super.registerType(desc);
+ }
+
+ protected boolean isIgnored(PropertyDescriptor desc) {
+ return desc.getReadMethod().isAnnotationPresent(IgnoreProperty.class);
+ }
+
+ protected boolean isAttribute(PropertyDescriptor desc) {
+ return desc.getReadMethod().isAnnotationPresent(XmlAttribute.class);
+ }
+
+ protected boolean isElement(PropertyDescriptor desc) {
+ return !isAttribute(desc);
+ }
+
+ protected boolean isAnnotatedElement(PropertyDescriptor desc) {
+ return desc.getReadMethod().isAnnotationPresent(XmlElement.class);
+ }
+
+ @Override
+ protected QName createMappedName(PropertyDescriptor desc) {
+ return createQName(desc);
+ }
+
+ protected QName createQName(PropertyDescriptor desc) {
+ String name = null;
+ String ns = null;
+
+ XmlType xtype = (XmlType)getTypeClass().getAnnotation(XmlType.class);
+ if (xtype != null) {
+ ns = xtype.namespace();
+ }
+
+ if (isAttribute(desc)) {
+ XmlAttribute att = desc.getReadMethod().getAnnotation(XmlAttribute.class);
+ name = att.name();
+ if (att.namespace().length() > 0)
+ ns = att.namespace();
+ } else if (isAnnotatedElement(desc)) {
+ XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
+ name = att.name();
+ if (att.namespace().length() > 0)
+ ns = att.namespace();
+ }
+
+ if (name == null || name.length() == 0)
+ name = desc.getName();
+
+ if (ns == null || ns.length() == 0)
+ ns = NamespaceHelper.makeNamespaceFromClassName(getTypeClass().getName(), "http");
+
+ return new QName(ns, name);
+ }
+
+ public boolean isNillable(QName name) {
+ PropertyDescriptor desc = getPropertyDescriptorFromMappedName(name);
+
+ if (isAnnotatedElement(desc)) {
+ XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
+ return att.nillable();
+ } else {
+ return super.isNillable(name);
+ }
+ }
+
+ public int getMinOccurs(QName name) {
+ PropertyDescriptor desc = getPropertyDescriptorFromMappedName(name);
+ if (isAnnotatedElement(desc)) {
+ XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
+ String minOccurs = att.minOccurs();
+ if (minOccurs != null && minOccurs.length() > 0) {
+ return Integer.parseInt(minOccurs);
+ }
+ }
+ return super.getMinOccurs(name);
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,56 @@
+/**
+ * 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.java5;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+
+/**
+ * @author Dan Diephouse
+ */
+public class DurationType extends Type {
+ private DatatypeFactory dtFactory;
+
+ public DurationType() {
+ try {
+ dtFactory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new DatabindingException("Couldn't load DatatypeFactory.", e);
+ }
+
+ setTypeClass(Duration.class);
+ }
+
+ @Override
+ public Object readObject(MessageReader reader, Context context) {
+ return dtFactory.newDuration(reader.getValue());
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) {
+ writer.writeValue(((Duration)object).toString());
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/DurationType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,80 @@
+/**
+ * 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.java5;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.XmlConstants;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.binding.soap.SoapConstants;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+public class EnumType extends Type {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object readObject(MessageReader reader, Context context) {
+ String value = reader.getValue();
+
+ return Enum.valueOf(getTypeClass(), value);
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) {
+ writer.writeValue(((Enum)object).toString());
+ }
+
+ @Override
+ public void setTypeClass(Class typeClass) {
+ if (!typeClass.isEnum()) {
+ throw new DatabindingException("Type class must be an enum.");
+ }
+
+ super.setTypeClass(typeClass);
+ }
+
+ @Override
+ public void writeSchema(Element root) {
+ Namespace xsd = Namespace.getNamespace(XmlConstants.XSD_PREFIX, XmlConstants.XSD);
+
+ Element simple = new Element("simpleType", xsd);
+ simple.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+ root.addContent(simple);
+
+ Element restriction = new Element("restriction", xsd);
+ restriction.setAttribute(new Attribute("base", XmlConstants.XSD_PREFIX + ":string"));
+ simple.addContent(restriction);
+
+ Object[] constants = getTypeClass().getEnumConstants();
+
+ for (Object constant : constants) {
+ Element enumeration = new Element("enumeration", xsd);
+ enumeration.setAttribute(new Attribute("value", ((Enum)constant).toString()));
+ restriction.addContent(enumeration);
+ }
+ }
+
+ @Override
+ public boolean isComplex() {
+ return true;
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,38 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * IgnoreProperty Annotation allows us to Ignore JavaBean Properties
+ * when using AEGIS POJO Binding with Java 5 Annotations
+ *
+ * @author <a href="mailto:adam@multicom.co.uk">Adam J Chesney</a>
+ *
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface IgnoreProperty
+{
+
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/IgnoreProperty.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,250 @@
+package org.apache.cxf.aegis.type.java5;
+
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.WildcardType;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.aegis.type.AbstractTypeCreator;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.basic.BeanType;
+import org.apache.cxf.aegis.util.NamespaceHelper;
+import org.apache.cxf.aegis.util.ServiceUtils;
+
+public class Java5TypeCreator extends AbstractTypeCreator {
+
+ @Override
+ public TypeClassInfo createClassInfo(Method m, int index) {
+ if (index >= 0) {
+ TypeClassInfo info;
+ java.lang.reflect.Type genericType = m.getGenericParameterTypes()[index];
+ if (genericType instanceof Class) {
+ info = nextCreator.createClassInfo(m, index);
+ } else {
+ info = new TypeClassInfo();
+ info.setGenericType(genericType);
+ }
+ info.setTypeClass(m.getParameterTypes()[index]);
+
+ XmlParamType xmlParam = getXmlParamAnnotation(m, index);
+ if (xmlParam != null) {
+ if (xmlParam.type() != Type.class)
+ info.setType(xmlParam.type());
+
+ info.setTypeName(createQName(m.getParameterTypes()[index], xmlParam.name(), xmlParam
+ .namespace()));
+ }
+
+ return info;
+ } else {
+ java.lang.reflect.Type genericReturnType = m.getGenericReturnType();
+ TypeClassInfo info;
+ if (genericReturnType instanceof Class) {
+ info = nextCreator.createClassInfo(m, index);
+ } else {
+ info = new TypeClassInfo();
+ info.setGenericType(genericReturnType);
+ }
+ info.setTypeClass(m.getReturnType());
+ if (m.getParameterAnnotations() != null && m.getAnnotations().length > 0)
+ info.setAnnotations(m.getAnnotations());
+
+ XmlReturnType xmlParam = m.getAnnotation(XmlReturnType.class);
+ if (xmlParam != null) {
+ if (xmlParam.type() != Type.class)
+ info.setType(xmlParam.type());
+
+ info.setTypeName(createQName(m.getReturnType(), xmlParam.name(), xmlParam.namespace()));
+ }
+
+ return info;
+ }
+ }
+
+ public XmlParamType getXmlParamAnnotation(Method m, int index) {
+ if (m.getParameterAnnotations() == null || m.getParameterAnnotations().length <= index
+ || m.getParameterAnnotations()[index] == null)
+ return null;
+
+ Annotation[] annotations = m.getParameterAnnotations()[index];
+
+ for (int i = 0; i < annotations.length; i++) {
+ Annotation annotation = annotations[i];
+ if (annotation.annotationType().equals(XmlParamType.class)) {
+ return (XmlParamType)annotations[i];
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public TypeClassInfo createClassInfo(PropertyDescriptor pd) {
+ TypeClassInfo info = createBasicClassInfo(pd.getPropertyType());
+ info.setGenericType(pd.getReadMethod().getGenericReturnType());
+ info.setAnnotations(pd.getReadMethod().getAnnotations());
+
+ XmlElement el = pd.getReadMethod().getAnnotation(XmlElement.class);
+ if (el != null && !el.type().equals(Type.class)) {
+ info.setType(el.type());
+ }
+
+ XmlAttribute att = pd.getReadMethod().getAnnotation(XmlAttribute.class);
+ if (att != null && !att.type().equals(Type.class)) {
+ info.setType(att.type());
+ }
+
+ return info;
+ }
+
+ @Override
+ public Type createCollectionType(TypeClassInfo info) {
+ Object genericType = info.getGenericType();
+ Class paramClass = getComponentType(genericType, 0);
+
+ if (paramClass != null) {
+ return createCollectionTypeFromGeneric(info);
+ } else {
+ return nextCreator.createCollectionType(info);
+ }
+ }
+
+ protected Type getOrCreateGenericType(TypeClassInfo info) {
+ return getOrCreateParameterizedType(info.getGenericType(), 0);
+ }
+
+ protected Type getOrCreateMapKeyType(TypeClassInfo info) {
+ return getOrCreateParameterizedType(info.getGenericType(), 0);
+ }
+
+ protected Type getOrCreateMapValueType(TypeClassInfo info) {
+ return getOrCreateParameterizedType(info.getGenericType(), 1);
+ }
+
+ protected Type getOrCreateParameterizedType(Object generic, int index) {
+ Class clazz = getComponentType(generic, index);
+
+ TypeClassInfo info = createBasicClassInfo(clazz);
+ info.setDescription(clazz.toString());
+ info.setGenericType(getGenericComponent(generic, index));
+
+ Type type = createTypeForClass(info);
+
+ return type;
+ }
+
+ private Object getGenericComponent(Object genericType, int index) {
+ if (genericType instanceof ParameterizedType) {
+ ParameterizedType type = (ParameterizedType)genericType;
+
+ if (type.getActualTypeArguments()[index] instanceof WildcardType) {
+ WildcardType wildcardType = (WildcardType)type.getActualTypeArguments()[index];
+
+ return wildcardType;
+ } else if (type.getActualTypeArguments()[index] instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType)type.getActualTypeArguments()[index];
+
+ return ptype;
+ }
+ }
+
+ return null;
+ }
+
+ protected Class getComponentType(Object genericType, int index) {
+ Class paramClass = null;
+
+ if (genericType instanceof ParameterizedType) {
+ ParameterizedType type = (ParameterizedType)genericType;
+
+ if (type.getActualTypeArguments()[index] instanceof Class) {
+ paramClass = (Class)type.getActualTypeArguments()[index];
+ }
+
+ else if (type.getActualTypeArguments()[index] instanceof WildcardType) {
+ WildcardType wildcardType = (WildcardType)type.getActualTypeArguments()[index];
+
+ if (wildcardType.getUpperBounds()[index] instanceof Class) {
+ paramClass = (Class)wildcardType.getUpperBounds()[index];
+ }
+ } else if (type.getActualTypeArguments()[index] instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType)type.getActualTypeArguments()[index];
+ paramClass = (Class)ptype.getRawType();
+ }
+ }
+ return paramClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Type createDefaultType(TypeClassInfo info) {
+ QName typeName = info.getTypeName();
+ if (typeName == null)
+ typeName = createQName(info.getTypeClass());
+
+ AnnotatedTypeInfo typeInfo = new AnnotatedTypeInfo(getTypeMapping(), info.getTypeClass(), typeName
+ .getNamespaceURI());
+ XmlType xtype = (XmlType)info.getTypeClass().getAnnotation(XmlType.class);
+ if (xtype != null) {
+ typeInfo.setExtensibleElements(xtype.extensibleElements());
+ typeInfo.setExtensibleAttributes(xtype.extensibleAttributes());
+ } else {
+ typeInfo.setExtensibleElements(getConfiguration().isDefaultExtensibleElements());
+ typeInfo.setExtensibleAttributes(getConfiguration().isDefaultExtensibleAttributes());
+ }
+
+ typeInfo.setDefaultMinOccurs(getConfiguration().getDefaultMinOccurs());
+ typeInfo.setDefaultNillable(getConfiguration().isDefaultNillable());
+
+ BeanType type = new BeanType(typeInfo);
+ type.setTypeMapping(getTypeMapping());
+ type.setSchemaType(typeName);
+
+ return type;
+ }
+
+ @Override
+ public Type createEnumType(TypeClassInfo info) {
+ EnumType type = new EnumType();
+
+ type.setSchemaType(createQName(info.getTypeClass()));
+ type.setTypeClass(info.getTypeClass());
+ type.setTypeMapping(getTypeMapping());
+
+ return type;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public QName createQName(Class typeClass) {
+ String name = null;
+ String ns = null;
+
+ XmlType xtype = (XmlType)typeClass.getAnnotation(XmlType.class);
+ if (xtype != null) {
+ name = xtype.name();
+ ns = xtype.namespace();
+ }
+
+ return createQName(typeClass, name, ns);
+ }
+
+ private QName createQName(Class typeClass, String name, String ns) {
+ String clsName = typeClass.getName();
+ if (name == null || name.length() == 0)
+ name = ServiceUtils.makeServiceNameFromClassName(typeClass);
+
+ if (ns == null || ns.length() == 0)
+ ns = NamespaceHelper.makeNamespaceFromClassName(clsName, "http");
+
+ return new QName(ns, name);
+ }
+
+ @Override
+ protected boolean isEnum(Class javaType) {
+ return javaType.isEnum();
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,56 @@
+/**
+ * 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.java5;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+
+/**
+ * @author Dan Diephouse
+ */
+public class XMLGregorianCalendarType extends Type {
+ private DatatypeFactory dtFactory;
+
+ public XMLGregorianCalendarType() {
+ try {
+ dtFactory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new DatabindingException("Couldn't load DatatypeFactory.", e);
+ }
+
+ setTypeClass(XMLGregorianCalendar.class);
+ }
+
+ @Override
+ public Object readObject(MessageReader reader, Context context) {
+ return dtFactory.newXMLGregorianCalendar(reader.getValue());
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) {
+ writer.writeValue(((XMLGregorianCalendar)object).toXMLFormat());
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XMLGregorianCalendarType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,36 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cxf.aegis.type.Type;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface XmlAttribute {
+ Class type() default Type.class;
+
+ String name() default "";
+
+ String namespace() default "";
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlAttribute.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,43 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cxf.aegis.type.Type;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface XmlElement {
+ Class type() default Type.class;
+
+ String name() default "";
+
+ String namespace() default "";
+
+ boolean nillable() default true;
+
+ /**
+ * Set to "0" to make the property optional, "1" for required
+ */
+ String minOccurs() default "";
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,42 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cxf.aegis.type.Type;
+
+/**
+ * Annotates services method parameters to provide information about how they
+ * are to be serialized.
+ *
+ * @author Dan Diephouse
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface XmlParamType {
+ Class type() default Type.class;
+
+ String name() default "";
+
+ String namespace() default "";
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlParamType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,42 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cxf.aegis.type.Type;
+
+/**
+ * Annotates a service's return type to provide information about how it is to
+ * be serialized.
+ *
+ * @author Dan Diephouse
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface XmlReturnType {
+ Class type() default Type.class;
+
+ String name() default "";
+
+ String namespace() default "";
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlReturnType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,40 @@
+/**
+ * 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.java5;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cxf.aegis.type.Type;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface XmlType {
+ Class type() default Type.class;
+
+ String name() default "";
+
+ String namespace() default "";
+
+ boolean extensibleElements() default true;
+
+ boolean extensibleAttributes() default true;
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,112 @@
+/**
+ * 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.mtom;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.message.Attachment;
+
+/**
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public abstract class AbstractXOPType extends Type {
+ public final static String XOP_NS = "http://www.w3.org/2004/08/xop/include";
+ public final static String XML_MIME_NS = "http://www.w3.org/2004/11/xmlmime";
+
+ public final static QName XOP_INCLUDE = new QName(XOP_NS, "Include");
+ public final static QName XOP_HREF = new QName("href");
+ public final static QName XML_MIME_TYPE = new QName(XML_MIME_NS, "mimeType");
+
+ public AbstractXOPType() {
+ }
+
+ @Override
+ public Object readObject(MessageReader reader, Context context) throws DatabindingException {
+ Object o = null;
+ while (reader.hasMoreElementReaders()) {
+ MessageReader child = reader.getNextElementReader();
+ if (child.getName().equals(XOP_INCLUDE)) {
+ MessageReader mimeReader = child.getAttributeReader(XOP_HREF);
+ String type = mimeReader.getValue();
+ o = readInclude(type, child, context);
+ }
+ child.readToEnd();
+ }
+
+ return o;
+ }
+
+ public Object readInclude(String type, MessageReader reader, Context context) throws DatabindingException {
+ String href = reader.getAttributeReader(XOP_HREF).getValue();
+
+ Attachment att = AttachmentUtil.getAttachment(href, context.getAttachments());
+
+ if (att == null) {
+ throw new DatabindingException("Could not find the attachment " + href);
+ }
+
+ try {
+ return readAttachment(att, context);
+ } catch (IOException e) {
+ throw new DatabindingException("Could not read attachment", e);
+ }
+ }
+
+ protected abstract Object readAttachment(Attachment att, Context context) throws IOException;
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ Collection<Attachment> attachments = context.getAttachments();
+ if (attachments == null) {
+ attachments = new ArrayList<Attachment>();
+ context.setAttachments(attachments);
+ }
+
+ String id = AttachmentUtil.createContentID(getSchemaType().getNamespaceURI());
+
+ Attachment att = createAttachment(object, id);
+
+ attachments.add(att);
+
+ String contentType = getContentType(object, context);
+ if (contentType != null) {
+ MessageWriter mt = writer.getAttributeWriter(XML_MIME_TYPE);
+ mt.writeValue(contentType);
+ }
+
+ MessageWriter include = writer.getElementWriter(XOP_INCLUDE);
+ MessageWriter href = include.getAttributeWriter(XOP_HREF);
+ href.writeValue("cid:" + id);
+
+ include.close();
+ }
+
+ protected abstract Attachment createAttachment(Object object, String id);
+
+ protected abstract String getContentType(Object object, Context context);
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,72 @@
+/**
+ * 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.mtom;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.activation.URLDataSource;
+
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.util.UID;
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.message.Attachment;
+
+public class AttachmentUtil {
+ public static String createContentID(String ns) {
+ String uid = UID.generate();
+ try {
+ URI uri = new URI(ns);
+ return uid + "@" + uri;
+ } catch (URISyntaxException e) {
+ throw new DatabindingException("Could not create URI for namespace: " + ns);
+ }
+ }
+
+ public static Attachment getAttachment(String id, Collection<Attachment> attachments) {
+ int i = id.indexOf("cid:");
+ if (i != -1) {
+ id = id.substring(4).trim();
+ }
+
+ if (attachments == null) {
+ return null;
+ }
+
+ for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) {
+ Attachment a = iter.next();
+ if (a.getId().equals(id)) {
+ return a;
+ }
+ }
+
+ // Try loading the URL remotely
+ try {
+ URLDataSource source = new URLDataSource(new URL(id));
+ return new AttachmentImpl(id, new DataHandler(source));
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AttachmentUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,97 @@
+/**
+ * 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.mtom;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.util.XmlConstants;
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.attachment.ByteDataSource;
+import org.apache.cxf.message.Attachment;
+
+/**
+ * @author Dan Diephouse
+ */
+public class ByteArrayType extends AbstractXOPType {
+ public ByteArrayType() {
+ setTypeClass(byte[].class);
+ setSchemaType(new QName(XmlConstants.XSD, "base64Binary"));
+ }
+
+ @Override
+ protected Object readAttachment(Attachment att, Context context) throws IOException {
+ DataHandler handler = att.getDataHandler();
+ InputStream is = handler.getInputStream();
+
+ // try
+ // {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copy(is, out);
+ is.close();
+ return out.toByteArray();
+ // }
+ // finally
+ // {
+ // DataSource dataSource = handler.getDataSource();
+ // if (dataSource instanceof AttachmentDataSource)
+ // {
+ // File attFile = ((AttachmentDataSource) dataSource).getFile();
+ // if (attFile != null) attFile.delete();
+ // }
+ // }
+ }
+
+ public static void copy(InputStream input, OutputStream output) throws IOException {
+ try {
+ final byte[] buffer = new byte[8096];
+
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ }
+ } finally {
+ output.close();
+ input.close();
+ }
+ }
+
+ @Override
+ protected Attachment createAttachment(Object object, String id) {
+ byte[] data = (byte[])object;
+
+ ByteDataSource source = new ByteDataSource(data);
+ source.setContentType(getContentType(object, null));
+ AttachmentImpl att = new AttachmentImpl(id, new DataHandler(source));
+ att.setXOP(true);
+
+ return att;
+ }
+
+ @Override
+ protected String getContentType(Object object, Context context) {
+ return "application/octet-stream";
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,47 @@
+/**
+ * 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.mtom;
+
+import javax.activation.DataHandler;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.message.Attachment;
+
+public class DataHandlerType extends AbstractXOPType {
+ @Override
+ protected Object readAttachment(Attachment att, Context context) {
+ return att.getDataHandler();
+ }
+
+ @Override
+ protected Attachment createAttachment(Object object, String id) {
+ DataHandler handler = (DataHandler)object;
+
+ AttachmentImpl att = new AttachmentImpl(id, handler);
+ att.setXOP(true);
+
+ return att;
+ }
+
+ @Override
+ protected String getContentType(Object object, Context context) {
+ return ((DataHandler)object).getContentType();
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,48 @@
+/**
+ * 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.mtom;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.message.Attachment;
+
+public class DataSourceType extends AbstractXOPType {
+ @Override
+ protected Object readAttachment(Attachment att, Context context) {
+ return att.getDataHandler().getDataSource();
+ }
+
+ @Override
+ protected Attachment createAttachment(Object object, String id) {
+ DataSource source = (DataSource)object;
+
+ DataHandler handler = new DataHandler(source);
+ AttachmentImpl att = new AttachmentImpl(id, handler);
+ att.setXOP(true);
+ return att;
+ }
+
+ @Override
+ protected String getContentType(Object object, Context context) {
+ return ((DataSource)object).getContentType();
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,83 @@
+/**
+ * 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.xml;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.STAXUtils;
+import org.apache.cxf.aegis.util.stax.FragmentStreamReader;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+
+/**
+ * Reads and writes <code>org.w3c.dom.Document</code> types.
+ *
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class DocumentType extends Type {
+ private DocumentBuilder builder;
+
+ public DocumentType() {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ throw new DatabindingException("Couldn't load document builder.", e);
+ }
+ setWriteOuter(false);
+ }
+
+ public DocumentType(DocumentBuilder builder) {
+ this.builder = builder;
+ setWriteOuter(false);
+ }
+
+ @Override
+ public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
+ try {
+ XMLStreamReader reader = ((ElementReader)mreader).getXMLStreamReader();
+ return STAXUtils.read(builder, new FragmentStreamReader(reader), true);
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not parse xml.", e);
+ }
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ Document doc = (Document)object;
+
+ try {
+ STAXUtils.writeElement(doc.getDocumentElement(), ((ElementWriter)writer).getXMLStreamWriter(),
+ false);
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not write xml.", e);
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,75 @@
+/**
+ * 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.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.jdom.StaxBuilder;
+import org.apache.cxf.aegis.util.jdom.StaxSerializer;
+import org.apache.cxf.aegis.util.stax.JDOMStreamReader;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+import org.jdom.Document;
+
+/**
+ * Reads and writes <code>org.w3c.dom.Document</code> types.
+ *
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class JDOMDocumentType extends Type {
+ // private static final StaxBuilder builder = new StaxBuilder();
+ private static final StaxSerializer serializer = new StaxSerializer();
+
+ public JDOMDocumentType() {
+ setWriteOuter(false);
+ }
+
+ @Override
+ public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
+ StaxBuilder builder = new StaxBuilder();
+ try {
+ XMLStreamReader reader = ((ElementReader)mreader).getXMLStreamReader();
+
+ if (reader instanceof JDOMStreamReader) {
+ return ((JDOMStreamReader)reader).getCurrentElement();
+ }
+
+ return builder.build(reader);
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not parse xml.", e);
+ }
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ Document doc = (Document)object;
+
+ try {
+ serializer.writeElement(doc.getRootElement(), ((ElementWriter)writer).getXMLStreamWriter());
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not write xml.", e);
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMDocumentType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,75 @@
+/**
+ * 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.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.jdom.StaxBuilder;
+import org.apache.cxf.aegis.util.jdom.StaxSerializer;
+import org.apache.cxf.aegis.util.stax.JDOMStreamReader;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+import org.jdom.Element;
+
+/**
+ * Reads and writes <code>org.w3c.dom.Document</code> types.
+ *
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class JDOMElementType extends Type {
+ // private static final StaxBuilder builder = new StaxBuilder();
+ private static final StaxSerializer serializer = new StaxSerializer();
+
+ public JDOMElementType() {
+ setWriteOuter(false);
+ }
+
+ @Override
+ public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
+ StaxBuilder builder = new StaxBuilder();
+ try {
+ XMLStreamReader reader = ((ElementReader)mreader).getXMLStreamReader();
+
+ if (reader instanceof JDOMStreamReader) {
+ return ((JDOMStreamReader)reader).getCurrentElement();
+ }
+
+ return builder.build(reader).getRootElement();
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not parse xml.", e);
+ }
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ Element el = (Element)object;
+
+ try {
+ serializer.writeElement(el, ((ElementWriter)writer).getXMLStreamWriter());
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not write xml.", e);
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/JDOMElementType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,151 @@
+/**
+ * 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.xml;
+
+import javanet.staxutils.ContentHandlerToXMLStreamWriter;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.STAXUtils;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+
+/**
+ * Reads and writes <code>javax.xml.transform.Source</code> types.
+ * <p>
+ * The XML stream is converted DOMSource and sent off.
+ *
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * @see javanet.staxutils.StAXSource
+ * @see javax.xml.stream.XMLInputFactory
+ * @see org.apache.cxf.aegis.util.STAXUtils
+ */
+public class SourceType extends Type {
+ public SourceType() {
+ setTypeClass(Source.class);
+ setWriteOuter(false);
+ }
+
+ @Override
+ public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
+ DocumentType dt = (DocumentType)getTypeMapping().getType(Document.class);
+
+ return new DOMSource((Document)dt.readObject(mreader, context));
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ try {
+ if (object == null) {
+ return;
+ }
+
+ write((Source)object, ((ElementWriter)writer).getXMLStreamWriter());
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not write xml.", e);
+ }
+ }
+
+ protected void write(Source object, XMLStreamWriter writer) throws FactoryConfigurationError,
+ XMLStreamException, DatabindingException {
+ if (object == null) {
+ return;
+ }
+
+ if (object instanceof DOMSource) {
+ DOMSource ds = (DOMSource)object;
+
+ Element element = null;
+ if (ds.getNode() instanceof Element) {
+ element = (Element)ds.getNode();
+ } else if (ds.getNode() instanceof Document) {
+ element = ((Document)ds.getNode()).getDocumentElement();
+ } else {
+ throw new DatabindingException("Node type " + ds.getNode().getClass()
+ + " was not understood.");
+ }
+
+ STAXUtils.writeElement(element, writer, false);
+ } else if (object instanceof SAXSource) {
+ SAXSource source = (SAXSource)object;
+
+ try {
+ XMLReader xmlReader = source.getXMLReader();
+ if (xmlReader == null) {
+ xmlReader = createXMLReader();
+ }
+
+ xmlReader.setContentHandler(new FilteringContentHandlerToXMLStreamWriter(writer));
+
+ xmlReader.parse(source.getInputSource());
+ } catch (Exception e) {
+ throw new DatabindingException("Could not send xml.", e);
+ }
+ } else if (object instanceof StreamSource) {
+ StreamSource ss = (StreamSource)object;
+ XMLStreamReader reader = STAXUtils.createXMLStreamReader(ss.getInputStream(), null, null);
+ STAXUtils.copy(reader, writer);
+ }
+ }
+
+ protected XMLReader createXMLReader() throws SAXException {
+ // In JDK 1.4, the xml reader factory does not look for META-INF
+ // services
+ // If the org.xml.sax.driver system property is not defined, and
+ // exception will be thrown.
+ // In these cases, default to xerces parser
+ try {
+ return XMLReaderFactory.createXMLReader();
+ } catch (Exception e) {
+ return XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+ }
+ }
+
+ class FilteringContentHandlerToXMLStreamWriter extends ContentHandlerToXMLStreamWriter {
+ public FilteringContentHandlerToXMLStreamWriter(XMLStreamWriter xmlStreamWriter) {
+ super(xmlStreamWriter);
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/SourceType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java Wed Mar 7 12:20:07 2007
@@ -0,0 +1,59 @@
+/**
+ * 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.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.util.STAXUtils;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+
+/**
+ * Reads and writes <code>org.w3c.dom.Document</code> types.
+ *
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class XMLStreamReaderType extends Type {
+ public XMLStreamReaderType() {
+ setWriteOuter(false);
+ }
+
+ @Override
+ public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
+ return ((ElementReader)mreader).getXMLStreamReader();
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
+ XMLStreamReader reader = (XMLStreamReader)object;
+
+ try {
+ STAXUtils.copy(reader, ((ElementWriter)writer).getXMLStreamWriter());
+ reader.close();
+ } catch (XMLStreamException e) {
+ throw new DatabindingException("Could not write xml.", e);
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/XMLStreamReaderType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date