Transforms the given {@code Source} to the {@code Result}.
@param source the source to transform from
@param result the result to transform to
@throws TransformerException in case of transformation errors
769641
protected void transform(Source source, Result result) throws TransformerException {
		this.transformerFactory.newTransformer().transform(source, result);
	}
360894
private void transform(final String xml, final UIContext uic, final PrintWriter writer) {

		Transformer transformer = newTransformer();
		Source inputXml;
		try {
			inputXml = new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8")));
			StreamResult result = new StreamResult(writer);
			if (debugRequested) {
				transformer.setParameter("isDebug", 1);
			}
			transformer.transform(inputXml, result);
		} catch (UnsupportedEncodingException | TransformerException ex) {
			throw new SystemException("Could not transform xml", ex);
		}
	}
176438
private static byte[] transform(final InputStream body) throws IOException {
        final SAXSource source = new SAXSource(new InputSource(body));
        final ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
            final XMLReader xmlreader = SAXParserFactory.newInstance()
                .newSAXParser().getXMLReader();
            source.setXMLReader(xmlreader);
            xmlreader.setFeature(
                RsPrettyXml.LOAD_EXTERNAL_DTD, false
            );
            final String yes = "yes";
            final Transformer transformer = TransformerFactory.newInstance()
                .newTransformer();
            // @checkstyle MultipleStringLiteralsCheck (2 line)
            transformer.setOutputProperty(
                OutputKeys.OMIT_XML_DECLARATION, yes
            );
            RsPrettyXml.prepareDocType(body, transformer);
            transformer.setOutputProperty(OutputKeys.INDENT, yes);
            transformer.transform(source, new StreamResult(result));
        } catch (final TransformerException
            | ParserConfigurationException
            | SAXException ex) {
            throw new IOException(ex);
        }
        return result.toByteArray();
    }
1343403
private <T> Collection<Integer> transformSource(SourceTransformation<T> source) {
		String slotSharingGroup = determineSlotSharingGroup(source.getSlotSharingGroup(), Collections.emptyList());

		streamGraph.addSource(source.getId(),
				slotSharingGroup,
				source.getCoLocationGroupKey(),
				source.getOperator(),
				null,
				source.getOutputType(),
				"Source: " + source.getName());
		if (source.getOperator().getUserFunction() instanceof InputFormatSourceFunction) {
			InputFormatSourceFunction<T> fs = (InputFormatSourceFunction<T>) source.getOperator().getUserFunction();
			streamGraph.setInputFormat(source.getId(), fs.getFormat());
		}
		streamGraph.setParallelism(source.getId(), source.getParallelism());
		streamGraph.setMaxParallelism(source.getId(), source.getMaxParallelism());
		return Collections.singleton(source.getId());
	}
148556
@Requires({
    "code != null",
    "lineNumbers != null",
    "code.size() == lineNumbers.size()"
  })
  protected boolean transform(List<String> code, List<Long> lineNumbers,
                              Object sourceInfo) {
    return transformer.transform(code, lineNumbers, sourceInfo);
  }
888082
public void execute(
          TransformerImpl transformer)
            throws TransformerException
  {

    int sourceNode = transformer.getXPathContext().getCurrentNode();
    String countString = getCountString(transformer, sourceNode);

    try
    {
      transformer.getResultTreeHandler().characters(countString.toCharArray(),
                                                    0, countString.length());
    }
    catch(SAXException se)
    {
      throw new TransformerException(se);
    }
  }
93980
@Override
	protected void transform(final XtendConstructor source, final JvmGenericType container) {
		final String constructorName = container.getSimpleName();

		// Special case: static constructor
		if (source.isStatic()) {
			final JvmOperation staticConstructor = this.typesFactory.createJvmOperation();
			container.getMembers().add(staticConstructor);
			this.associator.associatePrimary(source, staticConstructor);
			staticConstructor.setSimpleName(Utils.STATIC_CONSTRUCTOR_NAME);
			staticConstructor.setVisibility(JvmVisibility.PRIVATE);
			staticConstructor.setStatic(true);
			staticConstructor.setReturnType(this._typeReferenceBuilder.typeRef(Void.TYPE));
			setBody(staticConstructor, source.getExpression());
			copyAndCleanDocumentationTo(source, staticConstructor);
			return;
		}

		final GenerationContext context = getContext(container);

		final boolean isVarArgs = Utils.isVarArg(source.getParameters());

		// Generate the unique identifier of the constructor.
		final QualifiedActionName actionKey = this.sarlSignatureProvider.createConstructorQualifiedName(container);

		// Generate all the constructor signatures related to the constructor to create.
		final InferredPrototype constructorSignatures = this.sarlSignatureProvider.createPrototypeFromSarlModel(
				actionKey,
				Utils.isVarArg(source.getParameters()), source.getParameters());

		// Generate the main Java constructor.
		final JvmConstructor constructor = this.typesFactory.createJvmConstructor();
		container.getMembers().add(constructor);
		this.associator.associatePrimary(source, constructor);
		constructor.setSimpleName(constructorName);
		setVisibility(constructor, source);
		constructor.setVarArgs(isVarArgs);

		// Generate the parameters
		final List<InferredStandardParameter> paramList = constructorSignatures.getOriginalParameterTypes();
		translateSarlFormalParameters(
				context,
				constructor, container, isVarArgs,
				source.getParameters(), false, paramList);

		// Generate additional information (type parameters, exceptions...)
		copyAndFixTypeParameters(source.getTypeParameters(), constructor);
		for (final JvmTypeReference exception : source.getExceptions()) {
			constructor.getExceptions().add(this.typeBuilder.cloneWithProxies(exception));
		}
		translateAnnotationsTo(source.getAnnotations(), constructor);

		// Set the body.
		setBody(constructor, source.getExpression());

		// The signature definition of the constructor.
		final ActionParameterTypes sigKey = this.sarlSignatureProvider.createParameterTypesFromJvmModel(
				isVarArgs, constructor.getParameters());

		// Update the list of generated constructors
		if (context != null) {
			context.getGeneratedConstructors().put(sigKey, constructor);
		}

		copyAndCleanDocumentationTo(source, constructor);

		final Runnable differedGeneration  = () -> {
			// Generate the Java functions that correspond to the action with the parameter default values applied.
			for (final Entry<ActionParameterTypes, List<InferredStandardParameter>> entry
					: constructorSignatures.getInferredParameterTypes().entrySet()) {

				if (context == null || !context.getGeneratedConstructors().containsKey(entry.getKey())) {
					final List<InferredStandardParameter> otherSignature = entry.getValue();
					// Generate the additional constructor that is invoke the main constructor previously generated.
					final JvmConstructor constructor2 = SARLJvmModelInferrer.this.typesFactory.createJvmConstructor();
					container.getMembers().add(constructor2);
					copyAndCleanDocumentationTo(source, constructor2);
					constructor2.setSimpleName(container.getSimpleName());
					constructor2.setVisibility(constructor.getVisibility());
					constructor2.setVarArgs(isVarArgs);

					final List<String> args = translateSarlFormalParametersForSyntheticOperation(
							constructor2, container, isVarArgs, otherSignature);

					addAnnotationSafe(
							constructor2, DefaultValueUse.class,
							constructorSignatures.getFormalParameterTypes().toString());
					appendGeneratedAnnotation(constructor2, context);

					setBody(constructor2, toStringConcatenation(
							"this(" //$NON-NLS-1$
							+ IterableExtensions.join(args, ", ") //$NON-NLS-1$
							+ ");")); //$NON-NLS-1$

					// Update the list of the generated constructors.
					if (context != null) {
						context.getGeneratedConstructors().put(entry.getKey(), constructor2);
					}
				}
			}
		};

		if (context != null) {
			context.getPreFinalizationElements().add(differedGeneration);
			context.setActionIndex(context.getActionIndex() + 1);
			context.incrementSerial(sigKey.hashCode());
		} else {
			differedGeneration.run();
		}
	}
562815
public void setResult(Result result) throws IllegalArgumentException
  {

    if (null == result)
      throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_RESULT_NULL, null)); //"result should not be null");

    try
    {
//      ContentHandler handler =
//        m_transformer.createResultContentHandler(result);
//      m_transformer.setContentHandler(handler);
        SerializationHandler xoh = 
            m_transformer.createSerializationHandler(result);
        m_transformer.setSerializationHandler(xoh);
    }
    catch (javax.xml.transform.TransformerException te)
    {
      throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_RESULT_COULD_NOT_BE_SET, null)); //"result could not be set");
    }

    m_result = result;
  }
538294
private String performSplitting(String source, String splitString, String indexString)
        throws TransformationOperationException {
        try {
            Integer index = Integer.parseInt(indexString);
            return source.split(splitString)[index];
        } catch (NumberFormatException e) {
            throw new TransformationOperationException("The given result index parameter is not a number");
        } catch (IndexOutOfBoundsException e) {
            throw new TransformationOperationException(
                "The split result does not have that much results for the index parameter");
        }
    }
222932
@Override
    public boolean upgradeData(Source source, Result result) {
        final Transformer transformer;
        try {
            transformer = this.upgradeTemplates.newTransformer();
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException(
                    "Failed to create new Transformer from the configured templates: "
                            + this.xslResource,
                    e);
        }

        try {
            transformer.transform(source, result);
        } catch (TransformerException e) {
            throw new RuntimeException(
                    "Failed to upgrade data using XSLT transformation: " + this.xslResource, e);
        }

        return true;
    }
459491
public void execute(TransformerImpl transformer) throws TransformerException
  {    
    XPathContext context = transformer.getXPathContext();

    // Verify that result has not already been set by another result
    // element. Recursion is allowed: intermediate results are cleared 
    // in the owner ElemExsltFunction execute().
    if (transformer.currentFuncResultSeen()) {
        throw new TransformerException("An EXSLT function cannot set more than one result!");
    }

    int sourceNode = context.getCurrentNode();

    // Set the return value;
    XObject var = getValue(transformer, sourceNode);
    transformer.popCurrentFuncResult();
    transformer.pushCurrentFuncResult(var);
  }
235241
@Override
	@SuppressWarnings({"checkstyle:methodlength", "checkstyle:cyclomaticcomplexity",
			"checkstyle:npathcomplexity", "checkstyle:booleanexpressioncomplexity"})
	protected void transform(final XtendFunction source, final JvmGenericType container, boolean allowDispatch) {
		final GenerationContext context = getContext(container);

		// Compute the operation name
		// Issue #355: null or empty name is possible.
		final String originalFunctionName = source.getName();
		if (!Strings.isNullOrEmpty(originalFunctionName)) {
			final StringBuilder sourceNameBuffer = new StringBuilder(originalFunctionName);
			if (allowDispatch && source.isDispatch()) {
				sourceNameBuffer.insert(0, "_"); //$NON-NLS-1$
			}
			final String sourceName = sourceNameBuffer.toString();

			// Create the main function
			final JvmOperation operation = this.typesFactory.createJvmOperation();
			container.getMembers().add(operation);
			operation.setSimpleName(sourceName);
			setVisibility(operation, source);
			operation.setStrictFloatingPoint(source.isStrictFloatingPoint());
			operation.setStatic(source.isStatic());
			operation.setSynchronized(source.isSynchonized());
			operation.setNative(source.isNative());
			boolean enableFunctionBody;
			if (container.isInterface()) {
				enableFunctionBody = false;
				if (context != null && context.isAtLeastJava8()
						&& !Utils.toLightweightTypeReference(container, this.services).isSubtypeOf(Capacity.class)) {
					if (operation.isStatic()) {
						enableFunctionBody = true;
					} else if (source.getExpression() != null && !operation.isAbstract()) {
						enableFunctionBody = true;
					}
				}
				operation.setDefault(enableFunctionBody && !operation.isStatic());
				operation.setAbstract(!enableFunctionBody);
				operation.setFinal(false);
			} else {
				operation.setDefault(false);
				enableFunctionBody = context != null && !source.isAbstract();
				operation.setAbstract(!enableFunctionBody);
				operation.setFinal(enableFunctionBody && source.isFinal());
			}
			this.associator.associatePrimary(source, operation);

			// Type parameters
			copyAndFixTypeParameters(source.getTypeParameters(), operation);

			// Compute the identifier of the action.
			final QualifiedActionName actionKey = this.sarlSignatureProvider.createQualifiedActionName(
					container, sourceName);

			// Compute the different action prototypes associated to the action to create.
			final boolean isVarArgs = Utils.isVarArg(source.getParameters());
			final InferredPrototype actionSignatures = this.sarlSignatureProvider.createPrototypeFromSarlModel(
					actionKey,
					isVarArgs, source.getParameters());

			// Compute the action prototype of the action without optional parameter
			final ActionPrototype actSigKey = this.sarlSignatureProvider.createActionPrototype(
					sourceName,
					actionSignatures.getFormalParameterTypes());

			// Generate the parameters
			final List<InferredStandardParameter> paramList = actionSignatures.getOriginalParameterTypes();
			translateSarlFormalParameters(
					context,
					operation, container, isVarArgs,
					source.getParameters(),
					container.isInterface(), paramList);

			// Get the super function
			final JvmOperation inheritedOperation;
			if (context != null) {
				JvmOperation tmpInheritedOperation = context.getInheritedFinalOperations().get(actSigKey);
				if (tmpInheritedOperation == null) {
					tmpInheritedOperation = context.getInheritedOverridableOperations().get(actSigKey);
				}
				if (tmpInheritedOperation == null) {
					tmpInheritedOperation = context.getInheritedOperationsToImplement().get(actSigKey);
				}
				inheritedOperation = tmpInheritedOperation;
			} else {
				inheritedOperation = null;
			}

			// Infer the return type
			final JvmTypeReference selectedReturnType = inferFunctionReturnType(source, operation, inheritedOperation);
			operation.setReturnType(selectedReturnType);

			// Exceptions
			for (final JvmTypeReference exception : source.getExceptions()) {
				operation.getExceptions().add(this.typeBuilder.cloneWithProxies(exception));
			}

			// Add the body
			if (enableFunctionBody) {
				setBody(operation, source.getExpression());
			}

			// User Annotations
			translateAnnotationsTo(source.getAnnotations(), operation);

			// Add @Inline annotation
			if (context != null && context.isAtLeastJava8()
					&& context.getGeneratorConfig2().isGenerateInlineAnnotation()
					&& !source.isAbstract() && !container.isInterface()
					&& (source.isStatic() || source.isFinal() || container.isFinal())
					&& context.getParentContext() == null
					&& this.annotationFinder.findAnnotation(operation, Inline.class) == null) {
				context.getPostFinalizationElements().add(
						() -> this.inlineExpressionCompiler.appendInlineAnnotation(operation, source));
			}

			// Add @Override annotation
			if (source.isOverride()
					&& this.annotationFinder.findAnnotation(operation, Override.class) == null
					&& this.typeReferences.findDeclaredType(Override.class, source) != null) {
				addAnnotationSafe(operation, Override.class);
			}

			// Add @Pure annotation
			final boolean addDynamicPureAnnotationGenerator;
			final boolean hasExplicitPureAnnotation = this.annotationFinder.findAnnotation(operation, Pure.class) != null;
			if (context != null && context.getGeneratorConfig2().isGeneratePureAnnotation()
					&& !hasExplicitPureAnnotation && this.typeReferences.findDeclaredType(Pure.class, source) != null) {
				addDynamicPureAnnotationGenerator = inheritedOperation == null;
				if (addDynamicPureAnnotationGenerator) {
					this.operationHelper.attachPureAnnotationAdapter(operation, (op, helper) -> {
						return helper.isPurableOperation(source);
					});
				} else {
					this.operationHelper.attachPureAnnotationAdapter(operation, (op, helper) -> {
						return helper.isPureOperation(inheritedOperation);
					});
				}
			} else {
				addDynamicPureAnnotationGenerator = false;
			}

			// Detecting if the action is an early-exit action.
			// If true, the Java code is annotated to be usable by the SARL validator.
			final List<JvmTypeReference> firedEvents;
			final boolean isEarlyExit;
			if (source instanceof SarlAction) {
				final SarlAction action = (SarlAction) source;
				firedEvents = action.getFiredEvents();
				isEarlyExit = this.earlyExitComputer.isEarlyExitOperation(action);
				if (isEarlyExit) {
					addAnnotationSafe(operation, EarlyExit.class);
				}
			} else {
				firedEvents = Collections.emptyList();
				isEarlyExit = false;
			}

			// Put the fired SARL events as Java annotations for being usable by the SARL validator.
			if (!firedEvents.isEmpty()) {
				operation.getAnnotations().add(annotationClassRef(FiredEvent.class, firedEvents));
			}

			// 1. Ensure that the Java annotations related to the default value are really present.
			//    They may be not present if the generated action is a specific version of an inherited
			//    action with default values for parameters.
			// 2. Update the two collections that describes the implemented and implementable operations.
			if (context != null) {
				final JvmOperation implementedOperation = context.getInheritedOperationsToImplement().remove(actSigKey);
				// Put the annotations that were defined in the implemented operation
				if (implementedOperation != null) {
					if (this.annotationFinder.findAnnotation(implementedOperation, DefaultValueSource.class) != null
							&& this.annotationFinder.findAnnotation(operation, DefaultValueSource.class) == null) {
						addAnnotationSafe(operation, DefaultValueSource.class);
					}
					// Reinject the @DefaultValue annotations
					final List<JvmFormalParameter> oparams = implementedOperation.getParameters();
					final List<JvmFormalParameter> cparams = operation.getParameters();
					assert oparams.size() == cparams.size();
					for (int i = 0; i < oparams.size(); ++i) {
						final JvmFormalParameter op = oparams.get(i);
						final JvmFormalParameter cp = cparams.get(i);
						final String ovalue = this.annotationUtils.findStringValue(op, DefaultValue.class);
						if (ovalue != null
								&& this.annotationFinder.findAnnotation(cp, DefaultValue.class) == null) {
							addAnnotationSafe(cp,
									DefaultValue.class,
									this.sarlSignatureProvider.qualifyDefaultValueID(
											implementedOperation.getDeclaringType().getIdentifier(),
											ovalue));
						}
					}
				}
				// Add the main operation into the list of overridable operations
				context.getInheritedOverridableOperations().put(actSigKey, operation);
			}

			copyAndCleanDocumentationTo(source, operation);

			@SuppressWarnings("checkstyle:anoninnerlength")
			final Runnable differedGeneration = () -> {
				// Generate the Java functions that correspond to the action with the parameter default values applied.
				for (final Entry<ActionParameterTypes, List<InferredStandardParameter>> otherSignature
						: actionSignatures.getInferredParameterTypes().entrySet()) {
					final ActionPrototype ak = SARLJvmModelInferrer.this.sarlSignatureProvider.createActionPrototype(
							sourceName,
							otherSignature.getKey());
					if (ak != null
							&& (context == null
							|| (!context.getInheritedFinalOperations().containsKey(ak)
									&& !context.getInheritedOverridableOperations().containsKey(ak)))) {

						// Generate the additional constructor that is invoke the main constructor previously generated.
						final JvmOperation operation2 = SARLJvmModelInferrer.this.typesFactory.createJvmOperation();
						container.getMembers().add(operation2);
						operation2.setSimpleName(operation.getSimpleName());
						operation2.setVisibility(operation.getVisibility());
						operation2.setVarArgs(operation.isVarArgs());
						operation2.setAbstract(operation.isAbstract());
						operation2.setDeprecated(operation.isDeprecated());
						operation2.setStatic(operation.isStatic());
						operation2.setFinal(!operation.isStatic() && !container.isInterface());
						operation2.setNative(false);
						operation2.setStrictFloatingPoint(false);
						operation2.setSynchronized(false);
						this.associator.associate(source, operation2);

						copyTypeParametersFromJvmOperation(operation, operation2);

						for (final JvmTypeReference exception : operation.getExceptions()) {
							operation2.getExceptions().add(SARLJvmModelInferrer.this.typeBuilder
									.cloneWithProxies(exception));
						}

						if (selectedReturnType instanceof XComputedTypeReference) {
							operation2.setReturnType(this.typeReferences.createDelegateTypeReference(selectedReturnType));
						} else {
							operation2.setReturnType(cloneWithTypeParametersAndProxies(selectedReturnType, operation2));
						}

						final List<String> args = translateSarlFormalParametersForSyntheticOperation(
								operation2, container, isVarArgs, otherSignature.getValue());

						if (context != null && context.isAtLeastJava8()) {
							operation2.setDefault(container.isInterface());
							operation2.setAbstract(false);
							setBody(operation2, it -> {
								final JvmTypeReference type = operation2.getReturnType();
								if (!SARLJvmModelInferrer.this.typeReferences.is(type, void.class)) {
									it.append("return "); //$NON-NLS-1$
								}
								it.append(sourceName);
								it.append("("); //$NON-NLS-1$
								it.append(IterableExtensions.join(args, ", ")); //$NON-NLS-1$
								it.append(");"); //$NON-NLS-1$
							});
						} else {
							operation2.setDefault(false);
							operation2.setAbstract(true);
						}

						// @Override annotation
						if (source.isOverride()
								&& SARLJvmModelInferrer.this.annotationFinder.findAnnotation(operation,
								Override.class) == null
								&& SARLJvmModelInferrer.this.typeReferences.findDeclaredType(
										Override.class, source) != null) {
							addAnnotationSafe(
									operation, Override.class);
						}

						// @DefaultValueUse annotation
						addAnnotationSafe(
								operation2, DefaultValueUse.class,
								actionSignatures.getFormalParameterTypes().toString());
						appendGeneratedAnnotation(operation2, context);

						// @EarlyExit annotation
						// If the main action is an early-exit action, the additional operation
						// is also an early-exit operation.
						if (isEarlyExit) {
							addAnnotationSafe(
									operation2, EarlyExit.class);
						}

						// @FiredEvent annotation
						// Put the fired SARL events as Java annotations for being usable by the SARL validator.
						if (!firedEvents.isEmpty()) {
							operation2.getAnnotations().add(
									annotationClassRef(FiredEvent.class, firedEvents));
						}

						// @Pure annotation
						if (addDynamicPureAnnotationGenerator) {
							this.operationHelper.attachPureAnnotationAdapter(operation2, (op, helper) -> {
								return helper.isPureOperation(operation);
							});
						} else if (hasExplicitPureAnnotation) {
							addAnnotationSafe(
									operation2, Pure.class);
						}

						// Copy the annotations from the original operations, and that are not overridden above
						for (final JvmAnnotationReference annotation : operation.getAnnotations()) {
							final String id = annotation.getAnnotation().getIdentifier();
							if (!DefaultValueSource.class.getName().equals(id)
									&& !DefaultValueUse.class.getName().equals(id)
									&& !Pure.class.getName().equals(id)
									&& !EarlyExit.class.getName().equals(id)
									&& !FiredEvent.class.getName().equals(id)
									&& !Inline.class.getName().equals(id)
									&& !Generated.class.getName().equals(id)) {
								try {
									final JvmAnnotationReference clone = SARLJvmModelInferrer.this._annotationTypesBuilder
											.annotationRef(id);
									for (final JvmAnnotationValue annotationValue : annotation.getExplicitValues()) {
										clone.getExplicitValues().add(EcoreUtil.copy(annotationValue));
									}
									operation2.getAnnotations().add(clone);
								} catch (IllegalArgumentException exception) {
									// ignore
								}
							}
						}

						// Copy and clean the documentation
						copyAndCleanDocumentationTo(operation, operation2);

						// Update the two collections that describes the implemented and implementable operations.
						if (context != null) {
							context.getInheritedOperationsToImplement().remove(ak);
							context.getInheritedOverridableOperations().put(ak, operation2);
						}
					}
				}
			};

			if (context != null) {
				context.getPreFinalizationElements().add(differedGeneration);
				context.setActionIndex(context.getActionIndex() + 1);
				context.incrementSerial(actSigKey.hashCode());
			} else {
				differedGeneration.run();
			}
		}
	}
862842
protected void init(Source source) throws SQLException {

        if (source == null) {
            throw Util.nullArgument("source");
        }

        Transformer           transformer =
            JDBCSQLXML.getIdentityTransformer();
        StreamResult          result      = new StreamResult();
        ByteArrayOutputStream baos        = new ByteArrayOutputStream();
        GZIPOutputStream      gzos;

        try {
            gzos = new GZIPOutputStream(baos);
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }
        result.setOutputStream(gzos);

        try {
            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw Exceptions.transformFailed(ex);
        }

        try {
            gzos.close();
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }

        byte[] data = baos.toByteArray();

        setGZipData(data);
        setReadable(true);
        setWritable(false);
    }
27727
protected void transform(SarlCapacityUses source, JvmGenericType container) {
		final GenerationContext context = getContext(container);
		if (context == null) {
			return;
		}
		for (final JvmTypeReference capacityType : source.getCapacities()) {
			final JvmType type = capacityType.getType();
			if (type instanceof JvmGenericType
					/*&& this.inheritanceHelper.isSubTypeOf(capacityType, Capacity.class, SarlCapacity.class)*/
					&& !context.getGeneratedCapacityUseFields().contains(capacityType.getIdentifier())) {
				// Generate the buffer field
				final String fieldName = Utils.createNameForHiddenCapacityImplementationAttribute(capacityType.getIdentifier());
				final JvmField field = this.typesFactory.createJvmField();
				container.getMembers().add(field);
				field.setVisibility(JvmVisibility.PRIVATE);
				field.setSimpleName(fieldName);
				field.setTransient(true);
				final JvmType clearableReferenceType = this.typeReferences.findDeclaredType(ClearableReference.class, container);
				final JvmTypeReference skillClearableReference = this.typeReferences.createTypeRef(
						clearableReferenceType,
						this.typeReferences.createTypeRef(this.typeReferences.findDeclaredType(Skill.class, container)));
				field.setType(skillClearableReference);

				this.associator.associatePrimary(source, field);

				addAnnotationSafe(field, Extension.class);
				field.getAnnotations().add(annotationClassRef(ImportedCapacityFeature.class,
						Collections.singletonList(capacityType)));
				appendGeneratedAnnotation(field, getContext(container));

				// Generate the calling function
				final String methodName = Utils.createNameForHiddenCapacityImplementationCallingMethodFromFieldName(
						fieldName);
				final JvmOperation operation = this.typesFactory.createJvmOperation();
				container.getMembers().add(operation);
				operation.setVisibility(JvmVisibility.PRIVATE);
				operation.setReturnType(cloneWithTypeParametersAndProxies(capacityType, operation));
				operation.setSimpleName(methodName);

				this.associator.associatePrimary(source, operation);

				setBody(operation, it -> {
					it.append("if (this.").append(fieldName).append(" == null || this."); //$NON-NLS-1$ //$NON-NLS-2$
					it.append(fieldName).append(".get() == null) {"); //$NON-NLS-1$
					it.increaseIndentation();
					it.newLine();
					it.append("this.").append(fieldName).append(" = ") //$NON-NLS-1$ //$NON-NLS-2$
							.append(Utils.HIDDEN_MEMBER_CHARACTER).append("getSkill("); //$NON-NLS-1$
					it.append(capacityType.getType()).append(".class);"); //$NON-NLS-1$
					it.decreaseIndentation();
					it.newLine();
					it.append("}"); //$NON-NLS-1$
					it.newLine();
					it.append("return ").append(Utils.HIDDEN_MEMBER_CHARACTER) //$NON-NLS-1$
							.append("castSkill(").append(capacityType.getType()).append(".class, this.") //$NON-NLS-1$ //$NON-NLS-2$
							.append(fieldName).append(");"); //$NON-NLS-1$
				});

				// Add the annotation dedicated to this particular method
				if (context.isAtLeastJava8()) {
					context.getPostFinalizationElements().add(() -> {
						final String inlineExpression = Utils.HIDDEN_MEMBER_CHARACTER
								+ "castSkill(" + capacityType.getSimpleName() //$NON-NLS-1$
								+ ".class, ($0" + fieldName //$NON-NLS-1$
								+ " == null || $0" + fieldName //$NON-NLS-1$
								+ ".get() == null) ? ($0" + fieldName //$NON-NLS-1$
								+ " = $0" + Utils.HIDDEN_MEMBER_CHARACTER + "getSkill(" //$NON-NLS-1$ //$NON-NLS-2$
								+ capacityType.getSimpleName()
								+ ".class)) : $0" + fieldName + ")"; //$NON-NLS-1$ //$NON-NLS-2$;
						this.inlineExpressionCompiler.appendInlineAnnotation(
								operation, source.eResource().getResourceSet(), inlineExpression, capacityType);
					});
				}
				appendGeneratedAnnotation(operation, context);
				if (context.getGeneratorConfig2().isGeneratePureAnnotation()) {
					addAnnotationSafe(operation, Pure.class);
				}

				context.addGeneratedCapacityUseField(capacityType.getIdentifier());
				context.incrementSerial(capacityType.getIdentifier().hashCode());
			}
		}
	}
1011249
private void performTransform(String xslt, Document document,
                                  Result result)
        throws TransformerException, ConfigurationException, XpathException {
        try {
            StreamSource source = new StreamSource(new StringReader(xslt));
            TransformerFactory tf = XMLUnit.newTransformerFactory();
            ErrorListener el = new ErrorListener() {
                    public void error(TransformerException ex)
                        throws TransformerException {
                        // any error in our simple stylesheet must be fatal
                        throw ex;
                    }
                    public void fatalError(TransformerException ex)
                        throws TransformerException {
                        throw ex;
                    }
                    public void warning(TransformerException ex) {
                        // there shouldn't be any warning
                        ex.printStackTrace();
                    }
                };
            tf.setErrorListener(el);
            Transformer transformer = tf.newTransformer(source);
            // Issue 1985229 says Xalan-J 2.7.0 may return null for
            // illegal input
            if (transformer == null) {
                throw new XpathException("failed to obtain an XSLT transformer"
                                         + " for XPath expression.");
            }
            transformer.setErrorListener(el);
            transformer.transform(new DOMSource(document), result);
        } catch (javax.xml.transform.TransformerConfigurationException ex) {
            throw new ConfigurationException(ex);
        }
    }
60840
private static TransformerHandler getTransformerHandler(OutputStream out, String method,
                                                            String encoding)
        throws TransformerConfigurationException {

        TransformerHandler transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
        Transformer transformer = transformerHandler.getTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, method);
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        if (encoding != null) {
            transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
        }

        transformerHandler.setResult(new StreamResult(new PrintStream(out)));
        return transformerHandler;
    }
102991
public static void transform(Source source, Result result, String charset, int indent) {
		final TransformerFactory factory = TransformerFactory.newInstance();
		try {
			final Transformer xformer = factory.newTransformer();
			if (indent > 0) {
				xformer.setOutputProperty(OutputKeys.INDENT, "yes");
				xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
			}
			if (StrUtil.isNotBlank(charset)) {
				xformer.setOutputProperty(OutputKeys.ENCODING, charset);
			}
			xformer.transform(source, result);
		} catch (Exception e) {
			throw new UtilException(e, "Trans xml document to string error!");
		}
	}