Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.eclipse.winery.repository.resources.artifacts.GenericArtifactsResource.java

/**
 * @return TImplementationArtifact | TDeploymentArtifact (XML) | URL of generated IA zip (in case of autoGenerateIA)
 *//*from ww  w  . jav  a  2s.c o  m*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_XML)
@RestDoc(methodDescription = "Creates a new implementation/deployment artifact. "
        + "If an implementation artifact with the same name already exists, it is <em>overridden</em>.")
@SuppressWarnings("unchecked")
public Response onPost(
        @FormParam("artifactName") @RestDocParam(description = "This is the name of the implementation/deployment artifact. "
                + "Is <em>also</em>used as prefix of the name of the corresponding artifact template if no specific template is provided. "
                + "In contrast to CS01, we require a artifactName also for the implementationArtifact to be able to properly referencing it.") String artifactNameStr,

        @FormParam("artifactTemplate") @RestDocParam(description = "QName of the artifact Template - used by Winery Backend instead of artifactTemplateName + artifactTemplateNS") String artifactTemplate,

        @FormParam("artifactTemplateName") @RestDocParam(description = "if provided and autoCreateArtifactTemplate, a template of this id localname and artifactTemplateNS generated. "
                + "Winery always sends this string if auto creation is desired.") String artifactTemplateName,

        @FormParam("artifactTemplateNS") String artifactTemplateNS,

        @FormParam("autoCreateArtifactTemplate") @RestDocParam(description = "if empty, no, or false, no artifact template is created. "
                + "An artifact type has to be given in that case. "
                + "Furthermore, an artifact template name + artifact template namespace has to be provided. "
                + "Otherwise, the artifactNameStr is used as name for the artifact and a <em>new</em> artifact template is created having {@code <artifactNameString>Template} as name") String autoCreateArtifactTemplate,

        @FormParam("artifactType") @RestDocParam(description = "QName of the type, format: {namespace}localname. "
                + "Optional if artifactTemplateName + artifactTempalteNS is provided") String artifactTypeStr,

        @FormParam("artifactSpecificContent") @RestDocParam(description = "<em>XML</em> snippet that should be put inside the artifact XML in the TOSCA serialization. "
                + "This feature will be removed soon. "
                + "TODO: This only works if there is a single child element expected and not several elements. "
                + "Future versions of the Winery will support arbitrary content there.") String artifactSpecificContent,

        @FormParam("interfaceName") String interfaceNameStr,

        @FormParam("operationName") String operationNameStr,

        @FormParam("autoGenerateIA") @RestDocParam(description = "If not empty, the IA generator will be called") String autoGenerateIA,

        @FormParam("javapackage") @RestDocParam(description = "The Java package to use for IA generation") String javapackage,

        @Context UriInfo uriInfo) {
    // we assume that the parent ComponentInstance container exists

    // @formatter:on

    if (StringUtils.isEmpty(artifactNameStr)) {
        return Response.status(Status.BAD_REQUEST).entity("Empty artifactName").build();
    }
    if (StringUtils.isEmpty(artifactTypeStr)) {
        if (StringUtils.isEmpty(artifactTemplateName) || StringUtils.isEmpty(artifactTemplateNS)) {
            if (StringUtils.isEmpty(artifactTemplate)) {
                return Response.status(Status.BAD_REQUEST)
                        .entity("No artifact type given and no template given. Cannot guess artifact type")
                        .build();
            }
        }
    }

    if (!StringUtils.isEmpty(autoGenerateIA)) {
        if (StringUtils.isEmpty(javapackage)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("no java package name supplied for IA auto generation.").build();
        }
        if (StringUtils.isEmpty(interfaceNameStr)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("no interface name supplied for IA auto generation.").build();
        }
    }

    // convert second calling form to first calling form
    if (!StringUtils.isEmpty(artifactTemplate)) {
        QName qname = QName.valueOf(artifactTemplate);
        artifactTemplateName = qname.getLocalPart();
        artifactTemplateNS = qname.getNamespaceURI();
    }

    Document doc = null;

    // check artifact specific content for validity
    // if invalid, abort and do not create anything
    if (!StringUtils.isEmpty(artifactSpecificContent)) {
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            InputSource is = new InputSource();
            StringReader sr = new StringReader(artifactSpecificContent);
            is.setCharacterStream(sr);
            doc = db.parse(is);
        } catch (Exception e) {
            // FIXME: currently we allow a single element only. However, the content should be internally wrapped by an (arbitrary) XML element as the content will be nested in the artifact element, too
            GenericArtifactsResource.logger.debug("Invalid content", e);
            return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
        }
    }

    // determine artifactTemplate and artifactType

    ArtifactTypeId artifactTypeId;
    ArtifactTemplateId artifactTemplateId = null;
    ArtifactTemplateResource artifactTemplateResource = null;

    boolean doAutoCreateArtifactTemplate = !(StringUtils.isEmpty(autoCreateArtifactTemplate)
            || autoCreateArtifactTemplate.equalsIgnoreCase("no")
            || autoCreateArtifactTemplate.equalsIgnoreCase("false"));
    if (!doAutoCreateArtifactTemplate) {
        // no auto creation
        if (!StringUtils.isEmpty(artifactTemplateName) && !StringUtils.isEmpty(artifactTemplateNS)) {
            QName artifactTemplateQName = new QName(artifactTemplateNS, artifactTemplateName);
            artifactTemplateId = BackendUtils.getTOSCAcomponentId(ArtifactTemplateId.class,
                    artifactTemplateQName);
        }
        if (StringUtils.isEmpty(artifactTypeStr)) {
            // derive the type from the artifact template
            if (artifactTemplateId == null) {
                return Response.status(Status.NOT_ACCEPTABLE).entity(
                        "No artifactTemplate and no artifactType provided. Deriving the artifactType is not possible.")
                        .build();
            }
            artifactTemplateResource = new ArtifactTemplateResource(artifactTemplateId);
            artifactTypeId = BackendUtils.getTOSCAcomponentId(ArtifactTypeId.class,
                    artifactTemplateResource.getType());
        } else {
            // artifactTypeStr is directly given, use that
            artifactTypeId = BackendUtils.getTOSCAcomponentId(ArtifactTypeId.class, artifactTypeStr);
        }
    } else {
        // do the artifact template auto creation magic

        if (StringUtils.isEmpty(artifactTypeStr)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("Artifact template auto creation requested, but no artifact type supplied.")
                    .build();
        }

        // we assume that the type points to a valid artifact type
        artifactTypeId = BackendUtils.getTOSCAcomponentId(ArtifactTypeId.class, artifactTypeStr);

        if (StringUtils.isEmpty(artifactTemplateName) || StringUtils.isEmpty(artifactTemplateNS)) {
            // no explicit name provided
            // we use the artifactNameStr as prefix for the
            // artifact template name

            // we create a new artifact template in the namespace of the parent
            // element
            Namespace namespace = this.resWithNamespace.getNamespace();

            artifactTemplateId = new ArtifactTemplateId(namespace,
                    new XMLId(artifactNameStr + "artifactTemplate", false));
        } else {
            QName artifactTemplateQName = new QName(artifactTemplateNS, artifactTemplateName);
            artifactTemplateId = new ArtifactTemplateId(artifactTemplateQName);
        }
        ResourceCreationResult creationResult = BackendUtils.create(artifactTemplateId);
        if (!creationResult.isSuccess()) {
            // something went wrong. skip
            return creationResult.getResponse();
        }

        // associate the type to the created artifact template
        artifactTemplateResource = new ArtifactTemplateResource(artifactTemplateId);
        // set the type. The resource is automatically persisted inside
        artifactTemplateResource.setType(artifactTypeStr);
    }

    // variable artifactTypeId is set
    // variable artifactTemplateId is not null if artifactTemplate has been generated

    // we have to generate the DA/IA resource now
    // Doing it here instead of doing it at the subclasses is dirty on the
    // one hand, but quicker to implement on the other hand

    // Create the artifact itself

    ArtifactT resultingArtifact;

    if (this instanceof ImplementationArtifactsResource) {
        ImplementationArtifact a = new ImplementationArtifact();
        // Winery internal id is the name of the artifact:
        // store the name
        a.setName(artifactNameStr);
        a.setInterfaceName(interfaceNameStr);
        a.setOperationName(operationNameStr);
        assert (artifactTypeId != null);
        a.setArtifactType(artifactTypeId.getQName());
        if (artifactTemplateId != null) {
            a.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            // the content has been checked for validity at the beginning of the method.
            // If this point in the code is reached, the XML has been parsed into doc
            // just copy over the dom node. Hopefully, that works...
            a.getAny().add(doc.getDocumentElement());
        }

        this.list.add((ArtifactT) a);
        resultingArtifact = (ArtifactT) a;
    } else {
        // for comments see other branch

        TDeploymentArtifact a = new TDeploymentArtifact();
        a.setName(artifactNameStr);
        assert (artifactTypeId != null);
        a.setArtifactType(artifactTypeId.getQName());
        if (artifactTemplateId != null) {
            a.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            a.getAny().add(doc.getDocumentElement());
        }

        this.list.add((ArtifactT) a);
        resultingArtifact = (ArtifactT) a;
    }

    Response persistResponse = BackendUtils.persist(super.res);
    // TODO: check for error and in case one found return that

    if (StringUtils.isEmpty(autoGenerateIA)) {
        // no IA generation
        // we include an XML for the data table

        String implOrDeplArtifactXML = Utils.getXMLAsString(resultingArtifact);

        return Response.created(Utils.createURI(Util.URLencode(artifactNameStr))).entity(implOrDeplArtifactXML)
                .build();
    } else {
        // after everything was created, we fire up the artifact generation
        return this.generateImplementationArtifact(interfaceNameStr, javapackage, uriInfo, artifactTemplateId,
                artifactTemplateResource);
    }
}

From source file:org.eclipse.winery.repository.rest.resources.AbstractComponentsResource.java

/**
 * @return an instance of the requested resource
 *//*from w  w w.j  a  v a  2s  .co m*/
public R getComponentInstaceResource(QName qname) {
    return this.getComponentInstaceResource(qname.getNamespaceURI(), qname.getLocalPart(), false);
}

From source file:org.eclipse.winery.repository.rest.resources.API.APIResource.java

@GET
@Path("getallartifacttemplatesofcontaineddeploymentartifacts")
@Produces(MediaType.APPLICATION_JSON)//from w ww .  ja v  a2s .  co  m
public Response getAllArtifactTemplatesOfContainedDeploymentArtifacts(
        @QueryParam("servicetemplate") String serviceTemplateQNameString,
        @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter")
                .build();
    }

    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);

    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!RepositoryFactory.getRepository().exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);

    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils
            .getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils
                    .getArtifactTemplatesOfReferencedDeploymentArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }

    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}

From source file:org.eclipse.winery.repository.rest.resources.API.APIResource.java

/**
 * Implementation similar to/*from ww  w  .j  av a2s . c  om*/
 * getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
 * "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
 * "getArtifactTemplatesOfReferencedDeploymentArtifacts".
 */
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(
        @QueryParam("servicetemplate") String serviceTemplateQNameString,
        @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter")
                .build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);

    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!RepositoryFactory.getRepository().exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);

    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils
            .getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils
                    .getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }

    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}

From source file:org.eclipse.winery.repository.rest.resources.artifacts.GenericArtifactsResource.java

/**
 * @return TImplementationArtifact | TDeploymentArtifact (XML) | URL of generated IA zip (in case of autoGenerateIA)
 */// www  . jav  a  2 s .co  m
@POST
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a new implementation/deployment artifact. If an implementation artifact with the same name already exists, it is <em>overridden</em>.")
@SuppressWarnings("unchecked")
public Response generateArtifact(GenerateArtifactApiData apiData, @Context UriInfo uriInfo) {
    // we assume that the parent ComponentInstance container exists

    final IRepository repository = RepositoryFactory.getRepository();

    if (StringUtils.isEmpty(apiData.artifactName)) {
        return Response.status(Status.BAD_REQUEST).entity("Empty artifactName").build();
    }
    if (StringUtils.isEmpty(apiData.artifactType)) {
        if (StringUtils.isEmpty(apiData.artifactTemplateName)
                || StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            if (StringUtils.isEmpty(apiData.artifactTemplate)) {
                return Response.status(Status.BAD_REQUEST)
                        .entity("No artifact type given and no template given. Cannot guess artifact type")
                        .build();
            }
        }
    }

    if (!StringUtils.isEmpty(apiData.autoGenerateIA)) {
        if (StringUtils.isEmpty(apiData.javaPackage)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("no java package name supplied for IA auto generation.").build();
        }
        if (StringUtils.isEmpty(apiData.interfaceName)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("no interface name supplied for IA auto generation.").build();
        }
    }

    // convert second calling form to first calling form
    if (!StringUtils.isEmpty(apiData.artifactTemplate)) {
        QName qname = QName.valueOf(apiData.artifactTemplate);
        apiData.artifactTemplateName = qname.getLocalPart();
        apiData.artifactTemplateNamespace = qname.getNamespaceURI();
    }

    Document doc = null;

    // check artifact specific content for validity
    // if invalid, abort and do not create anything
    if (!StringUtils.isEmpty(apiData.artifactSpecificContent)) {
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            InputSource is = new InputSource();
            StringReader sr = new StringReader(apiData.artifactSpecificContent);
            is.setCharacterStream(sr);
            doc = db.parse(is);
        } catch (Exception e) {
            // FIXME: currently we allow a single element only. However, the content should be internally wrapped by an (arbitrary) XML element as the content will be nested in the artifact element, too
            GenericArtifactsResource.LOGGER.debug("Invalid content", e);
            return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
        }
    }

    // determine artifactTemplate and artifactType

    ArtifactTypeId artifactTypeId;
    ArtifactTemplateId artifactTemplateId = null;
    ArtifactTemplateResource artifactTemplateResource = null;

    boolean doAutoCreateArtifactTemplate = !(StringUtils.isEmpty(apiData.autoCreateArtifactTemplate)
            || apiData.autoCreateArtifactTemplate.equalsIgnoreCase("no")
            || apiData.autoCreateArtifactTemplate.equalsIgnoreCase("false"));
    if (!doAutoCreateArtifactTemplate) {
        // no auto creation
        if (!StringUtils.isEmpty(apiData.artifactTemplateName)
                && !StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            QName artifactTemplateQName = new QName(apiData.artifactTemplateNamespace,
                    apiData.artifactTemplateName);
            artifactTemplateId = BackendUtils.getDefinitionsChildId(ArtifactTemplateId.class,
                    artifactTemplateQName);
        }
        if (StringUtils.isEmpty(apiData.artifactType)) {
            // derive the type from the artifact template
            if (artifactTemplateId == null) {
                return Response.status(Status.NOT_ACCEPTABLE).entity(
                        "No artifactTemplate and no artifactType provided. Deriving the artifactType is not possible.")
                        .build();
            }
            @NonNull
            final QName type = repository.getElement(artifactTemplateId).getType();
            artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, type);
        } else {
            // artifactTypeStr is directly given, use that
            artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, apiData.artifactType);
        }
    } else {
        // do the artifact template auto creation magic

        if (StringUtils.isEmpty(apiData.artifactType)) {
            return Response.status(Status.BAD_REQUEST)
                    .entity("Artifact template auto creation requested, but no artifact type supplied.")
                    .build();
        }

        artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, apiData.artifactType);
        // ensure that given type exists
        if (!repository.exists(artifactTypeId)) {
            LOGGER.debug("Artifact type {} is created", apiData.artifactType);
            final TArtifactType element = repository.getElement(artifactTypeId);
            try {
                repository.setElement(artifactTypeId, element);
            } catch (IOException e) {
                throw new WebApplicationException(e);
            }
        }

        if (StringUtils.isEmpty(apiData.artifactTemplateName)
                || StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            // no explicit name provided
            // we use the artifactNameStr as prefix for the
            // artifact template name

            // we create a new artifact template in the namespace of the parent
            // element
            Namespace namespace = this.resWithNamespace.getNamespace();

            artifactTemplateId = new ArtifactTemplateId(namespace,
                    new XmlId(apiData.artifactName + "artifactTemplate", false));
        } else {
            QName artifactTemplateQName = new QName(apiData.artifactTemplateNamespace,
                    apiData.artifactTemplateName);
            artifactTemplateId = new ArtifactTemplateId(artifactTemplateQName);
        }

        // even if artifactTemplate does not exist, it is loaded
        final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
        artifactTemplate.setType(artifactTypeId.getQName());
        try {
            repository.setElement(artifactTemplateId, artifactTemplate);
        } catch (IOException e) {
            throw new WebApplicationException(e);
        }
    }

    // variable artifactTypeId is set
    // variable artifactTemplateId is not null if artifactTemplate has been generated

    // we have to generate the DA/IA resource now
    // Doing it here instead of doing it at the subclasses is dirty on the
    // one hand, but quicker to implement on the other hand

    // Create the artifact itself

    ArtifactT resultingArtifact;

    if (this instanceof ImplementationArtifactsResource) {
        ImplementationArtifact a = new ImplementationArtifact();
        // Winery internal id is the name of the artifact:
        // store the name
        a.setName(apiData.artifactName);
        a.setInterfaceName(apiData.interfaceName);
        a.setOperationName(apiData.operationName);
        assert (artifactTypeId != null);
        a.setArtifactType(artifactTypeId.getQName());
        if (artifactTemplateId != null) {
            a.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            // the content has been checked for validity at the beginning of the method.
            // If this point in the code is reached, the XML has been parsed into doc
            // just copy over the dom node. Hopefully, that works...
            a.getAny().add(doc.getDocumentElement());
        }

        this.list.add((ArtifactT) a);
        resultingArtifact = (ArtifactT) a;
    } else {
        // for comments see other branch

        TDeploymentArtifact a = new TDeploymentArtifact();
        a.setName(apiData.artifactName);
        assert (artifactTypeId != null);
        a.setArtifactType(artifactTypeId.getQName());
        if (artifactTemplateId != null) {
            a.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            a.getAny().add(doc.getDocumentElement());
        }

        this.list.add((ArtifactT) a);
        resultingArtifact = (ArtifactT) a;
    }

    // TODO: Check for error, and in case one found return it
    RestUtils.persist(super.res);

    if (StringUtils.isEmpty(apiData.autoGenerateIA)) {
        // No IA generation
        return Response.created(RestUtils.createURI(Util.URLencode(apiData.artifactName)))
                .entity(resultingArtifact).build();
    } else {
        // after everything was created, we fire up the artifact generation
        return this.generateImplementationArtifact(apiData.interfaceName, apiData.javaPackage, uriInfo,
                artifactTemplateId);
    }
}

From source file:org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource.java

/**
 * @return an instance of the requested resource
 *//*from  w ww  . j av  a 2s  .  co m*/
public R getComponentInstanceResource(QName qname) {
    return this.getComponentInstanceResource(qname.getNamespaceURI(), qname.getLocalPart(), false);
}

From source file:org.emonocot.job.io.StaxEventItemReader.java

/**
 * Responsible for moving the cursor before the StartElement of the fragment
 * root.// w  w  w  . j  a va  2  s  . c o m
 *
 * This implementation simply looks for the next corresponding element, it
 * does not care about element nesting. You will need to override this
 * method to correctly handle composite fragments.
 * @param xmlEventReader Set the XML event reader
 * @return <code>true</code> if next fragment was found, <code>false</code>
 *         otherwise.
 */
protected final boolean moveCursorToNextFragment(final XMLEventReader xmlEventReader) {
    try {
        while (true) {
            while (xmlEventReader.peek() != null && !xmlEventReader.peek().isStartElement()) {
                xmlEventReader.nextEvent();
            }
            if (xmlEventReader.peek() == null) {
                return false;
            }
            QName startElementName = ((StartElement) xmlEventReader.peek()).getName();
            if (startElementName.getLocalPart().equals(fragmentRootElementName)) {
                if (fragmentRootElementNameSpace == null
                        || startElementName.getNamespaceURI().equals(fragmentRootElementNameSpace)) {
                    return true;
                }
            }
            xmlEventReader.nextEvent();

        }
    } catch (XMLStreamException e) {
        throw new DataAccessResourceFailureException("Error while reading from event reader", e);
    }
}

From source file:org.enhydra.shark.asap.util.BeanSerializerShark.java

/**
 * Serialize a bean.  Done simply by serializing each bean property.
 * @param name is the element name/*from w  w w.j  a  v a 2  s. c o  m*/
 * @param attributes are the attributes...serialize is free to add more.
 * @param value is the value
 * @param context is the SerializationContext
 */
public void serialize(QName name, Attributes attributes, Object value, SerializationContext context)
        throws IOException {
    // Check for meta-data in the bean that will tell us if any of the
    // properties are actually attributes, add those to the element
    // attribute list
    Attributes beanAttrs = getObjectAttributes(value, attributes, context);

    // Get the encoding style
    String encodingStyle = context.getEncodingStyle();
    boolean isEncoded = Constants.isSOAP_ENC(encodingStyle);

    // check whether we have and xsd:any namespace="##any" type
    boolean suppressElement = !context.isEncoded() && name.getNamespaceURI().equals("")
            && name.getLocalPart().equals("any");

    boolean grpElement = name.toString().endsWith("Group");
    suppressElement |= grpElement;

    if (!suppressElement)
        context.startElement(name, beanAttrs);

    try {
        // Serialize each property
        for (int i = 0; i < propertyDescriptor.length; i++) {
            String propName = propertyDescriptor[i].getName();
            if (propName.equals("class"))
                continue;
            QName qname = null;
            QName xmlType = null;
            boolean isOmittable = false;

            // If we have type metadata, check to see what we're doing
            // with this field.  If it's an attribute, skip it.  If it's
            // an element, use whatever qname is in there.  If we can't
            // find any of this info, use the default.

            if (typeDesc != null) {
                FieldDesc field = typeDesc.getFieldByName(propName);
                if (field != null) {
                    if (!field.isElement())
                        continue;

                    // If we're SOAP encoded, just use the local part,
                    // not the namespace.  Otherwise use the whole
                    // QName.
                    if (isEncoded) {
                        qname = new QName(field.getXmlName().getLocalPart());
                    } else {
                        qname = field.getXmlName();
                    }
                    isOmittable = field.isMinOccursZero();
                    xmlType = field.getXmlType();
                }
            }

            if (qname == null) {
                qname = new QName(isEncoded ? "" : name.getNamespaceURI(), propName);
            }

            if (xmlType == null) {
                // look up the type QName using the class
                xmlType = context.getQNameForClass(propertyDescriptor[i].getType());
            }

            // Read the value from the property
            if (propertyDescriptor[i].isReadable()) {
                if (!propertyDescriptor[i].isIndexed()) {
                    // Normal case: serialize the value
                    Object propValue = propertyDescriptor[i].get(value);
                    // if meta data says minOccurs=0, then we can skip
                    // it if its value is null and we aren't doing SOAP
                    // encoding.
                    if (propValue == null && isOmittable && !isEncoded)
                        continue;

                    if (null == propValue && qname.toString().endsWith("Group")) {
                        System.err.println("\telemQName:" + qname + " contains 'Group' not appending nil");
                        continue;
                    }
                    context.serialize(qname, null, propValue, xmlType, true, null);
                } else {
                    // Collection of properties: serialize each one
                    int j = 0;
                    while (j >= 0) {
                        Object propValue = null;
                        try {
                            propValue = propertyDescriptor[i].get(value, j);
                            j++;
                        } catch (Exception e) {
                            j = -1;
                        }
                        if (j >= 0) {
                            context.serialize(qname, null, propValue, xmlType, true, null);
                        }
                    }
                }
            }
        }

        BeanPropertyDescriptor anyDesc = typeDesc == null ? null : typeDesc.getAnyDesc();
        if (anyDesc != null) {
            // If we have "extra" content here, it'll be an array
            // of MessageElements.  Serialize each one.
            Object anyVal = anyDesc.get(value);
            if (anyVal != null && anyVal instanceof MessageElement[]) {
                MessageElement[] anyContent = (MessageElement[]) anyVal;
                for (int i = 0; i < anyContent.length; i++) {
                    MessageElement element = anyContent[i];
                    element.output(context);
                }
            }
        }
    } catch (InvocationTargetException ite) {
        Throwable target = ite.getTargetException();
        log.error(Messages.getMessage("exception00"), target);
        throw new IOException(target.toString());
    } catch (Exception e) {
        log.error(Messages.getMessage("exception00"), e);
        throw new IOException(e.toString());
    }

    if (!suppressElement)
        context.endElement();
}

From source file:org.enhydra.shark.asap.util.BeanSerializerShark.java

/**
 * write a schema representation of the given Class field and append it to
 * the where Node, recurse on complex types
 * @param fieldName name of the field//from   w w  w  . ja v  a  2s. c o  m
 * @param xmlType the schema type of the field
 * @param fieldType type of the field
 * @param isUnbounded causes maxOccurs="unbounded" if set
 * @param where location for the generated schema node
 * @throws Exception
 */
protected void writeField(Types types, String fieldName, QName xmlType, Class fieldType, boolean isUnbounded,
        boolean isOmittable, Element where, boolean isAnonymous) throws Exception {
    Element elem;
    if (isAnonymous) {
        elem = types.createElementWithAnonymousType(fieldName, fieldType, isOmittable,
                where.getOwnerDocument());
    } else {
        if (!SchemaUtils.isSimpleSchemaType(xmlType) && Types.isArray(fieldType)) {
            xmlType = null;
        }

        String elementType = types.writeType(fieldType, xmlType);

        if (elementType == null) {
            // If writeType returns null, then emit an anytype in such situations.
            QName anyQN = Constants.XSD_ANYTYPE;
            String prefix = types.getNamespaces().getCreatePrefix(anyQN.getNamespaceURI());
            elementType = prefix + ":" + anyQN.getLocalPart();
        }

        elem = types.createElement(fieldName, elementType, types.isNullable(fieldType), isOmittable,
                where.getOwnerDocument());
    }

    if (isUnbounded) {
        elem.setAttribute("maxOccurs", "unbounded");
    }

    where.appendChild(elem);
}