List of usage examples for javax.xml.namespace QName toString
public String toString()
From source file:org.eclipse.winery.repository.resources.API.APIResource.java
@GET @Path("getallartifacttemplatesofcontaineddeploymentartifacts") @Produces(MediaType.APPLICATION_JSON)//from w ww . ja v a2s . c o 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 (!Repository.INSTANCE.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.resources.API.APIResource.java
/** * Implementation similar to getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only * difference is "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of * "getArtifactTemplatesOfReferencedDeploymentArtifacts". *///from ww w . ja va 2 s . c om @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 (!Repository.INSTANCE.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.API.APIResource.java
@GET @Path("getallartifacttemplatesofcontaineddeploymentartifacts") @Produces(MediaType.APPLICATION_JSON)/*from www. ja va2 s . c o 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/* w w w. j ava 2 s . co m*/ * 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.RestUtils.java
public static ArtifactTemplateId createArtifactTemplate(InputStream uploadedInputStream, FormDataContentDisposition fileDetail, FormDataBodyPart body, QName artifactType, UriInfo uriInfo) { ArtifactTemplatesResource templateResource = new ArtifactTemplatesResource(); QNameWithTypeApiData qNameApiData = new QNameWithTypeApiData(); qNameApiData.localname = "xaasPackager_" + fileDetail.getFileName(); qNameApiData.namespace = "http://opentosca.org/xaaspackager"; qNameApiData.type = artifactType.toString(); templateResource.onJsonPost(qNameApiData); ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://opentosca.org/xaaspackager", "xaasPackager_" + fileDetail.getFileName(), false); ArtifactTemplateResource atRes = new ArtifactTemplateResource(artifactTemplateId); atRes.getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo); return artifactTemplateId; }
From source file:org.enhydra.shark.asap.util.BeanDeserializerShark.java
/** * Deserializer interface called on each child element encountered in * the XML stream./* ww w .jav a2s .com*/ * @param namespace is the namespace of the child element * @param localName is the local name of the child element * @param prefix is the prefix used on the name of the child element * @param attributes are the attributes of the child element * @param context is the deserialization context. * @return is a Deserializer to use to deserialize a child (must be * a derived class of SOAPHandler) or null if no deserialization should * be performed. */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { //System.err.println("onStartChild namespace:"+namespace); //System.err.println("onStartChild localName:"+localName); //System.err.println("onStartChild prefix :"+prefix); if (xmlType.toString().endsWith("GetPropertiesRs") || xmlType.toString().endsWith("SetPropertiesRs")) { //new Throwable("onStartChild namespace:"+namespace // + "\nonStartChild localName:"+localName // + "\nonStartChild prefix :"+prefix).printStackTrace(); int failures = 0; SOAPHandler sHnd = null; for (int n = 0; n < 3; ++n) { try { if (alreadyFailed[n]) { ++failures; continue; } sHnd = additional[n].onStartChild(namespace, localName, prefix, attributes, context); } catch (Throwable t) { //t.printStackTrace(); alreadyFailed[n] = true; ++failures; } } if (3 == failures) throw new SAXException(Messages.getMessage("cantCreateBean00", _addLocalNames[0], "")); return sHnd; } handleMixedContent(); BeanPropertyDescriptor propDesc = null; FieldDesc fieldDesc = null; SOAPConstants soapConstants = context.getSOAPConstants(); String encodingStyle = context.getMessageContext().getEncodingStyle(); boolean isEncoded = Constants.isSOAP_ENC(encodingStyle); QName elemQName = new QName(namespace, localName); // The collectionIndex needs to be reset for Beans with multiple arrays if ((prevQName == null) || (!prevQName.equals(elemQName))) { collectionIndex = -1; } prevQName = elemQName; if (typeDesc != null) { // Lookup the name appropriately (assuming an unqualified // name for SOAP encoding, using the namespace otherwise) String fieldName = typeDesc.getFieldNameForElement(elemQName, isEncoded); propDesc = (BeanPropertyDescriptor) propertyMap.get(fieldName); fieldDesc = typeDesc.getFieldByName(fieldName); } if (propDesc == null) { // look for a field by this name. propDesc = (BeanPropertyDescriptor) propertyMap.get(localName); } // try and see if this is an xsd:any namespace="##any" element before // reporting a problem if (propDesc == null) { // try to put unknown elements into a SOAPElement property, if // appropriate propDesc = getAnyPropertyDesc(); if (propDesc != null) { try { MessageElement[] curElements = (MessageElement[]) propDesc.get(value); int length = 0; if (curElements != null) { length = curElements.length; } MessageElement[] newElements = new MessageElement[length + 1]; if (curElements != null) { System.arraycopy(curElements, 0, newElements, 0, length); } MessageElement thisEl = context.getCurElement(); newElements[length] = thisEl; propDesc.set(value, newElements); // if this is the first pass through the MessageContexts // make sure that the correct any element is set, // that is the child of the current MessageElement, however // on the first pass this child has not been set yet, so // defer it to the child SOAPHandler if (!localName.equals(thisEl.getName())) { return new SOAPHandler(newElements, length); } return new SOAPHandler(); } catch (Exception e) { throw new SAXException(e); } } } if (propDesc == null) { // No such field throw new SAXException(Messages.getMessage("badElem00", javaType.getName(), localName)); } // Get the child's xsi:type if available QName childXMLType = context.getTypeFromAttributes(namespace, localName, attributes); String href = attributes.getValue(soapConstants.getAttrHref()); // If no xsi:type or href, check the meta-data for the field if (childXMLType == null && fieldDesc != null && href == null) { childXMLType = fieldDesc.getXmlType(); } // Get Deserializer for child, default to using DeserializerImpl Deserializer dSer = getDeserializer(childXMLType, propDesc.getType(), href, context); // It is an error if the dSer is not found - the only case where we // wouldn't have a deserializer at this point is when we're trying // to deserialize something we have no clue about (no good xsi:type, // no good metadata). if (dSer == null) { dSer = context.getDeserializerForClass(propDesc.getType()); } // Fastpath nil checks... if (context.isNil(attributes)) { if (propDesc != null && propDesc.isIndexed()) { if (!((dSer != null) && (dSer instanceof ArrayDeserializer)) || propDesc.getType().isArray()) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); addChildDeserializer(dSer); return (SOAPHandler) dSer; } } return null; } if (dSer == null) { throw new SAXException(Messages.getMessage("noDeser00", childXMLType.toString())); } // Register value target if (propDesc.isWriteable()) { // If this is an indexed property, and the deserializer we found // was NOT the ArrayDeserializer, this is a non-SOAP array: // <bean> // <field>value1</field> // <field>value2</field> // ... // In this case, we want to use the collectionIndex and make sure // the deserialized value for the child element goes into the // right place in the collection. if (propDesc.isIndexed() && (!(dSer instanceof ArrayDeserializer) || propDesc.getType().isArray())) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); } else { // If we're here, the element maps to a single field value, // whether that be a "basic" type or an array, so use the // normal (non-indexed) BeanPropertyTarget form. collectionIndex = -1; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc)); } } // Let the framework know that we need this deserializer to complete // for the bean to complete. addChildDeserializer(dSer); return (SOAPHandler) dSer; }
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//ww w .j av a 2s . 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.wfxml.util.BeanDeserializerShark.java
/** * Deserializer interface called on each child element encountered in * the XML stream.//from w w w .j a va 2 s . c o m * @param namespace is the namespace of the child element * @param localName is the local name of the child element * @param prefix is the prefix used on the name of the child element * @param attributes are the attributes of the child element * @param context is the deserialization context. * @return is a Deserializer to use to deserialize a child (must be * a derived class of SOAPHandler) or null if no deserialization should * be performed. */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { //System.err.println("onStartChild namespace:"+namespace); //System.err.println("onStartChild localName:"+localName); //System.err.println("onStartChild prefix :"+prefix); if (xmlType.toString().endsWith("GetPropertiesRs") || xmlType.toString().endsWith("SetPropertiesRs")) { //new Throwable("onStartChild namespace:"+namespace // + "\nonStartChild localName:"+localName // + "\nonStartChild prefix :"+prefix).printStackTrace(); int failures = 0; SOAPHandler sHnd = null; for (int n = 0; n < additional.length; ++n) { try { if (alreadyFailed[n]) { ++failures; continue; } sHnd = additional[n].onStartChild(namespace, localName, prefix, attributes, context); } catch (Throwable t) { //t.printStackTrace(); alreadyFailed[n] = true; ++failures; } } if (additional.length == failures) throw new SAXException(Messages.getMessage("cantCreateBean00", _addLocalNames[0], "")); return sHnd; } handleMixedContent(); BeanPropertyDescriptor propDesc = null; FieldDesc fieldDesc = null; SOAPConstants soapConstants = context.getSOAPConstants(); String encodingStyle = context.getMessageContext().getEncodingStyle(); boolean isEncoded = Constants.isSOAP_ENC(encodingStyle); QName elemQName = new QName(namespace, localName); // The collectionIndex needs to be reset for Beans with multiple arrays if ((prevQName == null) || (!prevQName.equals(elemQName))) { collectionIndex = -1; } prevQName = elemQName; if (typeDesc != null) { // Lookup the name appropriately (assuming an unqualified // name for SOAP encoding, using the namespace otherwise) String fieldName = typeDesc.getFieldNameForElement(elemQName, isEncoded); propDesc = (BeanPropertyDescriptor) propertyMap.get(fieldName); fieldDesc = typeDesc.getFieldByName(fieldName); } if (propDesc == null) { // look for a field by this name. propDesc = (BeanPropertyDescriptor) propertyMap.get(localName); } // try and see if this is an xsd:any namespace="##any" element before // reporting a problem if (propDesc == null) { // try to put unknown elements into a SOAPElement property, if // appropriate propDesc = getAnyPropertyDesc(); if (propDesc != null) { try { MessageElement[] curElements = (MessageElement[]) propDesc.get(value); int length = 0; if (curElements != null) { length = curElements.length; } MessageElement[] newElements = new MessageElement[length + 1]; if (curElements != null) { System.arraycopy(curElements, 0, newElements, 0, length); } MessageElement thisEl = context.getCurElement(); newElements[length] = thisEl; propDesc.set(value, newElements); // if this is the first pass through the MessageContexts // make sure that the correct any element is set, // that is the child of the current MessageElement, however // on the first pass this child has not been set yet, so // defer it to the child SOAPHandler if (!localName.equals(thisEl.getName())) { return new SOAPHandler(newElements, length); } return new SOAPHandler(); } catch (Exception e) { throw new SAXException(e); } } } if (propDesc == null) { // No such field throw new SAXException(Messages.getMessage("badElem00", javaType.getName(), localName)); } // Get the child's xsi:type if available QName childXMLType = context.getTypeFromAttributes(namespace, localName, attributes); String href = attributes.getValue(soapConstants.getAttrHref()); // If no xsi:type or href, check the meta-data for the field if (childXMLType == null && fieldDesc != null && href == null) { childXMLType = fieldDesc.getXmlType(); } // Get Deserializer for child, default to using DeserializerImpl Deserializer dSer = getDeserializer(childXMLType, propDesc.getType(), href, context); // It is an error if the dSer is not found - the only case where we // wouldn't have a deserializer at this point is when we're trying // to deserialize something we have no clue about (no good xsi:type, // no good metadata). if (dSer == null) { dSer = context.getDeserializerForClass(propDesc.getType()); } // Fastpath nil checks... if (context.isNil(attributes)) { if (propDesc != null && propDesc.isIndexed()) { if (!((dSer != null) && (dSer instanceof ArrayDeserializer)) || propDesc.getType().isArray()) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); addChildDeserializer(dSer); return (SOAPHandler) dSer; } } return null; } if (dSer == null) { throw new SAXException(Messages.getMessage("noDeser00", childXMLType.toString())); } // Register value target if (propDesc.isWriteable()) { // If this is an indexed property, and the deserializer we found // was NOT the ArrayDeserializer, this is a non-SOAP array: // <bean> // <field>value1</field> // <field>value2</field> // ... // In this case, we want to use the collectionIndex and make sure // the deserialized value for the child element goes into the // right place in the collection. if (propDesc.isIndexed() && (!(dSer instanceof ArrayDeserializer) || propDesc.getType().isArray())) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); } else { // If we're here, the element maps to a single field value, // whether that be a "basic" type or an array, so use the // normal (non-indexed) BeanPropertyTarget form. collectionIndex = -1; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc)); } } // Let the framework know that we need this deserializer to complete // for the bean to complete. addChildDeserializer(dSer); return (SOAPHandler) dSer; }
From source file:org.enhydra.shark.wfxml.util.BeanSerializerShark.java
/** * Serialize a bean. Done simply by serializing each bean property. * @param name is the element name/* w w w .ja v a 2s . co 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 (isEmptyObjectType(name)) { context.setWriteXMLType(null); } if (!suppressElement) context.startElement(name, beanAttrs); if (!isEmptyObjectType(name)) { 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.fireflow.pdl.fpdl.io.FPDLSerializer.java
protected void writeProperties(List<Property> dataFields, Element parent) throws SerializerException { if (dataFields == null || dataFields.size() == 0) { return;/* ww w . j a va 2 s.c o m*/ } Element dataFieldsElement = Util4Serializer.addElement(parent, PROPERTIES); Iterator<Property> iter = dataFields.iterator(); while (iter.hasNext()) { Property dataField = iter.next(); Element dataFieldElement = Util4Serializer.addElement(dataFieldsElement, PROPERTY); dataFieldElement.setAttribute(ID, dataField.getId()); dataFieldElement.setAttribute(NAME, dataField.getName()); dataFieldElement.setAttribute(DISPLAY_NAME, dataField.getDisplayName()); QName dataType = dataField.getDataType(); if (dataType == null) {//?java.lang.String dataType = new QName(NameSpaces.JAVA.getUri(), "java.lang.String"); } dataFieldElement.setAttribute(DATA_TYPE, dataType.toString()); dataFieldElement.setAttribute(INIT_VALUE, dataField.getInitialValueAsString()); this.writeDescription(dataFieldElement, dataField.getDescription()); } }