aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.xjc.model; aoqi@0: aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Collection; aoqi@0: aoqi@0: import com.sun.tools.internal.xjc.Plugin; aoqi@0: aoqi@0: /** aoqi@0: * Represents the list of {@link CPluginCustomization}s attached to a JAXB model component. aoqi@0: * aoqi@0: *

aoqi@0: * When {@link Plugin}s register the customization namespace URIs through {@link Plugin#getCustomizationURIs()}, aoqi@0: * XJC will treat those URIs just like XJC's own extension "http://java.sun.com/xml/ns/xjc" and make them aoqi@0: * available as DOM nodes through {@link CPluginCustomization}. A {@link Plugin} can then access aoqi@0: * this information to change its behavior. aoqi@0: * aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: */ aoqi@0: public final class CCustomizations extends ArrayList { aoqi@0: aoqi@0: /** aoqi@0: * All {@link CCustomizations} used by a {@link Model} form a single linked list aoqi@0: * so that we can look for unacknowledged customizations later. aoqi@0: * aoqi@0: * @see CPluginCustomization#markAsAcknowledged() aoqi@0: * @see #setParent(Model,CCustomizable) aoqi@0: */ aoqi@0: /*package*/ CCustomizations next; aoqi@0: aoqi@0: /** aoqi@0: * The owner model component that carries these customizations. aoqi@0: */ aoqi@0: private CCustomizable owner; aoqi@0: aoqi@0: public CCustomizations() { aoqi@0: } aoqi@0: aoqi@0: public CCustomizations(Collection cPluginCustomizations) { aoqi@0: super(cPluginCustomizations); aoqi@0: } aoqi@0: aoqi@0: /*package*/ void setParent(Model model,CCustomizable owner) { aoqi@0: if(this.owner!=null) return; aoqi@0: aoqi@0: // // loop check aoqi@0: // for( CCustomizations c = model.customizations; c!=null; c=c.next ) aoqi@0: // assert c!=this; aoqi@0: aoqi@0: this.next = model.customizations; aoqi@0: model.customizations = this; aoqi@0: assert owner!=null; aoqi@0: this.owner = owner; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Gets the model component that carries this customization. aoqi@0: * aoqi@0: * @return never null. aoqi@0: */ aoqi@0: public CCustomizable getOwner() { aoqi@0: assert owner!=null; aoqi@0: return owner; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Finds the first {@link CPluginCustomization} that belongs to the given namespace URI. aoqi@0: * @return null if not found aoqi@0: */ aoqi@0: public CPluginCustomization find( String nsUri ) { aoqi@0: for (CPluginCustomization p : this) { aoqi@0: if(fixNull(p.element.getNamespaceURI()).equals(nsUri)) aoqi@0: return p; aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Finds the first {@link CPluginCustomization} that belongs to the given namespace URI and the local name. aoqi@0: * @return null if not found aoqi@0: */ aoqi@0: public CPluginCustomization find( String nsUri, String localName ) { aoqi@0: for (CPluginCustomization p : this) { aoqi@0: if(fixNull(p.element.getNamespaceURI()).equals(nsUri) aoqi@0: && fixNull(p.element.getLocalName()).equals(localName)) aoqi@0: return p; aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: private String fixNull(String s) { aoqi@0: if(s==null) return ""; aoqi@0: else return s; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Convenient singleton instance that represents an empty {@link CCustomizations}. aoqi@0: */ aoqi@0: public static final CCustomizations EMPTY = new CCustomizations(); aoqi@0: aoqi@0: /** aoqi@0: * Merges two {@link CCustomizations} objects into one. aoqi@0: */ aoqi@0: public static CCustomizations merge(CCustomizations lhs, CCustomizations rhs) { aoqi@0: if(lhs==null || lhs.isEmpty()) return rhs; aoqi@0: if(rhs==null || rhs.isEmpty()) return lhs; aoqi@0: aoqi@0: CCustomizations r = new CCustomizations(lhs); aoqi@0: r.addAll(rhs); aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: public boolean equals(Object o) { aoqi@0: return this==o; aoqi@0: } aoqi@0: aoqi@0: public int hashCode() { aoqi@0: return System.identityHashCode(this); aoqi@0: } aoqi@0: }