/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* Internalizes external binding declarations.
*
* <p>
* The {@link #transform(DOMForest,boolean)} method is the entry point.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
class Internalizer {
/**
* Internalize all <jaxb:bindings> customizations in the given forest.
*
* @return
* if the SCD support is enabled, the return bindings need to be applied
* after schema components are parsed.
* If disabled, the returned binding set will be empty.
* SCDs are only for XML Schema, and doesn't make any sense for other
* schema languages.
*/
}
}
/**
* DOMForest object currently being processed.
*/
/**
* All errors found during the transformation is sent to this object.
*/
/**
* If true, the SCD-based target selection is supported.
*/
private boolean enableSCD;
// either target nodes are conventional DOM nodes (as per spec),
// ... or it will be schema components by means of SCD (RI extension)
//
// identify target nodes for all <jaxb:bindings>
//
// initially, the inherited context is itself
}
//
// then move them to their respective positions.
//
}
return scd;
}
/**
* Validates attributes of a <jaxb:bindings> element.
*/
if( a.getNamespaceURI()!=null )
continue; // all foreign namespace OK.
continue;
continue;
continue;
// enhancements
continue;
continue;
// TODO: flag error for this undefined attribute
}
}
/**
* Determines the target node of the "bindings" element
* by using the inherited target node, then put
* the result into the "result" map and the "scd" map.
*
* @param inheritedTarget
* The current target node. This always exists, even if
* the user starts specifying targets via SCD (in that case
* this inherited target is just not going to be used.)
* @param inheritedSCD
* If the ancestor <bindings> node specifies @scd to
* specify the target via SCD, then this parameter represents that context.
*/
// start by the inherited target
boolean required = true;
boolean multiple = false;
required = false;
}
multiple = true;
}
// look for @schemaLocation
// enhancement - schemaLocation="*" = bind to all schemas..
buildTargetNodeMap(value, forest.get(systemId).getDocumentElement(), inheritedSCD, result, scdResult);
}
return;
} else {
try {
// TODO: use the URI class
// TODO: honor xml:base
);
}
} catch( MalformedURLException e ) {
} catch( IOException e ) {
}
return; // abort processing this <jaxb:bindings>
}
}
}
// look for @node
// evaluate this XPath
try {
} catch (XPathExpressionException e) {
if(required) {
return; // abort processing this <jaxb:bindings>
} else {
return;
}
}
if(required)
return; // abort
}
if(!multiple) {
return; // abort
} else {
}
}
}
// check
return; // abort
}
return; // abort
}
} else {
return; // abort
}
return; // abort
}
}
}
}
// look for @scd
if(!enableSCD) {
// SCD selector was found, but it's not activated. report an error
// but recover by handling it anyway. this also avoids repeated error messages.
enableSCD = true;
}
try {
} catch (ParseException e) {
return; // abort processing this bindings
}
}
// update the result map
if (inheritedSCD != null) {
} else {
}
}
// look for child <jaxb:bindings> and process them recursively
else {
}
}
}
/**
* Moves JAXB customizations under their respective target nodes.
*/
return; // abort
}
// recover from the error by ignoring this node
{
return;
}
// process child <jaxb:bindings> recursively
// <jaxb:globalBindings> always go to the root of document.
return;
} else {
}
} else {
}
} else {
return; // abort
}
return; // abort
}
// move this node under the target
}
}
}
}
/**
* Moves the "decl" node under the "target" node.
*
* @param decl
* A JAXB customization element (e.g., <jaxb:class>)
*
* @param target
* XML Schema element under which the declaration should move.
* For example, <xs:element>
*/
// copy in-scope namespace declarations of the decl node
// to the decl node itself so that this move won't change
// the in-scope namespace bindings.
while(true) {
else prefix = a.getLocalName();
// if this is the first time we see this namespace bindings,
// copy the declaration.
// if p==decl, there's no need to. Note that
// we want to add prefix to inscopes even if p==Decl
}
}
}
if( p.getParentNode() instanceof Document )
break;
p = (Element)p.getParentNode();
}
// if the default namespace was undeclared in the context of decl,
// it must be explicitly set to "" since the new environment might
// have a different default namespace URI.
}
// finally move the declaration to the target node.
// if they belong to different DOM documents, we need to clone them
// this effectively clones a ndoe,, so we need to copy locators.
}
}
/**
* Recursively visits sub-elements and declare all used namespaces.
* TODO: the fact that we recognize all namespaces in the extension
* is a bad design.
*/
// if this comes from external namespaces, add the namespace to
// @extensionBindingPrefixes.
if( n instanceof Element )
}
}
/** Attribute name. */
/**
* Adds the specified namespace URI to the jaxb:extensionBindingPrefixes
* attribute of the target document.
*/
// look for the attribute
// no such attribute. Create one.
}
// avoid redeclaring the same namespace twice.
}
/**
* Declares a new prefix on the given element and associates it
* with the specified namespace URI.
* <p>
* Note that this method doesn't use the default namespace
* even if it can.
*/
// look for existing namespaces.
return a.getLocalName(); // found one
}
}
// none found. allocate new.
while(true) {
continue; // this prefix is already allocated.
return prefix;
}
}
/**
* Copies location information attached to the "src" node to the "dst" node.
*/
// recursively process child elements
}
}
errorHandler.error(e);
}
}