Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.
javax.xml.bind.annotation

Annotation Type XmlElementDecl


  • @Retention(value=RUNTIME)
    @Target(value=METHOD)
    public @interface XmlElementDecl
    Maps a factory method to a XML element.

    Usage

    The annotation creates a mapping between an XML schema element declaration and a element factory method that returns a JAXBElement instance representing the element declaration. Typically, the element factory method is generated (and annotated) from a schema into the ObjectFactory class in a Java package that represents the binding of the element declaration's target namespace. Thus, while the annotation syntax allows @XmlElementDecl to be used on any method, semantically its use is restricted to annotation of element factory method. The usage is subject to the following constraints:
    • The class containing the element factory method annotated with @XmlElementDecl must be marked with XmlRegistry.
    • The element factory method must take one parameter assignable to Object.

    Example 1: Annotation on a factory method

         // Example: code fragment
         @XmlRegistry
         class ObjectFactory {
             @XmlElementDecl(name="foo")
             JAXBElement<String> createFoo(String s) { ... }
         }
     
         <!-- XML input -->
           <foo>string
    
         // Example: code fragment corresponding to XML input
         JAXBElement o =
         (JAXBElement)unmarshaller.unmarshal(aboveDocument);
         // print JAXBElement instance to show values
         System.out.println(o.getName());   // prints  "{}foo"
         System.out.println(o.getValue());  // prints  "string"
         System.out.println(o.getValue().getClass()); // prints "java.lang.String"
    
         <!-- Example: XML schema definition -->
         <xs:element name="foo" type="xs:string"/>
     

    Example 2: Element declaration with non local scope

    The following example illustrates the use of scope annotation parameter in binding of element declaration in schema derived code.

    The following example may be replaced in a future revision of this javadoc.

         <!-- Example: XML schema definition -->
         <xs:schema>
           <xs:complexType name="pea">
             <xs:choice maxOccurs="unbounded">
               <xs:element name="foo" type="xs:string"/>
               <xs:element name="bar" type="xs:string"/>
             </xs:choice>
           </xs:complexType>
           <xs:element name="foo" type="xs:int"/>
         </xs:schema>
     
         // Example: expected default binding
         class Pea {
             @XmlElementRefs({
                 @XmlElementRef(name="foo",type=JAXBElement.class)
                 @XmlElementRef(name="bar",type=JAXBElement.class)
             })
             List<JAXBElement<String>> fooOrBar;
         }
    
         @XmlRegistry
         class ObjectFactory {
             @XmlElementDecl(scope=Pea.class,name="foo")
             JAXBElement createPeaFoo(String s);
    
             @XmlElementDecl(scope=Pea.class,name="bar")
             JAXBElement createPeaBar(String s);
    
             @XmlElementDecl(name="foo")
             JAXBElement createFoo(Integer i);
         }
    
     
    Without scope createFoo and createPeaFoo would become ambiguous since both of them map to a XML schema element with the same local name "foo".
    Since:
    JAXB 2.0
    See Also:
    XmlRegistry
    • Element Detail

      • name

        public abstract String name
        local name of the XML element.

        Note to reviewers: There is no default name; since the annotation is on a factory method, it is not clear that the method name can be derived from the factory method name.

        See Also:
        namespace()
      • scope

        public abstract Class scope
        scope of the mapping.

        If this is not XmlElementDecl.GLOBAL, then this element declaration mapping is only active within the specified class.

        Default:
        javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class
      • namespace

        public abstract String namespace
        namespace name of the XML element.

        If the value is "##default", then the value is the namespace name for the package of the class containing this factory method.

        See Also:
        name()
        Default:
        "##default"
      • substitutionHeadNamespace

        public abstract String substitutionHeadNamespace
        namespace name of a substitution group's head XML element.

        This specifies the namespace name of the XML element whose local name is specified by substitutionHeadName().

        If susbtitutionHeadName() is "", then this value can only be "##default". But the value is ignored since since this element is not part of susbtitution group when the value of susbstitutionHeadName() is "".

        If susbtitutionHeadName() is not "" and the value is "##default", then the namespace name is the namespace name to which the package of the containing class, marked with XmlRegistry, is mapped.

        If susbtitutionHeadName() is not "" and the value is not "##default", then the value is the namespace name.

        See Also:
        substitutionHeadName()
        Default:
        "##default"
      • substitutionHeadName

        public abstract String substitutionHeadName
        XML local name of a substitution group's head element.

        If the value is "", then this element is not part of any substitution group.

        See Also:
        substitutionHeadNamespace()
        Default:
        ""
      • defaultValue

        public abstract String defaultValue
        Default value of this element.

        The

        ''
        value specified as a default of this annotation element is used as a poor-man's substitute for null to allow implementations to recognize the 'no default value' state.
        Default:
        "\u0000"

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/xml/bind/annotation/xmlelementdecl.html/.html/

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:fr Manuel PHP : https://docs.oracle.com

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut