/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> */ @Override public FunctionRequest clone() { return new FunctionRequest(function, at, workspaceName, inputs); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { FunctionRequest that = (FunctionRequest)obj; if (!this.at().isSame(that.at())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; if (!this.function.getClass().equals(that.function.getClass())) return false; if (!this.inputs().equals(that.inputs())) return false; return true; } return false; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.function.FunctionContext#output(java.lang.String, java.lang.Class, * java.lang.Object) */ public <T> T output( String name, Class<T> type, T defaultValue ) { return functionRequest.output(name, type, getExecutionContext()); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { String workspaceName = this.workspaceName != null ? "'" + this.workspaceName + "'" : "default"; String functionName = function.getClass().getSimpleName(); return "applyfn at " + printable(at()) + " (in " + workspaceName + " workspace) the " + functionName; }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); assertThat(request.function(), is(sameInstance(function))); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.inputs().isEmpty(), is(true)); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation2, workspace1, inputs); assertThat(request.equals(request2), is(false)); }
functionRequest.function().run(context); if (functionRequest.isReadOnly()) { functionRequest.setError(null);
/** * {@inheritDoc} * * @see org.modeshape.graph.request.function.FunctionContext#appliedAt() */ public Location appliedAt() { return functionRequest.at(); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.function.FunctionContext#workspace() */ public String workspace() { return functionRequest.inWorkspace(); }
/** * Get the value for the named output to this function. * * @param <T> the desired type of the value * @param name the name of the output parameter * @param type the expected type of the value used to convert the actual value using the * @param context the execution context to be used for converting the value; may not be null * @return the (possibly null) value for the named output, or null if there is no such named parameter * @throws ValueFormatException if the conversion from to the expected value could not be performed */ public <T> T output( String name, Class<T> type, ExecutionContext context ) { return convert(name, type, null, this.outputs, context); }
/** * Add an actual request created and executed by the invocation of this function. This method will be called by the * {@link Processor} and should not be called elsewhere. * * @param request the request * @throws IllegalArgumentException if the request reference is null */ public void addActualRequest( Request request ) { checkNotFrozen(); CheckArg.isNotNull(request, "request"); if (requests == null) requests = new ArrayList<Request>(); requests.add(request); }
public void execute( Request request ) { RequestProcessor.this.process(request); if (!request.hasError() && !request.isCancelled()) { functionRequest.addActualRequest(request); if (request instanceof ChangeRequest) { ChangeRequest changeRequest = (ChangeRequest)request; List<ChangeRequest> changes = changeRequests.get(); if (changes == null) { changes = new LinkedList<ChangeRequest>(); changeRequests.set(changes); } changes.add(changeRequest); } } }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation1, workspace2, inputs); assertThat(request.equals(request2), is(false)); } }
/** * Get the value for the named input to this function. The actual value will be converted to the specified type using the * {@link ExecutionContext}'s {@link ValueFactories}. * * @param <T> the desired type of the value * @param name the name of the input parameter * @param type the expected type of the value * @param defaultValue the default value to use, if the input doesn't have the named parameter * @param context the execution context to be used for converting the value; may not be null * @return the (possibly null) value for the named input, or the specified default value if there is no such named parameter * @throws ValueFormatException if the conversion from to the expected value could not be performed */ public <T> T input( String name, PropertyType type, T defaultValue, ExecutionContext context ) { return convert(name, type, defaultValue, this.inputs, context); }
/** * Set the value for the named output parameter for the function. If the value is nul, the parameter will be removed. * * @param name the name of the output parameter; may not be null * @param value the value for the named parameter; may be null * @return the prior value for this named parameter * @throws IllegalArgumentException if the name is null or empty * @throws IllegalStateException if the request is frozen */ public Serializable setOutput( String name, Serializable value ) { checkNotFrozen(); CheckArg.isNotEmpty(name, "name"); return value != null ? this.outputs.put(name, value) : this.outputs.remove(name); }
@Override protected Request createRequest() { return new FunctionRequest(function, validPathLocation1, workspace1, inputs); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentInputs() { inputs2.put("Some input", "value"); request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation1, workspace1, inputs2); assertThat(request.equals(request2), is(false)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.function.FunctionContext#output(java.lang.String, * org.modeshape.graph.property.PropertyType, java.lang.Object) */ public <T> T output( String name, PropertyType type, T defaultValue ) { return functionRequest.output(name, type, defaultValue, getExecutionContext()); }
/** * Get the value for the named output to this function. * * @param <T> the desired type of the value * @param name the name of the output parameter * @param type the expected type of the value used to convert the actual value using the * @param defaultValue the default value for the output parameter, if there is no such named parameter * @param context the execution context to be used for converting the value; may not be null * @return the (possibly null) value for the named output, or the specified default if there is no such named parameter * @throws ValueFormatException if the conversion from to the expected value could not be performed */ public <T> T output( String name, Class<T> type, T defaultValue, ExecutionContext context ) { return convert(name, type, defaultValue, this.outputs, context); }
/** * Add the actual requests created and executed by the invocation of this function. This method will be called by the * {@link Processor} and should not be called elsewhere. * * @param requests the requests * @throws IllegalArgumentException if the requests reference is null */ public void addActualRequests( Iterable<Request> requests ) { checkNotFrozen(); CheckArg.isNotNull(requests, "requests"); if (this.requests == null) requests = new ArrayList<Request>(); for (Request request : requests) { if (request != null) this.requests.add(request); } }