@@ -0,0 +1,2906 @@
+/*******************************************************************************%0D%0A * Copyright (c) 2011 Oracle. All rights reserved.%0D%0A * This program and the accompanying materials are made available under the%0D%0A * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0%0D%0A * which accompanies this distribution.%0D%0A * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html%0D%0A * and the Eclipse Distribution License is available at%0D%0A * http://www.eclipse.org/org/documents/edl-v10.php.%0D%0A *%0D%0A * Contributors:%0D%0A *     rbarkhouse - 2.4 - initial implementation%0D%0A ******************************************************************************/%0D%0A package org.eclipse.persistence.testing.jaxb.dynamic.util;%0D%0A%0D%0Aimport java.util.StringTokenizer;%0D%0A%0D%0Aimport javax.xml.bind.annotation.adapters.XmlAdapter;%0D%0A%0D%0Aimport org.eclipse.persistence.dynamic.DynamicEntity;%0D%0Aimport org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;%0D%0A%0D%0Apublic class LinkAdapter extends XmlAdapter%3CObject, DynamicEntity%3E %7B%0D%0A%0D%0A    // ValueType = mynamespace.Link%0D%0A    // BoundType = mynamespace.Address%0D%0A%0D%0A    public static DynamicJAXBContext jc = null;%0D%0A%0D%0A    public LinkAdapter() %7B%0D%0A        this(jc);%0D%0A    %7D%0D%0A%0D%0A    public LinkAdapter(DynamicJAXBContext jc) %7B%0D%0A        this.jc = jc;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public DynamicEntity unmarshal(Object v) throws Exception %7B%0D%0A        DynamicEntity link = (DynamicEntity) v;%0D%0A%0D%0A        DynamicEntity address = jc.newDynamicEntity(%22mynamespace.Address%22);%0D%0A%0D%0A        StringTokenizer tokenizer = new StringTokenizer(link.get(%22href%22).toString(), %22&%22, false);%0D%0A%0D%0A        String street = tokenizer.nextToken();%0D%0A        street = street.substring(street.lastIndexOf(%22=%22) + 1);%0D%0A        street = street.replace('_', ' ');%0D%0A        String city = tokenizer.nextToken();%0D%0A        city = city.substring(city.lastIndexOf(%22=%22) + 1);%0D%0A        String state = tokenizer.nextToken();%0D%0A        state = state.substring(state.lastIndexOf(%22=%22) + 1);%0D%0A        String zip = tokenizer.nextToken();%0D%0A        zip = zip.substring(zip.lastIndexOf(%22=%22) + 1);%0D%0A%0D%0A        address.set(%22street%22, street);%0D%0A        address.set(%22city%22, city);%0D%0A        address.set(%22state%22, state);%0D%0A        address.set(%22zip%22, zip);%0D%0A%0D%0A        return address;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public Object marshal(DynamicEntity v) throws Exception %7B%0D%0A        if(null == jc %7C%7C null == v) %7B%0D%0A            return null;%0D%0A        %7D%0D%0A%0D%0A        String street = v.get(%22street%22);%0D%0A        street = street.replace(' ', '_');%0D%0A        String city = v.get(%22city%22);%0D%0A        String state = v.get(%22state%22);%0D%0A        String zip = v.get(%22zip%22);%0D%0A%0D%0A        DynamicEntity link = jc.newDynamicEntity(%22mynamespace.Link%22);%0D%0A        link.set(%22rel%22, %22self%22);%0D%0A        link.set(%22href%22, %22http://www.address.com/findAddress?str=%22 + street + %22&city=%22 + city + %22&state=%22 + state + %22&zip=%22 + zip);%0D%0A        return link;%0D%0A    %7D%0D%0A%0D%0A%7D

Fix for bug 362905, reviewed by bdoughan