001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.aegis.client;
019:
020: import java.net.MalformedURLException;
021: import java.net.URL;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.aegis.databinding.AegisDatabinding;
026: import org.apache.cxf.aegis.type.TypeMapping;
027: import org.apache.cxf.aegis.type.basic.ArrayType;
028: import org.apache.cxf.aegis.type.basic.BeanType;
029: import org.apache.cxf.binding.soap.Soap11;
030: import org.apache.cxf.endpoint.Client;
031: import org.apache.cxf.endpoint.ClientImpl;
032: import org.apache.cxf.service.Service;
033:
034: public final class BookDynamicClient {
035: static final String ENCODED_NS = Soap11.getInstance()
036: .getSoapEncodingStyle();
037:
038: private BookDynamicClient() {
039: //utility class
040: }
041:
042: public static void main(String args[]) {
043: // String serviceURL = "http://localhost:8080/BookService";
044: try {
045: Client client = new ClientImpl(new URL(
046: "http://localhost:6980/BookService?WSDL"));
047:
048: Service s = client.getEndpoint().getService();
049: AegisDatabinding db = new AegisDatabinding();
050: s.setDataBinding(db);
051: db.initialize(s);
052:
053: TypeMapping tm = (TypeMapping) s.get(TypeMapping.class
054: .getName());
055: BeanType type = new BeanType();
056: type.setSchemaType(new QName(
057: "http://org.codehaus.xfire.client", "Book"));
058: type.setTypeClass(Book.class);
059: type.setTypeMapping(tm);
060:
061: System.out.println(type);
062:
063: tm.register(type);
064:
065: ArrayType aType = new ArrayType();
066: aType.setTypeClass(Book[].class);
067: aType.setSchemaType(new QName(
068: "http://client.xfire.codehaus.org", "ArrayOfBook"));
069: aType.setTypeMapping(tm);
070: tm.register(aType);
071:
072: QName qn = tm.getTypeQName(Book.class);
073: System.out.println("QName(" + tm.isRegistered(Book.class)
074: + ") = " + qn);
075:
076: Book book = new Book();
077:
078: book.setAuthor("Dan");
079: book.setIsbn("1");
080: book.setTitle("XFire in Action");
081: // client.invoke("addBook", new Object[] {book});
082:
083: book.setAuthor("Dierk");
084: book.setIsbn("2");
085: book.setTitle("Groovy in Action");
086: // client.invoke("addBook", new Object[] {book});
087:
088: Book[] books = (Book[]) client.invoke("getBooks",
089: new Object[] {})[0];
090:
091: System.out.println("BOOKS:");
092:
093: for (int i = 0; i < books.length; i++) {
094: System.out.println(books[i].getTitle());
095: }
096: /*
097: * Book[] books = (Book [])client.invoke("findBook", new Object[]
098: * {"2"});; System.out.println("ISBN :");
099: * System.out.println(books[0].getAuthor());
100: */
101: } catch (MalformedURLException e) {
102: e.printStackTrace();
103: } catch (Exception e) {
104: // TODO Auto-generated catch block
105: e.printStackTrace();
106: }
107:
108: }
109: }
|