325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.tools.internal.xjc.api.impl.s2j;
325N/A
325N/Aimport java.util.ArrayList;
325N/Aimport java.util.Collection;
325N/Aimport java.util.HashMap;
325N/Aimport java.util.List;
325N/Aimport java.util.Map;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/Aimport com.sun.codemodel.internal.JCodeModel;
325N/Aimport com.sun.codemodel.internal.JClass;
325N/Aimport com.sun.tools.internal.xjc.Plugin;
325N/Aimport com.sun.tools.internal.xjc.api.ErrorListener;
325N/Aimport com.sun.tools.internal.xjc.api.JAXBModel;
325N/Aimport com.sun.tools.internal.xjc.api.Mapping;
325N/Aimport com.sun.tools.internal.xjc.api.S2JJAXBModel;
325N/Aimport com.sun.tools.internal.xjc.api.TypeAndAnnotation;
325N/Aimport com.sun.tools.internal.xjc.model.CClassInfo;
325N/Aimport com.sun.tools.internal.xjc.model.CElementInfo;
325N/Aimport com.sun.tools.internal.xjc.model.Model;
325N/Aimport com.sun.tools.internal.xjc.model.TypeUse;
325N/Aimport com.sun.tools.internal.xjc.outline.Outline;
325N/Aimport com.sun.tools.internal.xjc.outline.PackageOutline;
325N/A
325N/A/**
325N/A * {@link JAXBModel} implementation.
325N/A *
325N/A * @author
325N/A * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
325N/A */
325N/Afinal class JAXBModelImpl implements S2JJAXBModel {
325N/A /*package*/ final Outline outline;
325N/A
325N/A /**
325N/A * All the known classes.
325N/A */
325N/A private final Model model;
325N/A
325N/A private final Map<QName,Mapping> byXmlName = new HashMap<QName,Mapping>();
325N/A
325N/A JAXBModelImpl(Outline outline) {
325N/A this.model = outline.getModel();
325N/A this.outline = outline;
325N/A
325N/A for (CClassInfo ci : model.beans().values()) {
325N/A if(!ci.isElement())
325N/A continue;
325N/A byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci));
325N/A }
325N/A for (CElementInfo ei : model.getElementMappings(null).values()) {
325N/A byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei));
325N/A }
325N/A }
325N/A
325N/A public JCodeModel generateCode(Plugin[] extensions,ErrorListener errorListener) {
325N/A // we no longer do any code generation
325N/A return outline.getCodeModel();
325N/A }
325N/A
325N/A public List<JClass> getAllObjectFactories() {
325N/A List<JClass> r = new ArrayList<JClass>();
325N/A for (PackageOutline pkg : outline.getAllPackageContexts()) {
325N/A r.add(pkg.objectFactory());
325N/A }
325N/A return r;
325N/A }
325N/A
325N/A public final Mapping get(QName elementName) {
325N/A return byXmlName.get(elementName);
325N/A }
325N/A
325N/A public final Collection<? extends Mapping> getMappings() {
325N/A return byXmlName.values();
325N/A }
325N/A
325N/A public TypeAndAnnotation getJavaType(QName xmlTypeName) {
325N/A // TODO: primitive type handling?
325N/A TypeUse use = model.typeUses().get(xmlTypeName);
325N/A if(use==null) return null;
325N/A
325N/A return new TypeAndAnnotationImpl(outline,use);
325N/A }
325N/A
325N/A public final List<String> getClassList() {
325N/A List<String> classList = new ArrayList<String>();
325N/A
325N/A // list up root classes
325N/A for( PackageOutline p : outline.getAllPackageContexts() )
325N/A classList.add( p.objectFactory().fullName() );
325N/A return classList;
325N/A }
325N/A}