You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by lr...@apache.org on 2011/02/23 06:45:13 UTC
svn commit: r1073606 - in /incubator/wink/trunk/wink-thrift-provider: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/wink/ src/main/java/org/apache/wink/providers/
src/main/java/org/apache/wink/pr...
Author: lresende
Date: Wed Feb 23 05:45:12 2011
New Revision: 1073606
URL: http://svn.apache.org/viewvc?rev=1073606&view=rev
Log:
WINK-337 - Applying patch from Raymond Feng to provide thrift provider
Added:
incubator/wink/trunk/wink-thrift-provider/
incubator/wink/trunk/wink-thrift-provider/pom.xml (with props)
incubator/wink/trunk/wink-thrift-provider/src/
incubator/wink/trunk/wink-thrift-provider/src/main/
incubator/wink/trunk/wink-thrift-provider/src/main/java/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/
incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/main/resources/
incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/
incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/wink-application
incubator/wink/trunk/wink-thrift-provider/src/test/
incubator/wink/trunk/wink-thrift-provider/src/test/java/
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/
incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java (with props)
incubator/wink/trunk/wink-thrift-provider/src/test/resources/
incubator/wink/trunk/wink-thrift-provider/src/test/resources/addressbook.thrift
Added: incubator/wink/trunk/wink-thrift-provider/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/pom.xml?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/pom.xml (added)
+++ incubator/wink/trunk/wink-thrift-provider/pom.xml Wed Feb 23 05:45:12 2011
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>wink-providers</artifactId>
+ <groupId>org.apache.wink</groupId>
+ <version>1.1.2-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-thrift-provider</artifactId>
+ <name>Apache Wink Providers :: Thrift Provider</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-common</artifactId>
+ </dependency>
+
+ <!-- [rfeng] The official thift jar is not in maven repo, see https://issues.apache.org/jira/browse/THRIFT-363 -->
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>libthrift</artifactId>
+ <version>0.5.0.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-component-test-support</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee_1.4_spec</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-server</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: incubator/wink/trunk/wink-thrift-provider/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/wink/trunk/wink-thrift-provider/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,120 @@
+/*
+ * 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.wink.providers.thrift;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TJSONProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.TIOStreamTransport;
+
+/**
+ * JAX-RS message provider for Apache Thrift
+ */
+@SuppressWarnings("rawtypes")
+@Provider
+@Consumes({"application/x-thrift", MediaType.APPLICATION_JSON})
+@Produces({"application/x-thrift", MediaType.APPLICATION_JSON})
+public class WinkThriftProvider implements MessageBodyReader<TBase>, MessageBodyWriter<TBase> {
+ public static final String THRIFT = "application/x-thrift";
+ public static final MediaType THRIFT_TYPE = new MediaType("application", "x-thrift");
+
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type != null && TBase.class.isAssignableFrom(type);
+ }
+
+ public TBase readFrom(Class<TBase> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders,
+ InputStream entityStream) throws IOException, WebApplicationException {
+ try {
+ return unmarshal(type, mediaType, entityStream);
+ } catch (Throwable e) {
+ throw new WebApplicationException(e);
+ }
+ }
+
+ static <T extends TBase> T unmarshal(Class<T> type, MediaType mediaType, InputStream entityStream) throws Exception {
+ TIOStreamTransport transport = new TIOStreamTransport(entityStream);
+ TProtocol protocol = null;
+ if (THRIFT_TYPE.isCompatible(mediaType)) {
+ protocol = new TBinaryProtocol.Factory().getProtocol(transport);
+ } else if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
+ protocol = new TJSONProtocol.Factory().getProtocol(transport);
+ }
+ T t = type.newInstance();
+ t.read(protocol);
+ return t;
+ }
+
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type != null && TBase.class.isAssignableFrom(type);
+ }
+
+ public long getSize(TBase t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return -1;
+ }
+
+ public void writeTo(TBase t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ marshal(t, mediaType, entityStream);
+ }
+
+ static <T extends TBase> void marshal(T t, MediaType mediaType, OutputStream entityStream) throws IOException {
+ TIOStreamTransport transport = new TIOStreamTransport(entityStream);
+ TProtocol protocol = null;
+ if (THRIFT_TYPE.isCompatible(mediaType)) {
+ protocol = new TBinaryProtocol.Factory().getProtocol(transport);
+ } else if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
+ protocol = new TJSONProtocol.Factory().getProtocol(transport);
+ }
+ if (t != null) {
+ try {
+ t.write(protocol);
+ } catch (TException e) {
+ throw new IOException(e);
+ }
+ }
+ }
+
+}
Propchange: incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/main/java/org/apache/wink/providers/thrift/WinkThriftProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/wink-application
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/wink-application?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/wink-application (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/main/resources/META-INF/wink-application Wed Feb 23 05:45:12 2011
@@ -0,0 +1,20 @@
+##
+## 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.
+##
+
+org.apache.wink.providers.thrift.WinkThriftProvider
Added: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,368 @@
+/*
+ * 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.
+ */
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package com.example.tutorial;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AddressBook implements org.apache.thrift.TBase<AddressBook, AddressBook._Fields>, java.io.Serializable, Cloneable {
+ private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("AddressBook");
+
+ private static final org.apache.thrift.protocol.TField PERSON_FIELD_DESC = new org.apache.thrift.protocol.TField("person", org.apache.thrift.protocol.TType.LIST, (short)1);
+
+ public List<Person> person;
+
+ /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+ public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+ PERSON((short)1, "person");
+
+ private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+ static {
+ for (_Fields field : EnumSet.allOf(_Fields.class)) {
+ byName.put(field.getFieldName(), field);
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, or null if its not found.
+ */
+ public static _Fields findByThriftId(int fieldId) {
+ switch(fieldId) {
+ case 1: // PERSON
+ return PERSON;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, throwing an exception
+ * if it is not found.
+ */
+ public static _Fields findByThriftIdOrThrow(int fieldId) {
+ _Fields fields = findByThriftId(fieldId);
+ if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+ return fields;
+ }
+
+ /**
+ * Find the _Fields constant that matches name, or null if its not found.
+ */
+ public static _Fields findByName(String name) {
+ return byName.get(name);
+ }
+
+ private final short _thriftId;
+ private final String _fieldName;
+
+ _Fields(short thriftId, String fieldName) {
+ _thriftId = thriftId;
+ _fieldName = fieldName;
+ }
+
+ public short getThriftFieldId() {
+ return _thriftId;
+ }
+
+ public String getFieldName() {
+ return _fieldName;
+ }
+ }
+
+ // isset id assignments
+
+ public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+ static {
+ Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+ tmpMap.put(_Fields.PERSON, new org.apache.thrift.meta_data.FieldMetaData("person", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
+ new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Person.class))));
+ metaDataMap = Collections.unmodifiableMap(tmpMap);
+ org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(AddressBook.class, metaDataMap);
+ }
+
+ public AddressBook() {
+ }
+
+ public AddressBook(
+ List<Person> person)
+ {
+ this();
+ this.person = person;
+ }
+
+ /**
+ * Performs a deep copy on <i>other</i>.
+ */
+ public AddressBook(AddressBook other) {
+ if (other.isSetPerson()) {
+ List<Person> __this__person = new ArrayList<Person>();
+ for (Person other_element : other.person) {
+ __this__person.add(new Person(other_element));
+ }
+ this.person = __this__person;
+ }
+ }
+
+ public AddressBook deepCopy() {
+ return new AddressBook(this);
+ }
+
+ // @Override
+ public void clear() {
+ this.person = null;
+ }
+
+ public int getPersonSize() {
+ return (this.person == null) ? 0 : this.person.size();
+ }
+
+ public java.util.Iterator<Person> getPersonIterator() {
+ return (this.person == null) ? null : this.person.iterator();
+ }
+
+ public void addToPerson(Person elem) {
+ if (this.person == null) {
+ this.person = new ArrayList<Person>();
+ }
+ this.person.add(elem);
+ }
+
+ public List<Person> getPerson() {
+ return this.person;
+ }
+
+ public AddressBook setPerson(List<Person> person) {
+ this.person = person;
+ return this;
+ }
+
+ public void unsetPerson() {
+ this.person = null;
+ }
+
+ /** Returns true if field person is set (has been assigned a value) and false otherwise */
+ public boolean isSetPerson() {
+ return this.person != null;
+ }
+
+ public void setPersonIsSet(boolean value) {
+ if (!value) {
+ this.person = null;
+ }
+ }
+
+ public void setFieldValue(_Fields field, Object value) {
+ switch (field) {
+ case PERSON:
+ if (value == null) {
+ unsetPerson();
+ } else {
+ setPerson((List<Person>)value);
+ }
+ break;
+
+ }
+ }
+
+ public Object getFieldValue(_Fields field) {
+ switch (field) {
+ case PERSON:
+ return getPerson();
+
+ }
+ throw new IllegalStateException();
+ }
+
+ /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+ public boolean isSet(_Fields field) {
+ if (field == null) {
+ throw new IllegalArgumentException();
+ }
+
+ switch (field) {
+ case PERSON:
+ return isSetPerson();
+ }
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (that == null)
+ return false;
+ if (that instanceof AddressBook)
+ return this.equals((AddressBook)that);
+ return false;
+ }
+
+ public boolean equals(AddressBook that) {
+ if (that == null)
+ return false;
+
+ boolean this_present_person = true && this.isSetPerson();
+ boolean that_present_person = true && that.isSetPerson();
+ if (this_present_person || that_present_person) {
+ if (!(this_present_person && that_present_person))
+ return false;
+ if (!this.person.equals(that.person))
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ public int compareTo(AddressBook other) {
+ if (!getClass().equals(other.getClass())) {
+ return getClass().getName().compareTo(other.getClass().getName());
+ }
+
+ int lastComparison = 0;
+ AddressBook typedOther = (AddressBook)other;
+
+ lastComparison = Boolean.valueOf(isSetPerson()).compareTo(typedOther.isSetPerson());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetPerson()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.person, typedOther.person);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ return 0;
+ }
+
+ public _Fields fieldForId(int fieldId) {
+ return _Fields.findByThriftId(fieldId);
+ }
+
+ public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+ org.apache.thrift.protocol.TField field;
+ iprot.readStructBegin();
+ while (true)
+ {
+ field = iprot.readFieldBegin();
+ if (field.type == org.apache.thrift.protocol.TType.STOP) {
+ break;
+ }
+ switch (field.id) {
+ case 1: // PERSON
+ if (field.type == org.apache.thrift.protocol.TType.LIST) {
+ {
+ org.apache.thrift.protocol.TList _list4 = iprot.readListBegin();
+ this.person = new ArrayList<Person>(_list4.size);
+ for (int _i5 = 0; _i5 < _list4.size; ++_i5)
+ {
+ Person _elem6;
+ _elem6 = new Person();
+ _elem6.read(iprot);
+ this.person.add(_elem6);
+ }
+ iprot.readListEnd();
+ }
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ default:
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ iprot.readFieldEnd();
+ }
+ iprot.readStructEnd();
+
+ // check for required fields of primitive type, which can't be checked in the validate method
+ validate();
+ }
+
+ public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+ validate();
+
+ oprot.writeStructBegin(STRUCT_DESC);
+ if (this.person != null) {
+ oprot.writeFieldBegin(PERSON_FIELD_DESC);
+ {
+ oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.person.size()));
+ for (Person _iter7 : this.person)
+ {
+ _iter7.write(oprot);
+ }
+ oprot.writeListEnd();
+ }
+ oprot.writeFieldEnd();
+ }
+ oprot.writeFieldStop();
+ oprot.writeStructEnd();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("AddressBook(");
+ boolean first = true;
+
+ sb.append("person:");
+ if (this.person == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.person);
+ }
+ first = false;
+ sb.append(")");
+ return sb.toString();
+ }
+
+ public void validate() throws org.apache.thrift.TException {
+ // check for required fields
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+ try {
+ write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+ try {
+ read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+}
+
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/AddressBook.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,636 @@
+/*
+ * 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.
+ */
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package com.example.tutorial;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Person implements org.apache.thrift.TBase<Person, Person._Fields>, java.io.Serializable, Cloneable {
+ private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Person");
+
+ private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1);
+ private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I32, (short)2);
+ private static final org.apache.thrift.protocol.TField EMAIL_FIELD_DESC = new org.apache.thrift.protocol.TField("email", org.apache.thrift.protocol.TType.STRING, (short)3);
+ private static final org.apache.thrift.protocol.TField PHONE_FIELD_DESC = new org.apache.thrift.protocol.TField("phone", org.apache.thrift.protocol.TType.LIST, (short)4);
+
+ public String name;
+ public int id;
+ public String email;
+ public List<PhoneNumber> phone;
+
+ /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+ public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+ NAME((short)1, "name"),
+ ID((short)2, "id"),
+ EMAIL((short)3, "email"),
+ PHONE((short)4, "phone");
+
+ private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+ static {
+ for (_Fields field : EnumSet.allOf(_Fields.class)) {
+ byName.put(field.getFieldName(), field);
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, or null if its not found.
+ */
+ public static _Fields findByThriftId(int fieldId) {
+ switch(fieldId) {
+ case 1: // NAME
+ return NAME;
+ case 2: // ID
+ return ID;
+ case 3: // EMAIL
+ return EMAIL;
+ case 4: // PHONE
+ return PHONE;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, throwing an exception
+ * if it is not found.
+ */
+ public static _Fields findByThriftIdOrThrow(int fieldId) {
+ _Fields fields = findByThriftId(fieldId);
+ if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+ return fields;
+ }
+
+ /**
+ * Find the _Fields constant that matches name, or null if its not found.
+ */
+ public static _Fields findByName(String name) {
+ return byName.get(name);
+ }
+
+ private final short _thriftId;
+ private final String _fieldName;
+
+ _Fields(short thriftId, String fieldName) {
+ _thriftId = thriftId;
+ _fieldName = fieldName;
+ }
+
+ public short getThriftFieldId() {
+ return _thriftId;
+ }
+
+ public String getFieldName() {
+ return _fieldName;
+ }
+ }
+
+ // isset id assignments
+ private static final int __ID_ISSET_ID = 0;
+ private BitSet __isset_bit_vector = new BitSet(1);
+
+ public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+ static {
+ Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+ tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+ tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
+ tmpMap.put(_Fields.EMAIL, new org.apache.thrift.meta_data.FieldMetaData("email", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+ tmpMap.put(_Fields.PHONE, new org.apache.thrift.meta_data.FieldMetaData("phone", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
+ new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, PhoneNumber.class))));
+ metaDataMap = Collections.unmodifiableMap(tmpMap);
+ org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Person.class, metaDataMap);
+ }
+
+ public Person() {
+ }
+
+ public Person(
+ String name,
+ int id,
+ String email,
+ List<PhoneNumber> phone)
+ {
+ this();
+ this.name = name;
+ this.id = id;
+ setIdIsSet(true);
+ this.email = email;
+ this.phone = phone;
+ }
+
+ /**
+ * Performs a deep copy on <i>other</i>.
+ */
+ public Person(Person other) {
+ __isset_bit_vector.clear();
+ __isset_bit_vector.or(other.__isset_bit_vector);
+ if (other.isSetName()) {
+ this.name = other.name;
+ }
+ this.id = other.id;
+ if (other.isSetEmail()) {
+ this.email = other.email;
+ }
+ if (other.isSetPhone()) {
+ List<PhoneNumber> __this__phone = new ArrayList<PhoneNumber>();
+ for (PhoneNumber other_element : other.phone) {
+ __this__phone.add(new PhoneNumber(other_element));
+ }
+ this.phone = __this__phone;
+ }
+ }
+
+ public Person deepCopy() {
+ return new Person(this);
+ }
+
+ // @Override
+ public void clear() {
+ this.name = null;
+ setIdIsSet(false);
+ this.id = 0;
+ this.email = null;
+ this.phone = null;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Person setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public void unsetName() {
+ this.name = null;
+ }
+
+ /** Returns true if field name is set (has been assigned a value) and false otherwise */
+ public boolean isSetName() {
+ return this.name != null;
+ }
+
+ public void setNameIsSet(boolean value) {
+ if (!value) {
+ this.name = null;
+ }
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public Person setId(int id) {
+ this.id = id;
+ setIdIsSet(true);
+ return this;
+ }
+
+ public void unsetId() {
+ __isset_bit_vector.clear(__ID_ISSET_ID);
+ }
+
+ /** Returns true if field id is set (has been assigned a value) and false otherwise */
+ public boolean isSetId() {
+ return __isset_bit_vector.get(__ID_ISSET_ID);
+ }
+
+ public void setIdIsSet(boolean value) {
+ __isset_bit_vector.set(__ID_ISSET_ID, value);
+ }
+
+ public String getEmail() {
+ return this.email;
+ }
+
+ public Person setEmail(String email) {
+ this.email = email;
+ return this;
+ }
+
+ public void unsetEmail() {
+ this.email = null;
+ }
+
+ /** Returns true if field email is set (has been assigned a value) and false otherwise */
+ public boolean isSetEmail() {
+ return this.email != null;
+ }
+
+ public void setEmailIsSet(boolean value) {
+ if (!value) {
+ this.email = null;
+ }
+ }
+
+ public int getPhoneSize() {
+ return (this.phone == null) ? 0 : this.phone.size();
+ }
+
+ public java.util.Iterator<PhoneNumber> getPhoneIterator() {
+ return (this.phone == null) ? null : this.phone.iterator();
+ }
+
+ public void addToPhone(PhoneNumber elem) {
+ if (this.phone == null) {
+ this.phone = new ArrayList<PhoneNumber>();
+ }
+ this.phone.add(elem);
+ }
+
+ public List<PhoneNumber> getPhone() {
+ return this.phone;
+ }
+
+ public Person setPhone(List<PhoneNumber> phone) {
+ this.phone = phone;
+ return this;
+ }
+
+ public void unsetPhone() {
+ this.phone = null;
+ }
+
+ /** Returns true if field phone is set (has been assigned a value) and false otherwise */
+ public boolean isSetPhone() {
+ return this.phone != null;
+ }
+
+ public void setPhoneIsSet(boolean value) {
+ if (!value) {
+ this.phone = null;
+ }
+ }
+
+ public void setFieldValue(_Fields field, Object value) {
+ switch (field) {
+ case NAME:
+ if (value == null) {
+ unsetName();
+ } else {
+ setName((String)value);
+ }
+ break;
+
+ case ID:
+ if (value == null) {
+ unsetId();
+ } else {
+ setId((Integer)value);
+ }
+ break;
+
+ case EMAIL:
+ if (value == null) {
+ unsetEmail();
+ } else {
+ setEmail((String)value);
+ }
+ break;
+
+ case PHONE:
+ if (value == null) {
+ unsetPhone();
+ } else {
+ setPhone((List<PhoneNumber>)value);
+ }
+ break;
+
+ }
+ }
+
+ public Object getFieldValue(_Fields field) {
+ switch (field) {
+ case NAME:
+ return getName();
+
+ case ID:
+ return new Integer(getId());
+
+ case EMAIL:
+ return getEmail();
+
+ case PHONE:
+ return getPhone();
+
+ }
+ throw new IllegalStateException();
+ }
+
+ /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+ public boolean isSet(_Fields field) {
+ if (field == null) {
+ throw new IllegalArgumentException();
+ }
+
+ switch (field) {
+ case NAME:
+ return isSetName();
+ case ID:
+ return isSetId();
+ case EMAIL:
+ return isSetEmail();
+ case PHONE:
+ return isSetPhone();
+ }
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (that == null)
+ return false;
+ if (that instanceof Person)
+ return this.equals((Person)that);
+ return false;
+ }
+
+ public boolean equals(Person that) {
+ if (that == null)
+ return false;
+
+ boolean this_present_name = true && this.isSetName();
+ boolean that_present_name = true && that.isSetName();
+ if (this_present_name || that_present_name) {
+ if (!(this_present_name && that_present_name))
+ return false;
+ if (!this.name.equals(that.name))
+ return false;
+ }
+
+ boolean this_present_id = true;
+ boolean that_present_id = true;
+ if (this_present_id || that_present_id) {
+ if (!(this_present_id && that_present_id))
+ return false;
+ if (this.id != that.id)
+ return false;
+ }
+
+ boolean this_present_email = true && this.isSetEmail();
+ boolean that_present_email = true && that.isSetEmail();
+ if (this_present_email || that_present_email) {
+ if (!(this_present_email && that_present_email))
+ return false;
+ if (!this.email.equals(that.email))
+ return false;
+ }
+
+ boolean this_present_phone = true && this.isSetPhone();
+ boolean that_present_phone = true && that.isSetPhone();
+ if (this_present_phone || that_present_phone) {
+ if (!(this_present_phone && that_present_phone))
+ return false;
+ if (!this.phone.equals(that.phone))
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ public int compareTo(Person other) {
+ if (!getClass().equals(other.getClass())) {
+ return getClass().getName().compareTo(other.getClass().getName());
+ }
+
+ int lastComparison = 0;
+ Person typedOther = (Person)other;
+
+ lastComparison = Boolean.valueOf(isSetName()).compareTo(typedOther.isSetName());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetName()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, typedOther.name);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetId()).compareTo(typedOther.isSetId());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetId()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, typedOther.id);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetEmail()).compareTo(typedOther.isSetEmail());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetEmail()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.email, typedOther.email);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetPhone()).compareTo(typedOther.isSetPhone());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetPhone()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.phone, typedOther.phone);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ return 0;
+ }
+
+ public _Fields fieldForId(int fieldId) {
+ return _Fields.findByThriftId(fieldId);
+ }
+
+ public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+ org.apache.thrift.protocol.TField field;
+ iprot.readStructBegin();
+ while (true)
+ {
+ field = iprot.readFieldBegin();
+ if (field.type == org.apache.thrift.protocol.TType.STOP) {
+ break;
+ }
+ switch (field.id) {
+ case 1: // NAME
+ if (field.type == org.apache.thrift.protocol.TType.STRING) {
+ this.name = iprot.readString();
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 2: // ID
+ if (field.type == org.apache.thrift.protocol.TType.I32) {
+ this.id = iprot.readI32();
+ setIdIsSet(true);
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 3: // EMAIL
+ if (field.type == org.apache.thrift.protocol.TType.STRING) {
+ this.email = iprot.readString();
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 4: // PHONE
+ if (field.type == org.apache.thrift.protocol.TType.LIST) {
+ {
+ org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
+ this.phone = new ArrayList<PhoneNumber>(_list0.size);
+ for (int _i1 = 0; _i1 < _list0.size; ++_i1)
+ {
+ PhoneNumber _elem2;
+ _elem2 = new PhoneNumber();
+ _elem2.read(iprot);
+ this.phone.add(_elem2);
+ }
+ iprot.readListEnd();
+ }
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ default:
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ iprot.readFieldEnd();
+ }
+ iprot.readStructEnd();
+
+ // check for required fields of primitive type, which can't be checked in the validate method
+ validate();
+ }
+
+ public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+ validate();
+
+ oprot.writeStructBegin(STRUCT_DESC);
+ if (this.name != null) {
+ oprot.writeFieldBegin(NAME_FIELD_DESC);
+ oprot.writeString(this.name);
+ oprot.writeFieldEnd();
+ }
+ oprot.writeFieldBegin(ID_FIELD_DESC);
+ oprot.writeI32(this.id);
+ oprot.writeFieldEnd();
+ if (this.email != null) {
+ oprot.writeFieldBegin(EMAIL_FIELD_DESC);
+ oprot.writeString(this.email);
+ oprot.writeFieldEnd();
+ }
+ if (this.phone != null) {
+ oprot.writeFieldBegin(PHONE_FIELD_DESC);
+ {
+ oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.phone.size()));
+ for (PhoneNumber _iter3 : this.phone)
+ {
+ _iter3.write(oprot);
+ }
+ oprot.writeListEnd();
+ }
+ oprot.writeFieldEnd();
+ }
+ oprot.writeFieldStop();
+ oprot.writeStructEnd();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("Person(");
+ boolean first = true;
+
+ sb.append("name:");
+ if (this.name == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.name);
+ }
+ first = false;
+ if (!first) sb.append(", ");
+ sb.append("id:");
+ sb.append(this.id);
+ first = false;
+ if (!first) sb.append(", ");
+ sb.append("email:");
+ if (this.email == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.email);
+ }
+ first = false;
+ if (!first) sb.append(", ");
+ sb.append("phone:");
+ if (this.phone == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.phone);
+ }
+ first = false;
+ sb.append(")");
+ return sb.toString();
+ }
+
+ public void validate() throws org.apache.thrift.TException {
+ // check for required fields
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+ try {
+ write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+ try {
+ // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
+ __isset_bit_vector = new BitSet(1);
+ read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+}
+
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/Person.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,433 @@
+/*
+ * 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.
+ */
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package com.example.tutorial;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+public class PhoneNumber implements org.apache.thrift.TBase<PhoneNumber, PhoneNumber._Fields>, java.io.Serializable, Cloneable {
+ private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("PhoneNumber");
+
+ private static final org.apache.thrift.protocol.TField NO_FIELD_DESC = new org.apache.thrift.protocol.TField("no", org.apache.thrift.protocol.TType.STRING, (short)1);
+ private static final org.apache.thrift.protocol.TField TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("type", org.apache.thrift.protocol.TType.I32, (short)2);
+
+ public String no;
+ /**
+ *
+ * @see PhoneType
+ */
+ public PhoneType type;
+
+ /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+ public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+ NO((short)1, "no"),
+ /**
+ *
+ * @see PhoneType
+ */
+ TYPE((short)2, "type");
+
+ private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+ static {
+ for (_Fields field : EnumSet.allOf(_Fields.class)) {
+ byName.put(field.getFieldName(), field);
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, or null if its not found.
+ */
+ public static _Fields findByThriftId(int fieldId) {
+ switch(fieldId) {
+ case 1: // NO
+ return NO;
+ case 2: // TYPE
+ return TYPE;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Find the _Fields constant that matches fieldId, throwing an exception
+ * if it is not found.
+ */
+ public static _Fields findByThriftIdOrThrow(int fieldId) {
+ _Fields fields = findByThriftId(fieldId);
+ if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+ return fields;
+ }
+
+ /**
+ * Find the _Fields constant that matches name, or null if its not found.
+ */
+ public static _Fields findByName(String name) {
+ return byName.get(name);
+ }
+
+ private final short _thriftId;
+ private final String _fieldName;
+
+ _Fields(short thriftId, String fieldName) {
+ _thriftId = thriftId;
+ _fieldName = fieldName;
+ }
+
+ public short getThriftFieldId() {
+ return _thriftId;
+ }
+
+ public String getFieldName() {
+ return _fieldName;
+ }
+ }
+
+ // isset id assignments
+
+ public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+ static {
+ Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+ tmpMap.put(_Fields.NO, new org.apache.thrift.meta_data.FieldMetaData("no", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+ tmpMap.put(_Fields.TYPE, new org.apache.thrift.meta_data.FieldMetaData("type", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, PhoneType.class)));
+ metaDataMap = Collections.unmodifiableMap(tmpMap);
+ org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(PhoneNumber.class, metaDataMap);
+ }
+
+ public PhoneNumber() {
+ }
+
+ public PhoneNumber(
+ String no,
+ PhoneType type)
+ {
+ this();
+ this.no = no;
+ this.type = type;
+ }
+
+ /**
+ * Performs a deep copy on <i>other</i>.
+ */
+ public PhoneNumber(PhoneNumber other) {
+ if (other.isSetNo()) {
+ this.no = other.no;
+ }
+ if (other.isSetType()) {
+ this.type = other.type;
+ }
+ }
+
+ public PhoneNumber deepCopy() {
+ return new PhoneNumber(this);
+ }
+
+ // @Override
+ public void clear() {
+ this.no = null;
+ this.type = null;
+ }
+
+ public String getNo() {
+ return this.no;
+ }
+
+ public PhoneNumber setNo(String no) {
+ this.no = no;
+ return this;
+ }
+
+ public void unsetNo() {
+ this.no = null;
+ }
+
+ /** Returns true if field no is set (has been assigned a value) and false otherwise */
+ public boolean isSetNo() {
+ return this.no != null;
+ }
+
+ public void setNoIsSet(boolean value) {
+ if (!value) {
+ this.no = null;
+ }
+ }
+
+ /**
+ *
+ * @see PhoneType
+ */
+ public PhoneType getType() {
+ return this.type;
+ }
+
+ /**
+ *
+ * @see PhoneType
+ */
+ public PhoneNumber setType(PhoneType type) {
+ this.type = type;
+ return this;
+ }
+
+ public void unsetType() {
+ this.type = null;
+ }
+
+ /** Returns true if field type is set (has been assigned a value) and false otherwise */
+ public boolean isSetType() {
+ return this.type != null;
+ }
+
+ public void setTypeIsSet(boolean value) {
+ if (!value) {
+ this.type = null;
+ }
+ }
+
+ public void setFieldValue(_Fields field, Object value) {
+ switch (field) {
+ case NO:
+ if (value == null) {
+ unsetNo();
+ } else {
+ setNo((String)value);
+ }
+ break;
+
+ case TYPE:
+ if (value == null) {
+ unsetType();
+ } else {
+ setType((PhoneType)value);
+ }
+ break;
+
+ }
+ }
+
+ public Object getFieldValue(_Fields field) {
+ switch (field) {
+ case NO:
+ return getNo();
+
+ case TYPE:
+ return getType();
+
+ }
+ throw new IllegalStateException();
+ }
+
+ /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+ public boolean isSet(_Fields field) {
+ if (field == null) {
+ throw new IllegalArgumentException();
+ }
+
+ switch (field) {
+ case NO:
+ return isSetNo();
+ case TYPE:
+ return isSetType();
+ }
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (that == null)
+ return false;
+ if (that instanceof PhoneNumber)
+ return this.equals((PhoneNumber)that);
+ return false;
+ }
+
+ public boolean equals(PhoneNumber that) {
+ if (that == null)
+ return false;
+
+ boolean this_present_no = true && this.isSetNo();
+ boolean that_present_no = true && that.isSetNo();
+ if (this_present_no || that_present_no) {
+ if (!(this_present_no && that_present_no))
+ return false;
+ if (!this.no.equals(that.no))
+ return false;
+ }
+
+ boolean this_present_type = true && this.isSetType();
+ boolean that_present_type = true && that.isSetType();
+ if (this_present_type || that_present_type) {
+ if (!(this_present_type && that_present_type))
+ return false;
+ if (!this.type.equals(that.type))
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ public int compareTo(PhoneNumber other) {
+ if (!getClass().equals(other.getClass())) {
+ return getClass().getName().compareTo(other.getClass().getName());
+ }
+
+ int lastComparison = 0;
+ PhoneNumber typedOther = (PhoneNumber)other;
+
+ lastComparison = Boolean.valueOf(isSetNo()).compareTo(typedOther.isSetNo());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetNo()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.no, typedOther.no);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetType()).compareTo(typedOther.isSetType());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetType()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.type, typedOther.type);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ return 0;
+ }
+
+ public _Fields fieldForId(int fieldId) {
+ return _Fields.findByThriftId(fieldId);
+ }
+
+ public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+ org.apache.thrift.protocol.TField field;
+ iprot.readStructBegin();
+ while (true)
+ {
+ field = iprot.readFieldBegin();
+ if (field.type == org.apache.thrift.protocol.TType.STOP) {
+ break;
+ }
+ switch (field.id) {
+ case 1: // NO
+ if (field.type == org.apache.thrift.protocol.TType.STRING) {
+ this.no = iprot.readString();
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 2: // TYPE
+ if (field.type == org.apache.thrift.protocol.TType.I32) {
+ this.type = PhoneType.findByValue(iprot.readI32());
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ default:
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+ }
+ iprot.readFieldEnd();
+ }
+ iprot.readStructEnd();
+
+ // check for required fields of primitive type, which can't be checked in the validate method
+ validate();
+ }
+
+ public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+ validate();
+
+ oprot.writeStructBegin(STRUCT_DESC);
+ if (this.no != null) {
+ oprot.writeFieldBegin(NO_FIELD_DESC);
+ oprot.writeString(this.no);
+ oprot.writeFieldEnd();
+ }
+ if (this.type != null) {
+ oprot.writeFieldBegin(TYPE_FIELD_DESC);
+ oprot.writeI32(this.type.getValue());
+ oprot.writeFieldEnd();
+ }
+ oprot.writeFieldStop();
+ oprot.writeStructEnd();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("PhoneNumber(");
+ boolean first = true;
+
+ sb.append("no:");
+ if (this.no == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.no);
+ }
+ first = false;
+ if (!first) sb.append(", ");
+ sb.append("type:");
+ if (this.type == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.type);
+ }
+ first = false;
+ sb.append(")");
+ return sb.toString();
+ }
+
+ public void validate() throws org.apache.thrift.TException {
+ // check for required fields
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+ try {
+ write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+ try {
+ read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+ } catch (org.apache.thrift.TException te) {
+ throw new java.io.IOException(te);
+ }
+ }
+
+}
+
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneNumber.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package com.example.tutorial;
+
+
+
+public enum PhoneType implements org.apache.thrift.TEnum {
+ MOBILE(0),
+ HOME(1),
+ WORK(2);
+
+ private final int value;
+
+ private PhoneType(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the integer value of this enum value, as defined in the Thrift IDL.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Find a the enum type by its integer value, as defined in the Thrift IDL.
+ * @return null if the value is not found.
+ */
+ public static PhoneType findByValue(int value) {
+ switch (value) {
+ case 0:
+ return MOBILE;
+ case 1:
+ return HOME;
+ case 2:
+ return WORK;
+ default:
+ return null;
+ }
+ }
+}
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/com/example/tutorial/PhoneType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java Wed Feb 23 05:45:12 2011
@@ -0,0 +1,146 @@
+package org.apache.wink.providers.thrift;
+
+/*******************************************************************************
+ * 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.
+ *
+ *******************************************************************************/
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.Assert;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.example.tutorial.Person;
+
+/**
+ * Tests the Apache Thrift provider.
+ */
+public class ThriftTest extends MockServletInvocationTest {
+
+ @Override
+ protected Class<?>[] getClasses() {
+ return new Class<?>[] {PersonResource.class};
+ }
+
+ @Override
+ protected Object[] getSingletons() {
+ return new Object[] {
+ // new WinkThriftProvider()
+ };
+ }
+
+ private static Person createPerson() {
+ return new Person().setId(1).setEmail("abc@example.com").setName("John Smith");
+ }
+
+ @Path("/test/person")
+ public static class PersonResource {
+
+ @GET
+ public Person getPerson() throws IOException {
+ return createPerson();
+ }
+
+ @POST
+ public Person postPerson(Person p) {
+ return p;
+ }
+ }
+
+ /**
+ * Tests a simple single JAXB Object to write.
+ *
+ * @throws Exception
+ */
+ public void testGetPerson() throws Exception {
+ testGet(WinkThriftProvider.THRIFT_TYPE);
+ }
+
+ private void assertEquals(Person p) {
+ Assert.assertEquals("abc@example.com", p.getEmail());
+ Assert.assertEquals(1, p.getId());
+ Assert.assertEquals("John Smith", p.getName());
+ }
+
+ /**
+ * Tests a simple single JAXB Object to both read and write.
+ *
+ * @throws Exception
+ */
+ public void testPostPerson() throws Exception {
+ testPost(WinkThriftProvider.THRIFT_TYPE);
+ }
+
+ /**
+ * Tests a simple single JAXB Object to write.
+ *
+ * @throws Exception
+ */
+ public void testGetPersonJSON() throws Exception {
+ MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
+ testGet(mediaType);
+ }
+
+ private void testGet(MediaType mediaType) throws ServletException, IOException, Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("GET", "/test/person", mediaType.toString());
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ byte[] data = response.getContentAsByteArray();
+ Person p = WinkThriftProvider.unmarshal(Person.class, mediaType, new ByteArrayInputStream(data));
+ assertEquals(p);
+ }
+
+ /**
+ * Tests a simple single JAXB Object to both read and write.
+ *
+ * @throws Exception
+ */
+ public void testPostPersonJSON() throws Exception {
+ MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
+ testPost(mediaType);
+ }
+
+ private void testPost(MediaType mediaType) throws IOException, ServletException, Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("POST", "/test/person", mediaType.toString());
+ request.setContentType(mediaType.toString());
+ Person p = createPerson();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ WinkThriftProvider.marshal(p, mediaType, bos);
+ request.setContent(bos.toByteArray());
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ byte[] data = response.getContentAsByteArray();
+ Person p1 = WinkThriftProvider.unmarshal(Person.class, mediaType, new ByteArrayInputStream(data));
+ assertEquals(p1);
+ }
+
+}
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wink/trunk/wink-thrift-provider/src/test/java/org/apache/wink/providers/thrift/ThriftTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/wink/trunk/wink-thrift-provider/src/test/resources/addressbook.thrift
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-thrift-provider/src/test/resources/addressbook.thrift?rev=1073606&view=auto
==============================================================================
--- incubator/wink/trunk/wink-thrift-provider/src/test/resources/addressbook.thrift (added)
+++ incubator/wink/trunk/wink-thrift-provider/src/test/resources/addressbook.thrift Wed Feb 23 05:45:12 2011
@@ -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.
+//
+
+namespace java com.example.tutorial
+
+enum PhoneType {
+ MOBILE = 0,
+ HOME = 1,
+ WORK = 2,
+}
+
+struct PhoneNumber {
+ 1: string no,
+ 2: PhoneType type,
+}
+
+struct Person {
+ 1: string name,
+ 2: i32 id, // Unique ID number for this person.
+ 3: string email,
+ 4: list<PhoneNumber> phone,
+}
+
+// Our address book file is just one of these.
+struct AddressBook {
+ 1: list<Person> person,
+}