/* * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.internal.xjc.reader.dtd.bindinfo; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import com.sun.tools.internal.xjc.model.CClassInfo; import com.sun.xml.internal.bind.api.impl.NameConverter; import org.w3c.dom.Element; import org.xml.sax.Locator; /** * <element> declaration in the binding file. */ public final class BIElement { /** * Wraps a given <element> element in the binding file. * *
* Should be created only from {@link BindInfo}.
*/
BIElement( BindInfo bi, Element _e ) {
this.parent = bi;
this.e = _e;
{
Element c = DOMUtil.getElement(e,"content");
if(c!=null) {
if(DOMUtil.getAttribute(c,"property")!=null) {
// if @property is there, this is a general declaration
this.rest = BIContent.create(c,this);
} else {
// this must be a model-based declaration
for( Element p : DOMUtil.getChildElements(c) ) {
if(p.getLocalName().equals("rest"))
this.rest = BIContent.create(p,this);
else
this.contents.add(BIContent.create(p,this));
}
}
}
}
// parse
* This vector will be empty if no content-property declaration is made.
*/
private final List
* This field is null when there was no "rest" declaration.
*/
private BIContent rest;
/** Attribute-property declarations. */
private final Map
* This method returns null if this declaration
* is an element-property declaration.
*/
public String getClassName() {
return className;
}
/**
* Creates constructor declarations for this element.
*
*
* This method should only be called by DTDReader after
* the normalization has completed.
*
* @param src
* The ClassItem object that corresponds to this declaration
*/
public void declareConstructors( CClassInfo src ) {
for( BIConstructor c : constructors )
c.createDeclaration(src);
}
/**
* Gets the conversion method for this element.
*
*
* This method can be called only when this element
* declaration is designated as element-value.
*
* @return
* If the convert attribute is not specified, this
* method returns null.
*/
public BIConversion getConversion() {
String cnv = DOMUtil.getAttribute(e,"convert");
if(cnv==null) return null;
return conversion(cnv);
}
/**
* Resolves the conversion name to the conversion declaration.
*
*
* Element-local declarations are checked first.
*
* @return
* A non-null valid BIConversion object.
*/
public BIConversion conversion( String name ) {
BIConversion r = conversions.get(name);
if(r!=null) return r;
// check the global conversion declarations
return parent.conversion(name);
}
/**
* Iterates all content-property declarations (except 'rest').
*/
public List