public static XmlObject fromTemplateElement( String name, Object value, boolean setValue ) throws SOAPException { // Use the TEMPLATE org.w3c.dom.Element to create new Message Elements XmlObject me = new XmlObject(); if ( setValue ) { me.setValue( value ); } me.setName( new QName( name ) ); return me; }
private static XmlObject createForeignKeyElement( String type, String lookupField, String extIdName, Object extIdValue ) throws Exception { // Foreign key relationship to the object XmlObject me = fromTemplateElement( lookupField, null, false ); me.addField( "type", type ); me.addField( extIdName, extIdValue ); return me; }
void setFieldInSObject( SObject sobjPass, XmlObject element ) { Iterator<XmlObject> children = element.getChildren(); String name = element.getName().getLocalPart(); if ( !children.hasNext() ) { sobjPass.setSObjectField( name, element.getValue() ); } else { SObject child = new SObject(); child.setName( new QName( name ) ); while ( children.hasNext() ) { setFieldInSObject( child, children.next() ); } sobjPass.setSObjectField( name, child ); } }
@Override public void load(XmlInputStream __in, TypeMapper __typeMapper) throws IOException, ConnectionException { __typeMapper.consumeStartTag(__in); loadFields(__in, __typeMapper); __typeMapper.consumeEndTag(__in); }
/** * Drill down the SObject hierarchy based on the given field hierarchy until either null or the correct MessageElement * is found */ private XmlObject getMessageElementForHierarchy( SObject con, String[] fieldHierarchy ) { final int lastIndex = fieldHierarchy.length - 1; SObject currentSObject = con; for ( int index = 0; index <= lastIndex; index++ ) { for ( XmlObject element : getChildren( currentSObject ) ) { if ( element.getName().getLocalPart().equals( fieldHierarchy[index] ) ) { if ( index == lastIndex ) { return element; } else { if ( element instanceof SObject ) { // Found the next level, keep going currentSObject = (SObject) element; } break; } } } } return null; }
public String getRecordValue( SObject con, String fieldname ) throws KettleException { String[] fieldHierarchy = fieldname.split( "\\." ); if ( con == null ) { return null; } else { XmlObject element = getMessageElementForHierarchy( con, fieldHierarchy ); if ( element != null ) { Object object = element.getValue(); if ( object != null ) { if ( object instanceof QueryResult ) { return buildJsonQueryResult( (QueryResult) object ); } return String.valueOf( object ); } else { return (String) element.getValue(); } } } return null; }
public void writeObject(XmlOutputStream out, TypeInfo info, Object value, boolean isSet) throws IOException { if (!isSet && info.getMinOcc() == 0) { return; } if (value == null) { writeNull(out, info); return; } if (info.getMaxOcc() == 1) { writeSingleObject(out, info, value); } else { writeArrayObject(out, info, value); } }
public Object readObject(XmlInputStream in, TypeInfo info, Class<?> type) throws ConnectionException, IOException { Object result; if (info.getMaxOcc() == 1) { result = readSingle(in, info, type); } else { result = readArray(in, info, type, false); } return result; }
public Generator(String packagePrefix, STGroupDir templates, String interfacePackagePrefix, char startDelim, char endDelim) throws Exception { this.templates = templates; this.packagePrefix = packagePrefix; this.interfacePackagePrefix = interfacePackagePrefix; typeMapper.setPackagePrefix(packagePrefix); typeMapper.setInterfacePackagePrefix(interfacePackagePrefix); }
protected void writeFields(com.sforce.ws.parser.XmlOutputStream __out, com.sforce.ws.bind.TypeMapper __typeMapper) throws java.io.IOException { __typeMapper.writeObject(__out, exceptionCode__typeInfo, exceptionCode, exceptionCode__is_set); __typeMapper.writeString(__out, exceptionMessage__typeInfo, exceptionMessage, exceptionMessage__is_set); }
@Override public void load(XmlInputStream in, TypeMapper typeMapper) throws IOException, ConnectionException { loadStartTag(in, typeMapper); loadAfterStartTag(in, typeMapper); }
/** * return the method name for the specified field name. * * @param name field name * @return method name. First letter of the method name will be upper case. */ public static String getMethodName(String name) { return upperCaseFirstLetterName(name); }
@SuppressWarnings( "unchecked" ) private JSONObject buildJSONSObject( SObject sobject ) { JSONObject jsonObject = new JSONObject(); for ( XmlObject element : getChildren( sobject ) ) { Object object = element.getValue(); if ( object != null && object instanceof SObject ) { jsonObject.put( element.getName(), buildJSONSObject( (SObject) object ) ); } else { jsonObject.put( element.getName(), element.getValue() ); } } return jsonObject; }
@Override public void load(XmlInputStream __in, TypeMapper __typeMapper) throws IOException, ConnectionException { __typeMapper.consumeStartTag(__in); loadFields(__in, __typeMapper); __typeMapper.consumeEndTag(__in); }
public static XmlObject[] getChildren( SObject object ) { List<String> reservedFieldNames = Arrays.asList( "type", "fieldsToNull" ); if ( object == null ) { return null; } List<XmlObject> children = new ArrayList<>(); Iterator<XmlObject> iterator = object.getChildren(); while ( iterator.hasNext() ) { XmlObject child = iterator.next(); if ( child.getName().getNamespaceURI().equals( Constants.PARTNER_SOBJECT_NS ) && reservedFieldNames.contains( child.getName().getLocalPart() ) ) { continue; } children.add( child ); } if ( children.size() == 0 ) { return null; } return children.toArray( new XmlObject[children.size()] ); } }
public Object readObject(XmlInputStream in, TypeInfo info, Class<?> type) throws ConnectionException, IOException { Object result; if (info.getMaxOcc() == 1) { result = readSingle(in, info, type); } else { result = readArray(in, info, type, false); } return result; }
void addFields( String prefix, Set<String> fieldNames, XmlObject field ) { //Salesforce SOAP Api sends IDs always in the response, even if we don't request it in SOQL query and //the id's value is null in this case. So, do not add this Id to the fields list if ( isNullIdField( field ) ) { return; } String fieldname = prefix + field.getName().getLocalPart(); if ( field instanceof SObject ) { SObject sobject = (SObject) field; for ( XmlObject element : SalesforceConnection.getChildren( sobject ) ) { addFields( fieldname + ".", fieldNames, element ); } } else { addField( fieldname, fieldNames, (String) field.getValue() ); } }