All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.requestfactory.shared.impl.AbstractRequest Maven / Gradle / Ivy

There is a newer version: 2.10.0
Show newest version
/*
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.requestfactory.shared.impl;

import com.google.gwt.autobean.shared.Splittable;
import com.google.gwt.requestfactory.shared.BaseProxy;
import com.google.gwt.requestfactory.shared.InstanceRequest;
import com.google.gwt.requestfactory.shared.Receiver;
import com.google.gwt.requestfactory.shared.Request;
import com.google.gwt.requestfactory.shared.RequestContext;
import com.google.gwt.requestfactory.shared.ServerFailure;
import com.google.gwt.requestfactory.shared.Violation;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Abstract implementation of {@link Request}. Each request stores a
 * {@link DeltaValueStoreJsonImpl}.
 *
 * 

RequestFactory has moved to * com.google.web.bindery.requestfactory. This package will be * removed in a future version of GWT.

* * @param return type */ @Deprecated public abstract class AbstractRequest implements Request, InstanceRequest { /** * Used by generated subtypes. */ protected final Set propertyRefs = new HashSet(); protected final AbstractRequestContext requestContext; private Receiver receiver; private RequestData requestData; protected AbstractRequest(AbstractRequestContext requestContext) { this.requestContext = requestContext; } public void fire() { requestContext.fire(); } public void fire(Receiver receiver) { to(receiver); fire(); } /** * Returns the properties. */ public Set getPropertyRefs() { return Collections.unmodifiableSet(propertyRefs); } public RequestData getRequestData() { if (requestData == null) { requestData = makeRequestData(); } return requestData; } public RequestContext to(Receiver receiver) { this.receiver = receiver; return requestContext; } /** * This method comes from the {@link InstanceRequest} interface. Instance * methods place the instance in the first parameter slot. */ public Request using(BaseProxy instanceObject) { getRequestData().getOrderedParameters()[0] = instanceObject; /* * Instance methods enqueue themselves when their using() method is called. * This ensures that the instance parameter will have been set when * AbstractRequestContext.retainArg() is called. */ requestContext.addInvocation(this); return this; } public Request with(String... propertyRefs) { this.propertyRefs.addAll(Arrays.asList(propertyRefs)); return this; } protected abstract RequestData makeRequestData(); Receiver getReceiver() { return receiver; } boolean hasReceiver() { return receiver != null; } void onFail(ServerFailure failure) { if (receiver != null) { receiver.onFailure(failure); } } void onSuccess(Splittable split) { // The user may not have called to() if (receiver != null) { @SuppressWarnings("unchecked") T result = (T) EntityCodex.decode(requestContext, requestData.getReturnType(), requestData.getElementType(), split); receiver.onSuccess(result); } } void onViolation(Set errors) { // The user may not have called to() if (receiver != null) { receiver.onViolation(errors); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy