com.sun.tools.ws.processor.model.jaxb.JAXBModel Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.tools.ws.processor.model.jaxb;
import com.sun.tools.xjc.api.J2SJAXBModel;
import com.sun.tools.xjc.api.Mapping;
import com.sun.tools.xjc.api.S2JJAXBModel;
import javax.xml.namespace.QName;
import java.util.*;
/**
* Root of the JAXB Model.
*
*
* This is just a wrapper around a list of {@link JAXBMapping}s.
*
* @author Kohsuke Kawaguchi, Vivek Pandey
*/
public class JAXBModel {
/**
* All the mappings known to this model.
*/
private List mappings;
// index for faster access.
private final Map byQName = new HashMap();
private final Map byClassName = new HashMap();
private com.sun.tools.xjc.api.JAXBModel rawJAXBModel;
public com.sun.tools.xjc.api.JAXBModel getRawJAXBModel() {
return rawJAXBModel;
}
/**
* @return Schema to Java model
*/
public S2JJAXBModel getS2JJAXBModel(){
if(rawJAXBModel instanceof S2JJAXBModel)
return (S2JJAXBModel)rawJAXBModel;
return null;
}
/**
* @return Java to Schema JAXBModel
*/
public J2SJAXBModel getJ2SJAXBModel(){
if(rawJAXBModel instanceof J2SJAXBModel)
return (J2SJAXBModel)rawJAXBModel;
return null;
}
/**
* Default constructor for the persistence.
*/
public JAXBModel() {}
/**
* Constructor that fills in the values from the given raw model
*/
public JAXBModel( com.sun.tools.xjc.api.JAXBModel rawModel ) {
this.rawJAXBModel = rawModel;
if(rawModel instanceof S2JJAXBModel){
S2JJAXBModel model = (S2JJAXBModel)rawModel;
List ms = new ArrayList(model.getMappings().size());
for( Mapping m : model.getMappings())
ms.add(new JAXBMapping(m));
setMappings(ms);
}
}
/**
*/
public List getMappings() {
return mappings;
}
//public void setMappings(List mappings) {
public void setMappings(List mappings) {
this.mappings = mappings;
byQName.clear();
byClassName.clear();
for( JAXBMapping m : mappings ) {
byQName.put(m.getElementName(),m);
byClassName.put(m.getType().getName(),m);
}
}
/**
*/
public JAXBMapping get( QName elementName ) {
return byQName.get(elementName);
}
/**
*/
public JAXBMapping get( String className ) {
return byClassName.get(className);
}
/**
*
* @return set of full qualified class names that jaxb will generate
*/
public Set getGeneratedClassNames() {
return generatedClassNames;
}
public void setGeneratedClassNames(Set generatedClassNames) {
this.generatedClassNames = generatedClassNames;
}
private Set generatedClassNames;
}