List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:org.apache.axis.AxisFault.java
/** * Find a fault detail element by its qname. * @param qname name of the node to look for * @return the matching element or null/* w w w. j a v a 2 s .co m*/ * @since axis1.1 */ public Element lookupFaultDetail(QName qname) { if (faultDetails != null) { //extract details from the qname. the empty namespace is represented //by the empty string String searchNamespace = qname.getNamespaceURI(); String searchLocalpart = qname.getLocalPart(); //now spin through the elements, seeking a match Iterator it = faultDetails.iterator(); while (it.hasNext()) { Element e = (Element) it.next(); String localpart = e.getLocalName(); if (localpart == null) { localpart = e.getNodeName(); } String namespace = e.getNamespaceURI(); if (namespace == null) { namespace = ""; } //we match on matching namespace and local part; empty namespace //in an element may be null, which matches QName's "" if (searchNamespace.equals(namespace) && searchLocalpart.equals(localpart)) { return e; } } } return null; }
From source file:org.apache.axis.client.Call.java
/** * Adds the specified parameter to the list of parameters for the * operation associated with this Call object. * * * Note: Not part of JAX-RPC specification. * * @param paramName Name that will be used for the parameter in the XML * @param xmlType XMLType of the parameter * @param javaType The Java class of the parameter * @param parameterMode one of IN, OUT or INOUT *///from w w w.ja v a 2s .co m public void addParameter(QName paramName, QName xmlType, Class javaType, ParameterMode parameterMode) { if (operationSetManually) { throw new RuntimeException(Messages.getMessage("operationAlreadySet")); } if (operation == null) operation = new OperationDesc(); ParameterDesc param = new ParameterDesc(); byte mode = ParameterDesc.IN; if (parameterMode == ParameterMode.INOUT) { mode = ParameterDesc.INOUT; param.setIsReturn(true); } else if (parameterMode == ParameterMode.OUT) { mode = ParameterDesc.OUT; param.setIsReturn(true); } param.setMode(mode); param.setQName(new QName(paramName.getNamespaceURI(), Utils.getLastLocalPart(paramName.getLocalPart()))); param.setTypeQName(xmlType); param.setJavaType(javaType); operation.addParameter(param); parmAndRetReq = true; }
From source file:org.apache.axis.client.Call.java
/** //from www. j a va 2 s. c o m * Adds a parameter type as a soap:header. * @param paramName - Name of the parameter * @param xmlType - XML datatype of the parameter * @param javaType - The Java class of the parameter * @param parameterMode - Mode of the parameter-whether IN, OUT or INOUT * @param headerMode - Mode of the header. Even if this is an INOUT * parameter, it need not be in the header in both * directions. * @exception JAXRPCException - if isParameterAndReturnSpecRequired returns * false, then addParameter MAY throw * JAXRPCException....actually Axis allows * modification in such cases */ public void addParameterAsHeader(QName paramName, QName xmlType, Class javaType, ParameterMode parameterMode, ParameterMode headerMode) { if (operationSetManually) { throw new RuntimeException(Messages.getMessage("operationAlreadySet")); } if (operation == null) operation = new OperationDesc(); ParameterDesc param = new ParameterDesc(); param.setQName(new QName(paramName.getNamespaceURI(), Utils.getLastLocalPart(paramName.getLocalPart()))); param.setTypeQName(xmlType); param.setJavaType(javaType); if (parameterMode == ParameterMode.IN) { param.setMode(ParameterDesc.IN); } else if (parameterMode == ParameterMode.INOUT) { param.setMode(ParameterDesc.INOUT); } else if (parameterMode == ParameterMode.OUT) { param.setMode(ParameterDesc.OUT); } if (headerMode == ParameterMode.IN) { param.setInHeader(true); } else if (headerMode == ParameterMode.INOUT) { param.setInHeader(true); param.setOutHeader(true); } else if (headerMode == ParameterMode.OUT) { param.setOutHeader(true); } operation.addParameter(param); parmAndRetReq = true; }
From source file:org.apache.axis.client.Call.java
/** * Convert the list of objects into RPCParam's based on the paramNames, * paramXMLTypes and paramModes variables. If those aren't set then just * return what was passed in.// w ww.j a va 2 s . co m * * @param params Array of parameters to pass into the operation/method * @return Object[] Array of parameters to pass to invoke() */ private Object[] getParamList(Object[] params) { int numParams = 0; // If we never set-up any names... then just return what was passed in ////////////////////////////////////////////////////////////////////// if (log.isDebugEnabled()) { log.debug("operation=" + operation); if (operation != null) { log.debug("operation.getNumParams()=" + operation.getNumParams()); } } if (operation == null || operation.getNumParams() == 0) { return (params); } // Count the number of IN and INOUT params, this needs to match the // number of params passed in - if not throw an error ///////////////////////////////////////////////////////////////////// numParams = operation.getNumInParams(); if (params == null || numParams != params.length) { throw new JAXRPCException(Messages.getMessage("parmMismatch00", (params == null) ? "no params" : "" + params.length, "" + numParams)); } log.debug("getParamList number of params: " + params.length); // All ok - so now produce an array of RPCParams ////////////////////////////////////////////////// Vector result = new Vector(); int j = 0; ArrayList parameters = operation.getParameters(); for (int i = 0; i < parameters.size(); i++) { ParameterDesc param = (ParameterDesc) parameters.get(i); if (param.getMode() != ParameterDesc.OUT) { QName paramQName = param.getQName(); // Create an RPCParam if param isn't already an RPCParam. RPCParam rpcParam = null; Object p = params[j++]; if (p instanceof RPCParam) { rpcParam = (RPCParam) p; } else { rpcParam = new RPCParam(paramQName.getNamespaceURI(), paramQName.getLocalPart(), p); } // Attach the ParameterDescription to the RPCParam // so that the serializer can use the (javaType, xmlType) // information. rpcParam.setParamDesc(param); // Add the param to the header or vector depending // on whether it belongs in the header or body. if (param.isInHeader()) { addHeader(new RPCHeaderParam(rpcParam)); } else { result.add(rpcParam); } } } return (result.toArray()); }
From source file:org.apache.axis.deployment.wsdd.WSDDDeployableItem.java
private Handler getNewInstance(EngineConfiguration registry) throws ConfigurationException { QName type = getType(); if (type == null || WSDDConstants.URI_WSDD_JAVA.equals(type.getNamespaceURI())) { return makeNewInstance(registry); } else {/*from w w w .j a v a 2s . c o m*/ return registry.getHandler(type); } }
From source file:org.apache.axis.deployment.wsdd.WSDDDeployableItem.java
/** * * @return XXX//from www .j a v a 2s.c o m * @throws ClassNotFoundException XXX */ public Class getJavaClass() throws ClassNotFoundException { QName type = getType(); if (type != null && URI_WSDD_JAVA.equals(type.getNamespaceURI())) { return ClassUtils.forName(type.getLocalPart()); } return null; }
From source file:org.apache.axis.description.TypeDesc.java
/** * Get the field name associated with this QName, but only if it's * marked as an element./* w ww . j a v a 2 s . c om*/ * * If the "ignoreNS" argument is true, just compare localNames. */ public String getFieldNameForElement(QName qname, boolean ignoreNS) { // have we already computed the answer to this question? if (fieldElementMap != null) { String cached = (String) fieldElementMap.get(qname); if (cached != null) return cached; } String result = null; String localPart = qname.getLocalPart(); // check fields in this class for (int i = 0; fields != null && i < fields.length; i++) { FieldDesc field = fields[i]; if (field.isElement()) { QName xmlName = field.getXmlName(); if (localPart.equals(xmlName.getLocalPart())) { if (ignoreNS || qname.getNamespaceURI().equals(xmlName.getNamespaceURI())) { result = field.getFieldName(); break; } } } } // check superclasses if they exist // and we are allowed to look if (result == null && canSearchParents) { if (parentDesc != null) { result = parentDesc.getFieldNameForElement(qname, ignoreNS); } } // cache the answer away for quicker retrieval next time. if (result != null) { if (fieldElementMap == null) fieldElementMap = new HashMap(); fieldElementMap.put(qname, result); } return result; }
From source file:org.apache.axis.description.TypeDesc.java
/** * Get the field name associated with this QName, but only if it's * marked as an attribute.//w w w .ja v a2 s. c om */ public String getFieldNameForAttribute(QName qname) { String possibleMatch = null; for (int i = 0; fields != null && i < fields.length; i++) { FieldDesc field = fields[i]; if (!field.isElement()) { // It's an attribute, so if we have a solid match, return // its name. if (qname.equals(field.getXmlName())) { return field.getFieldName(); } // Not a solid match, but it's still possible we might match // the default (i.e. QName("", fieldName)) if (qname.getNamespaceURI().equals("") && qname.getLocalPart().equals(field.getFieldName())) { possibleMatch = field.getFieldName(); } } } if (possibleMatch == null && canSearchParents) { // check superclasses if they exist // and we are allowed to look if (parentDesc != null) { possibleMatch = parentDesc.getFieldNameForAttribute(qname); } } return possibleMatch; }
From source file:org.apache.axis.encoding.ser.ArrayDeserializer.java
/** * This method is invoked after startElement when the element requires * deserialization (i.e. the element is not an href & the value is not nil) * DeserializerImpl provides default behavior, which simply * involves obtaining a correct Deserializer and plugging its handler. * @param namespace is the namespace of the element * @param localName is the name of the element * @param prefix is the prefix of the element * @param attributes are the attrs on the element...used to get the type * @param context is the DeserializationContext *///from w w w . ja v a2s .c om public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { // Deserializing the xml array requires processing the // xsi:type= attribute, the soapenc:arrayType attribute, // and the xsi:type attributes of the individual elements. // // The xsi:type=<qName> attribute is used to determine the java // type of the array to instantiate. Axis expects it // to be set to the generic "soapenc:Array" or to // a specific qName. If the generic "soapenc:Array" // specification is used, Axis determines the array // type by examining the soapenc:arrayType attribute. // // The soapenc:arrayType=<qname><dims> is used to determine // i) the number of dimensions, // ii) the length of each dimension, // iii) the default xsi:type of each of the elements. // // If the arrayType attribute is missing, Axis assumes // a single dimension array with length equal to the number // of nested elements. In such cases, the default xsi:type of // the elements is determined using the array xsi:type. // // The xsi:type attributes of the individual elements of the // array are used to determine the java type of the element. // If the xsi:type attribute is missing for an element, the // default xsi:type value is used. if (log.isDebugEnabled()) { log.debug("Enter: ArrayDeserializer::startElement()"); } soapConstants = context.getSOAPConstants(); // Get the qname for the array type=, set it to null if // the generic type is used. QName typeQName = context.getTypeFromAttributes(namespace, localName, attributes); if (typeQName == null) { typeQName = getDefaultType(); } if (typeQName != null && Constants.equals(Constants.SOAP_ARRAY, typeQName)) { typeQName = null; } // Now get the arrayType value QName arrayTypeValue = context.getQNameFromString( Constants.getValue(attributes, Constants.URIS_SOAP_ENC, soapConstants.getAttrItemType())); // The first part of the arrayType expression is // the default item type qname. // The second part is the dimension information String dimString = null; QName innerQName = null; String innerDimString = ""; if (arrayTypeValue != null) { if (soapConstants != SOAPConstants.SOAP12_CONSTANTS) { // Doing SOAP 1.1 // Array dimension noted like this : [][x] String arrayTypeValueNamespaceURI = arrayTypeValue.getNamespaceURI(); String arrayTypeValueLocalPart = arrayTypeValue.getLocalPart(); int leftBracketIndex = arrayTypeValueLocalPart.lastIndexOf('['); int rightBracketIndex = arrayTypeValueLocalPart.lastIndexOf(']'); if (leftBracketIndex == -1 || rightBracketIndex == -1 || rightBracketIndex < leftBracketIndex) { throw new IllegalArgumentException(Messages.getMessage("badArrayType00", "" + arrayTypeValue)); } dimString = arrayTypeValueLocalPart.substring(leftBracketIndex + 1, rightBracketIndex); arrayTypeValueLocalPart = arrayTypeValueLocalPart.substring(0, leftBracketIndex); // If multi-dim array set to soapenc:Array if (arrayTypeValueLocalPart.endsWith("]")) { defaultItemType = Constants.SOAP_ARRAY; int bracket = arrayTypeValueLocalPart.indexOf("["); innerQName = new QName(arrayTypeValueNamespaceURI, arrayTypeValueLocalPart.substring(0, bracket)); innerDimString = arrayTypeValueLocalPart.substring(bracket); } else { defaultItemType = new QName(arrayTypeValueNamespaceURI, arrayTypeValueLocalPart); } } else { String arraySizeValue = attributes.getValue(soapConstants.getEncodingURI(), Constants.ATTR_ARRAY_SIZE); int leftStarIndex = arraySizeValue.lastIndexOf('*'); // Skip to num if any if (leftStarIndex != -1) { // "*" => "" if (leftStarIndex == 0 && arraySizeValue.length() == 1) { // "* *" => "" } else if (leftStarIndex == (arraySizeValue.length() - 1)) { throw new IllegalArgumentException( Messages.getMessage("badArraySize00", "" + arraySizeValue)); // "* N" => "N" } else { dimString = arraySizeValue.substring(leftStarIndex + 2); innerQName = arrayTypeValue; innerDimString = arraySizeValue.substring(0, leftStarIndex + 1); } } else { dimString = arraySizeValue; } if (innerDimString == null || innerDimString.length() == 0) { defaultItemType = arrayTypeValue; } else { defaultItemType = Constants.SOAP_ARRAY12; } } } // If no type QName and no defaultItemType qname, use xsd:anyType if (defaultItemType == null && typeQName == null) { Class destClass = context.getDestinationClass(); if (destClass != null && destClass.isArray()) { // This will get set OK down below... } else { defaultItemType = Constants.XSD_ANYTYPE; } } // Determine the class type for the array. arrayClass = null; if (typeQName != null) { arrayClass = context.getTypeMapping().getClassForQName(typeQName); } if (typeQName == null || arrayClass == null) { // type= information is not sufficient. // Get an array of the default item type. Class arrayItemClass = null; QName compQName = defaultItemType; // Nested array, use the innermost qname String dims = "[]"; if (innerQName != null) { compQName = innerQName; if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { // With SOAP 1.2 Array, we append [] for each * found int offset = 0; while ((offset = innerDimString.indexOf('*', offset)) != -1) { dims += "[]"; offset++; } } else { // With SOAP 1.1 Array, we can append directly the complete innerDimString dims += innerDimString; } } // item Class arrayItemClass = context.getTypeMapping().getClassForQName(compQName); if (arrayItemClass != null) { try { // Append the dimension found to the classname computed from the itemClass // to form the array classname // String loadableArrayClassName = JavaUtils .getLoadableClassName(JavaUtils.getTextClassName(arrayItemClass.getName()) + dims); arrayClass = ClassUtils.forName(loadableArrayClassName, true, arrayItemClass.getClassLoader()); } catch (Exception e) { throw new SAXException(Messages.getMessage("noComponent00", "" + defaultItemType)); } } } if (arrayClass == null) { arrayClass = context.getDestinationClass(); } if (arrayClass == null) { throw new SAXException(Messages.getMessage("noComponent00", "" + defaultItemType)); } if (dimString == null || dimString.length() == 0) { // Size determined using length of the members value = new ArrayListExtension(arrayClass); } else { try { StringTokenizer tokenizer; if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { tokenizer = new StringTokenizer(dimString); } else { tokenizer = new StringTokenizer(dimString, "[],"); } length = Integer.parseInt(tokenizer.nextToken()); if (tokenizer.hasMoreTokens()) { // If the array is passed as a multi-dimensional array // (i.e. int[2][3]) then store all of the // mult-dim lengths. // The valueReady method uses this array to set the // proper mult-dim element. mDimLength = new ArrayList(); mDimLength.add(new Integer(length)); while (tokenizer.hasMoreTokens()) { mDimLength.add(new Integer(Integer.parseInt(tokenizer.nextToken()))); } } // Create an ArrayListExtension class to store the ArrayList // plus converted objects. ArrayList list = new ArrayListExtension(arrayClass, length); // This is expensive as our array may not grown this big. // Prevents problems when XML claims a huge size // that it doesn't actually fill. //for (int i = 0; i < length; i++) { // list.add(null); //} value = list; } catch (NumberFormatException e) { throw new IllegalArgumentException(Messages.getMessage("badInteger00", dimString)); } } // If soapenc:offset specified, set the current index accordingly String offset = Constants.getValue(attributes, Constants.URIS_SOAP_ENC, Constants.ATTR_OFFSET); if (offset != null) { if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { throw new SAXException(Messages.getMessage("noSparseArray")); } int leftBracketIndex = offset.lastIndexOf('['); int rightBracketIndex = offset.lastIndexOf(']'); if (leftBracketIndex == -1 || rightBracketIndex == -1 || rightBracketIndex < leftBracketIndex) { throw new SAXException(Messages.getMessage("badOffset00", offset)); } curIndex = convertToIndex(offset.substring(leftBracketIndex + 1, rightBracketIndex), "badOffset00"); } if (log.isDebugEnabled()) { log.debug("Exit: ArrayDeserializer::startElement()"); } }
From source file:org.apache.axis.encoding.ser.BeanSerializer.java
/** * Serialize a bean. Done simply by serializing each bean property. * @param name is the element name// www . j a v a 2 s . 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 boolean isEncoded = context.isEncoded(); // check whether we have and xsd:any namespace="##any" type boolean suppressElement = !isEncoded && name.getNamespaceURI().equals("") && name.getLocalPart().equals("any"); if (!suppressElement) context.startElement(name, beanAttrs); // check whether the array is converted to ArrayOfT shema type if (value != null && value.getClass().isArray()) { Object newVal = JavaUtils.convert(value, javaType); if (newVal != null && javaType.isAssignableFrom(newVal.getClass())) { value = newVal; } } 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; Class javaType = propertyDescriptor[i].getType(); boolean isOmittable = false; // isNillable default value depends on the field type boolean isNillable = Types.isNullable(javaType); // isArray boolean isArray = false; QName itemQName = null; // 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; } ElementDesc element = (ElementDesc) field; // If we're SOAP encoded, just use the local part, // not the namespace. Otherwise use the whole // QName. if (isEncoded) { qname = new QName(element.getXmlName().getLocalPart()); } else { qname = element.getXmlName(); } isOmittable = element.isMinOccursZero(); isNillable = element.isNillable(); isArray = element.isMaxOccursUnbounded(); xmlType = element.getXmlType(); itemQName = element.getItemQName(); context.setItemQName(itemQName); } } if (qname == null) { qname = new QName(isEncoded ? "" : name.getNamespaceURI(), propName); } if (xmlType == null) { // look up the type QName using the class xmlType = context.getQNameForClass(javaType); } // Read the value from the property if (propertyDescriptor[i].isReadable()) { if (itemQName != null || (!propertyDescriptor[i].isIndexed() && !isArray)) { // Normal case: serialize the value Object propValue = propertyDescriptor[i].get(value); if (propValue == null) { // an element cannot be null if nillable property is set to // "false" and the element cannot be omitted if (!isNillable && !isOmittable) { if (Number.class.isAssignableFrom(javaType)) { // If we have a null and it's a number, though, // we might turn it into the appropriate kind of 0. // TODO : Should be caching these constructors? try { Constructor constructor = javaType .getConstructor(SimpleDeserializer.STRING_CLASS); propValue = constructor.newInstance(ZERO_ARGS); } catch (Exception e) { // If anything goes wrong here, oh well we tried. } } if (propValue == null) { throw new IOException(Messages.getMessage("nullNonNillableElement", propName)); } } // if meta data says minOccurs=0, then we can skip // it if its value is null and we aren't doing SOAP // encoding. if (isOmittable && !isEncoded) { continue; } } context.serialize(qname, null, propValue, xmlType, javaType); } 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, propertyDescriptor[i].getType()); } } } } } 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(); }