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.xml.internal.bind.v2.model.impl;
325N/A
325N/Aimport java.util.LinkedHashSet;
325N/Aimport java.util.Set;
325N/A
325N/Aimport javax.xml.bind.annotation.XmlElementDecl;
325N/A
325N/Aimport com.sun.xml.internal.bind.v2.model.annotation.Locatable;
325N/Aimport com.sun.xml.internal.bind.v2.model.annotation.MethodLocatable;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.RegistryInfo;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.TypeInfo;
325N/Aimport com.sun.xml.internal.bind.v2.model.nav.Navigator;
325N/Aimport com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
325N/Aimport com.sun.xml.internal.bind.v2.runtime.Location;
325N/Aimport com.sun.xml.internal.bind.v2.ContextFactory;
325N/A
325N/A/**
325N/A * Implementation of {@link RegistryInfo}.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/A// experimenting with shorter type parameters for <T,C,F,M> quadruple.
325N/A// the idea is that they show so often that you'd understand the meaning
325N/A// without relying on the whole name.
325N/Afinal class RegistryInfoImpl<T,C,F,M> implements Locatable, RegistryInfo<T,C> {
325N/A
325N/A final C registryClass;
325N/A private final Locatable upstream;
325N/A private final Navigator<T,C,F,M> nav;
325N/A
325N/A /**
325N/A * Types that are referenced from this registry.
325N/A */
325N/A private final Set<TypeInfo<T,C>> references = new LinkedHashSet<TypeInfo<T,C>>();
325N/A
325N/A /**
325N/A * Picks up references in this registry to other types.
325N/A */
325N/A RegistryInfoImpl(ModelBuilder<T,C,F,M> builder, Locatable upstream, C registryClass) {
325N/A this.nav = builder.nav;
325N/A this.registryClass = registryClass;
325N/A this.upstream = upstream;
325N/A builder.registries.put(getPackageName(),this);
325N/A
325N/A if(nav.getDeclaredField(registryClass,ContextFactory.USE_JAXB_PROPERTIES)!=null) {
325N/A // the user is trying to use ObjectFactory that we generate for interfaces,
325N/A // that means he's missing jaxb.properties
325N/A builder.reportError(new IllegalAnnotationException(
325N/A Messages.MISSING_JAXB_PROPERTIES.format(getPackageName()),
325N/A this
325N/A ));
325N/A // looking at members will only add more errors, so just abort now
325N/A return;
325N/A }
325N/A
325N/A for( M m : nav.getDeclaredMethods(registryClass) ) {
325N/A XmlElementDecl em = builder.reader.getMethodAnnotation(
325N/A XmlElementDecl.class, m, this );
325N/A
325N/A if(em==null) {
325N/A if(nav.getMethodName(m).startsWith("create")) {
325N/A // this is a factory method. visit this class
325N/A references.add(
325N/A builder.getTypeInfo(nav.getReturnType(m),
325N/A new MethodLocatable<M>(this,m,nav)));
325N/A }
325N/A
325N/A continue;
325N/A }
325N/A
325N/A ElementInfoImpl<T,C,F,M> ei;
325N/A try {
325N/A ei = builder.createElementInfo(this,m);
325N/A } catch (IllegalAnnotationException e) {
325N/A builder.reportError(e);
325N/A continue; // recover by ignoring this element
325N/A }
325N/A
325N/A // register this mapping
325N/A // TODO: any chance this could cause a stack overflow (by recursively visiting classes)?
325N/A builder.typeInfoSet.add(ei,builder);
325N/A references.add(ei);
325N/A }
325N/A }
325N/A
325N/A public Locatable getUpstream() {
325N/A return upstream;
325N/A }
325N/A
325N/A public Location getLocation() {
325N/A return nav.getClassLocation(registryClass);
325N/A }
325N/A
325N/A public Set<TypeInfo<T,C>> getReferences() {
325N/A return references;
325N/A }
325N/A
325N/A /**
325N/A * Gets the name of the package that this registry governs.
325N/A */
325N/A public String getPackageName() {
325N/A return nav.getPackageName(registryClass);
325N/A }
325N/A
325N/A public C getClazz() {
325N/A return registryClass;
325N/A }
325N/A}