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.j2s;
325N/A
325N/Aimport java.util.Collection;
325N/Aimport java.util.Collections;
325N/Aimport java.util.HashMap;
325N/Aimport java.util.Map;
325N/A
325N/Aimport javax.xml.bind.annotation.XmlList;
325N/Aimport javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/Aimport com.sun.mirror.apt.AnnotationProcessorEnvironment;
325N/Aimport com.sun.mirror.apt.Messager;
325N/Aimport com.sun.mirror.declaration.FieldDeclaration;
325N/Aimport com.sun.mirror.declaration.MethodDeclaration;
325N/Aimport com.sun.mirror.declaration.TypeDeclaration;
325N/Aimport com.sun.mirror.type.TypeMirror;
325N/Aimport com.sun.tools.internal.jxc.apt.InlineAnnotationReaderImpl;
325N/Aimport com.sun.tools.internal.jxc.model.nav.APTNavigator;
325N/Aimport com.sun.tools.internal.xjc.api.J2SJAXBModel;
325N/Aimport com.sun.tools.internal.xjc.api.JavaCompiler;
325N/Aimport com.sun.tools.internal.xjc.api.Reference;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.Ref;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
325N/Aimport com.sun.xml.internal.bind.v2.model.impl.ModelBuilder;
325N/Aimport com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
325N/A
325N/A/**
325N/A * @author Kohsuke Kawaguchi (kk@kohsuke.org)
325N/A */
325N/Apublic class JavaCompilerImpl implements JavaCompiler {
325N/A public J2SJAXBModel bind(
325N/A Collection<Reference> rootClasses,
325N/A Map<QName,Reference> additionalElementDecls,
325N/A String defaultNamespaceRemap,
325N/A AnnotationProcessorEnvironment env) {
325N/A
325N/A ModelBuilder<TypeMirror,TypeDeclaration,FieldDeclaration,MethodDeclaration> builder =
325N/A new ModelBuilder<TypeMirror,TypeDeclaration,FieldDeclaration,MethodDeclaration>(
325N/A InlineAnnotationReaderImpl.theInstance,
325N/A new APTNavigator(env),
325N/A Collections.<TypeDeclaration,TypeDeclaration>emptyMap(),
325N/A defaultNamespaceRemap );
325N/A
325N/A builder.setErrorHandler(new ErrorHandlerImpl(env.getMessager()));
325N/A
325N/A for( Reference ref : rootClasses ) {
325N/A TypeMirror t = ref.type;
325N/A
325N/A XmlJavaTypeAdapter xjta = ref.annotations.getAnnotation(XmlJavaTypeAdapter.class);
325N/A XmlList xl = ref.annotations.getAnnotation(XmlList.class);
325N/A
325N/A builder.getTypeInfo(new Ref<TypeMirror,TypeDeclaration>(builder,t,xjta,xl));
325N/A }
325N/A
325N/A TypeInfoSet r = builder.link();
325N/A if(r==null) return null;
325N/A
325N/A if(additionalElementDecls==null)
325N/A additionalElementDecls = Collections.emptyMap();
325N/A else {
325N/A // fool proof check
325N/A for (Map.Entry<QName, ? extends Reference> e : additionalElementDecls.entrySet()) {
325N/A if(e.getKey()==null)
325N/A throw new IllegalArgumentException("nulls in additionalElementDecls");
325N/A }
325N/A }
325N/A return new JAXBModelImpl(r,builder.reader,rootClasses,new HashMap(additionalElementDecls));
325N/A }
325N/A
325N/A private static final class ErrorHandlerImpl implements ErrorHandler {
325N/A private final Messager messager;
325N/A
325N/A public ErrorHandlerImpl(Messager messager) {
325N/A this.messager = messager;
325N/A }
325N/A
325N/A public void error(IllegalAnnotationException e) {
325N/A messager.printError(e.toString());
325N/A }
325N/A }
325N/A}