| /******************************************************************************* |
| * Copyright (c) 2010-2012 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| * which accompanies this distribution. |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * dclarke - EclipseLink 2.4 - MySports Demo Bug 344608 |
| ******************************************************************************/ |
| package example.mysports.persistence; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| import javax.xml.bind.JAXBContext; |
| |
| import org.eclipse.persistence.config.SessionCustomizer; |
| import org.eclipse.persistence.jaxb.JAXBContextProperties; |
| import org.eclipse.persistence.sessions.Session; |
| |
| import example.mysports.MySportsConfig; |
| |
| /** |
| * Create an EclipseLink {@link JAXBContext} which is built from the |
| * {@value #MAPPING_FILE} combined with the virtual attribute extended mappings |
| * returned from the call to the Admin server. |
| * |
| * @author dclarke |
| * @since EclipseLink 2.4 |
| */ |
| public class ConfigureMOXyContext implements SessionCustomizer { |
| |
| /** |
| * EclipseLink MOXy mapping file to use when creating the context |
| */ |
| private static final String MAPPING_FILE = "META-INF/eclipselink-oxm.xml"; |
| |
| @Override |
| public void customize(Session session) throws Exception { |
| MySportsConfig config = MySportsConfig.get(session.getProperties()); |
| String leagueId = (String) session.getProperty(MySportsConfig.LEAGUE_CONTEXT); |
| |
| if (leagueId != null) { |
| Map<String, Object> props = new HashMap<String, Object>(); |
| |
| List<String> xmlBindings = new ArrayList<String>(); |
| xmlBindings.add(MAPPING_FILE); |
| |
| String url = config.getAdminConnector().getOxmURL(leagueId); |
| if (url != null) { |
| xmlBindings.add(url); |
| } |
| props.put(JAXBContextProperties.OXM_METADATA_SOURCE, xmlBindings); |
| |
| } |
| } |
| |
| } |