Example usage for java.util.concurrent.atomic AtomicReference get

List of usage examples for java.util.concurrent.atomic AtomicReference get

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicReference get.

Prototype

public final V get() 

Source Link

Document

Returns the current value, with memory effects as specified by VarHandle#getVolatile .

Usage

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Gets information about merges performed on the given target item (and
 * version), optionally qualified by a source item (which can be null).
 *
 * @param sourceItem/*from   w w w.j  a  va 2 s .  c  o m*/
 *        the item that is the source of merges to be returned (may be
 *        <code>null</code>)
 * @param sourceVersion
 *        the version of the source item for the merges (may be
 *        <code>null</code> if sourceItem is <code>null</code>)
 * @param targetItem
 *        the item that is the target of merges to be returned (must not be
 *        <code>null</code> or empty)
 *
 * @param targetVersion
 *        the version of the target item for the merges (must not be
 *        <code>null</code>)
 * @param versionFrom
 *        the oldest version to be included in the results (may be
 *        <code>null</code>)
 * @param versionTo
 *        the most recent version to be included in the results (may be
 *        <code>null</code>)
 * @param recursion
 *        the type of recursion to apply to the given items (must not be
 *        <code>null</code>)
 * @return the {@link ChangesetMerge}s returned by the server. May be empty
 *         but never <code>null</code>.
 */
public ChangesetMerge[] queryMerges(final String sourceItem, final VersionSpec sourceVersion,
        final String targetItem, final VersionSpec targetVersion, final VersionSpec versionFrom,
        final VersionSpec versionTo, final RecursionType recursion) {
    Check.notNull(targetItem, "targetItem"); //$NON-NLS-1$
    Check.notNull(targetVersion, "targetVersion"); //$NON-NLS-1$
    Check.notNull(recursion, "recursion"); //$NON-NLS-1$

    final List<String> allPaths = new ArrayList<String>(2);

    ItemSpec sourceItemSpec = null;
    if (sourceItem != null) {
        sourceItemSpec = new ItemSpec(sourceItem, recursion);
        allPaths.add(sourceItem);
    }

    final ItemSpec targetItemSpec = new ItemSpec(targetItem, recursion);
    allPaths.add(targetItem);

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(allPaths.toArray(new String[allPaths.size()]), workspaceName,
            workspaceOwner);

    final AtomicReference<Changeset[]> changesetsHolder = new AtomicReference<Changeset[]>();

    final ChangesetMerge[] merges = getWebServiceLayer().queryMerges(workspaceName.get(), workspaceOwner.get(),
            sourceItemSpec, sourceVersion, targetItemSpec, targetVersion, versionFrom, versionTo,
            VersionControlConstants.MAX_MERGES_RESULTS, true, changesetsHolder);

    /*
     * Hook up the changesets that came back into the merge objects this
     * method returns.
     */
    if (merges != null) {
        final Map<Integer, Changeset> changesetIDToChangesetMap = new HashMap<Integer, Changeset>();

        /*
         * Map all the changesets by ID so we can hook them into the merges
         * that have matching target versions.
         */
        final Changeset[] changesets = changesetsHolder.get();
        if (changesets != null && changesets.length > 0) {
            for (int i = 0; i < changesets.length; i++) {
                changesetIDToChangesetMap.put(new Integer(changesets[i].getChangesetID()), changesets[i]);
            }
        }

        for (int i = 0; i < merges.length; i++) {
            merges[i].setTargetChangeset(
                    changesetIDToChangesetMap.get(new Integer(merges[i].getTargetVersion())));
        }
    }

    return merges;
}

From source file:de.schildbach.pte.AbstractEfaProvider.java

protected NearbyLocationsResult xmlCoordRequest(final EnumSet<LocationType> types, final int lat, final int lon,
        final int maxDistance, final int maxStations) throws IOException {
    final HttpUrl.Builder url = coordEndpoint.newBuilder();
    appendXmlCoordRequestParameters(url, types, lat, lon, maxDistance, maxStations);
    final AtomicReference<NearbyLocationsResult> result = new AtomicReference<>();

    final HttpClient.Callback callback = new HttpClient.Callback() {
        @Override//from  w  w w  .  j av a  2 s  .co  m
        public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
            try {
                final XmlPullParser pp = parserFactory.newPullParser();
                pp.setInput(body.byteStream(), null); // Read encoding from XML declaration
                final ResultHeader header = enterItdRequest(pp);

                XmlPullUtil.enter(pp, "itdCoordInfoRequest");

                XmlPullUtil.enter(pp, "itdCoordInfo");

                XmlPullUtil.enter(pp, "coordInfoRequest");
                XmlPullUtil.skipExit(pp, "coordInfoRequest");

                final List<Location> locations = new ArrayList<>();

                if (XmlPullUtil.optEnter(pp, "coordInfoItemList")) {
                    while (XmlPullUtil.test(pp, "coordInfoItem")) {
                        final String type = XmlPullUtil.attr(pp, "type");
                        final LocationType locationType;
                        if ("STOP".equals(type))
                            locationType = LocationType.STATION;
                        else if ("POI_POINT".equals(type))
                            locationType = LocationType.POI;
                        else
                            throw new IllegalStateException("unknown type: " + type);

                        String id = XmlPullUtil.optAttr(pp, "stateless", null);
                        if (id == null)
                            id = XmlPullUtil.attr(pp, "id");

                        final String name = normalizeLocationName(XmlPullUtil.optAttr(pp, "name", null));
                        final String place = normalizeLocationName(XmlPullUtil.optAttr(pp, "locality", null));

                        XmlPullUtil.enter(pp, "coordInfoItem");

                        // FIXME this is always only one coordinate
                        final List<Point> path = processItdPathCoordinates(pp);
                        final Point coord = path != null ? path.get(0) : null;

                        XmlPullUtil.skipExit(pp, "coordInfoItem");

                        if (name != null)
                            locations.add(new Location(locationType, id, coord, place, name));
                    }

                    XmlPullUtil.skipExit(pp, "coordInfoItemList");
                }

                result.set(new NearbyLocationsResult(header, locations));
            } catch (final XmlPullParserException x) {
                throw new ParserException("cannot parse xml: " + bodyPeek, x);
            }
        }
    };

    if (httpPost)
        httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(),
                "application/x-www-form-urlencoded", httpReferer);
    else
        httpClient.getInputStream(callback, url.build(), httpReferer);

    return result.get();
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Permanently destroys a versioned item. The item to be destroyed is
 * identified by an {@link ItemSpec} (which must contain a server path and
 * use full recursion) and an {@link VersionSpec}. The destroyed item is the
 * item that has the specified server path at the specified version. The
 * item to be destroyed does not need to be deleted before calling destroy.
 * If the item is deleted, a deletion ID can be specified in the item spec.
 * <p>//from   www .  j a  v  a2 s. com
 * If destroy is successful (and {@link DestroyFlags#PREVIEW} was not
 * specified), the items are immediately destroyed on the server - destroy
 * does not create pending changes like many other version control methods.
 * <p>
 * The destroy feature is not available in TFS 2005. This method will throw
 * an exception if this {@link VersionControlClient} is connected to a Team
 * Foundation server that does not support destroy. Additionally, the
 * authenticated user must have the AdminProjectRights permission on all
 * items that will be destroyed.
 * <p>
 * <!-- Event Origination Info -->
 * <p>
 * This method is an <b>core event origination point</b>. The
 * {@link EventSource} object that accompanies each event fired by this
 * method describes the execution context (current thread, etc.) when and
 * where this method was invoked.
 *
 * @param itemSpec
 *        identifies the item to destroy (must not be <code>null</code> and
 *        must contain a server path, not a local path)
 * @param versionSpec
 *        identifies the item to destroy (must not be <code>null</code>)
 * @param stopAt
 *        if keeping history, identifies the version including and after
 *        which file contents will be preserved for - defaults to latest
 *        version (must be <code>null</code> if not passing
 *        {@link DestroyFlags#KEEP_HISTORY})
 * @param flags
 *        the flags for this destroy operation, or {@link DestroyFlags#NONE}
 *        for default options
 * @param affectedPendingChanges
 *        a list to be filled with the pending sets affected by the destroy
 *        operation if the {@link DestroyFlags#AFFECTED_CHANGES} flag is
 *        set. May be <code>null</code> if the list of changes is not
 *        required.
 * @param affectedShelvedChanges
 *        a list to be filled with the shelved sets affected by the destroy
 *        operation if the {@link DestroyFlags#AFFECTED_CHANGES} flag is
 *        set. May be <code>null</code> if the list of changes is not
 *        required.
 * @return the items that were destroyed as a result of this call (never
 *         <code>null</code>)
 */
public Item[] destroy(final ItemSpec itemSpec, final VersionSpec versionSpec, final VersionSpec stopAt,
        DestroyFlags flags, final List<PendingSet> affectedPendingChanges,
        final List<PendingSet> affectedShelvedChanges) {
    Check.notNull(itemSpec, "itemSpec"); //$NON-NLS-1$
    Check.notNull(versionSpec, "versionSpec"); //$NON-NLS-1$

    if (flags == null) {
        flags = DestroyFlags.NONE;
    }

    if (!ServerPath.isServerPath(itemSpec.getItem())) {
        throw new IllegalArgumentException(
                Messages.getString("VersionControlClient.DestroyOperationRequiresServerPath")); //$NON-NLS-1$
    }

    final AtomicReference<Failure[]> failuresHolder = new AtomicReference<Failure[]>();
    final AtomicReference<PendingSet[]> pendingChangesHolder = new AtomicReference<PendingSet[]>();
    final AtomicReference<PendingSet[]> shelvedChangesHolder = new AtomicReference<PendingSet[]>();

    Item[] resultItems = getWebServiceLayer().destroy(itemSpec, versionSpec, stopAt, flags, failuresHolder,
            pendingChangesHolder, shelvedChangesHolder);

    if (resultItems == null) {
        resultItems = new Item[0];
    }

    if (affectedPendingChanges != null && pendingChangesHolder.get() != null) {
        for (final PendingSet set : pendingChangesHolder.get()) {
            affectedPendingChanges.add(set);
        }
    }

    if (affectedShelvedChanges != null && shelvedChangesHolder.get() != null) {
        for (final PendingSet set : shelvedChangesHolder.get()) {
            affectedShelvedChanges.add(set);
        }
    }

    for (final Item item : resultItems) {
        final DestroyEvent event = new DestroyEvent(EventSource.newFromHere(), item, stopAt, flags);
        eventEngine.fireDestroyEvent(event);
    }

    Workstation.getCurrent(getConnection().getPersistenceStoreProvider()).notifyForFolderContentChanged(this);

    reportFailures(failuresHolder.get());

    return resultItems;
}

From source file:cl.gisred.android.MedidorActivity.java

private void cerrarFormCrear(boolean bSave, View v) {
    if (bSave) {//  w w w  .  ja  va2s . c o m

        final AtomicReference<String> resp = new AtomicReference<>("");

        if (!validarForm(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            View vAction = getLayoutValidate(v);
            Map<String, Object> objectMap = new HashMap<>();
            for (View view : vAction.getTouchables()) {

                if (view.getClass().getGenericSuperclass().equals(EditText.class)) {
                    EditText oText = (EditText) view;

                    if (oText.getId() == R.id.txtNroMedidor) {
                        String oVal = (oText.getText().toString().isEmpty()) ? "0" : oText.getText().toString();
                        objectMap.put("nro_medidor", oVal);
                    }
                    if (oText.getId() == R.id.txtLectura) {
                        String oVal = (oText.getText().toString().isEmpty()) ? "0" : oText.getText().toString();
                        objectMap.put("lectura_actual", oVal);
                    }
                    if (oText.getId() == R.id.txtPoste)
                        objectMap.put("poste", oText.getText().toString());
                    if (oText.getId() == R.id.txtDireccion)
                        objectMap.put("direccion", oText.getText().toString());

                } else if (view.getClass().getGenericSuperclass().equals(Spinner.class)) {
                    Spinner oSpinner = (Spinner) view;
                    String sValue = oSpinner.getSelectedItem().toString();

                    if (oSpinner.getId() == R.id.spinnerEstado)
                        objectMap.put("estado", sValue);
                    else if (oSpinner.getId() == R.id.spinnerTipoEdific)
                        objectMap.put("tipo_edificacion", sValue);
                    else if (oSpinner.getId() == R.id.spinnerUser)
                        objectMap.put("lector", sValue);
                }
            }

            Graphic newFeatureGraphic = new Graphic(oUbicacion, null, objectMap);
            Graphic[] adds = { newFeatureGraphic };
            LyAddMedidores.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {
                @Override
                public void onCallback(FeatureEditResult[][] featureEditResults) {
                    if (featureEditResults[0] != null) {
                        if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                            resp.set("Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.showConfirmation(MedidorActivity.this, resp.get());
                                }
                            });
                        }
                    }
                }

                @Override
                public void onError(Throwable throwable) {
                    resp.set("Error al ingresar: " + throwable.getLocalizedMessage());
                    Log.w("onError", resp.get());

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(MedidorActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }
    }

    bMapTap = false;
    oUbicacion = null;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    if (bVerCapas)
        toogleCapas(fabVerCapas);

    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMedidorActions.setVisibility(View.VISIBLE);
    fabShowForm.setVisibility(View.GONE);
    formCrear.dismiss();

    if (LyAddMedidores != null)
        LyAddMedidores.setVisible(true);
}

From source file:cl.gisred.android.MantCatastroActivity.java

private void cerrarDialogCrear(boolean bSave, @Nullable View viewDialog) {
    final AtomicReference<String> resp = new AtomicReference<>("");

    if (bSave) {// w w w  . j av a2s. co m
        if (!validarVista(viewDialog)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            switch (idResLayoutSelect) {
            case R.layout.dialog_poste:
                oLyAddGraphs = LyAddPoste;
                break;
            case R.layout.dialog_direccion:
                oLyAddGraphs = LyAddDireccion;
                break;
            case R.layout.dialog_cliente:
                oLyAddGraphs = LyAddCliente;
                break;
            case R.layout.dialog_cliente_cnr:
                oLyAddGraphs = LyAddClienteCnr;
                break;
            }

            if (oLyAddGraphs != null) {
                View oView = getLayoutValidate(viewDialog);
                Util oUtil = new Util(oUbicacion);

                ArrayList<Map<String, Object>> oAttrToSave = oUtil.getAttrAddByView(oView, idResLayoutSelect,
                        empresa);

                Map<String, Object> attributes = oAttrToSave.get(0);
                Graphic newFeatureGraphic = new Graphic(oUbicacion, null, attributes);
                Graphic[] adds = { newFeatureGraphic };

                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                        || idResLayoutSelect == R.layout.dialog_cliente) {
                    addsUnion = Util.addAttrUnionPoint(oAttrToSave, oUbicacion);
                }

                oLyAddGraphs.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {

                    @Override
                    public void onCallback(FeatureEditResult[][] featureEditResults) {
                        if (featureEditResults[0] != null) {
                            if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                                resp.set(
                                        "Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                                        || idResLayoutSelect == R.layout.dialog_cliente)
                                    LyAddUnion.applyEdits(addsUnion, null, null, callBackUnion());

                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Util.showConfirmation(MantCatastroActivity.this, resp.get());
                                    }
                                });
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        resp.set("Error al grabar: " + throwable.getLocalizedMessage());
                        Log.w("onError", resp.get());

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MantCatastroActivity.this, resp.get(), Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });
                    }

                });
            }
        }
    } else {
        resp.set("Cancelado");
        Toast.makeText(MantCatastroActivity.this, resp.get(), Toast.LENGTH_LONG).show();
    }

    bMapTap = false;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    oUbicacion = null;
    if (bVerCapas)
        toogleCapas(fabVerCapas);
    //setLayerAddToggle(false);
    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    fabShowDialog.setVisibility(View.GONE);
    dialogCrear.dismiss();
    if (oLyAddGraphs != null)
        oLyAddGraphs.setVisible(true);
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Create or update a label for items in this workspace.
 *
 * @param label//w ww. j a v a2  s  . co m
 *        the label to create or update (must not be <code>null</code>)
 * @param items
 *        the items to be included in the label creation or update (not
 *        null).
 * @param options
 *        options that affect the processing of the label creation or update
 *        (must not be <code>null</code> or empty).
 * @return the label results, null if none were returned. May be empty but
 *         never null.
 */
public LabelResult[] createLabel(final VersionControlLabel label, final LabelItemSpec[] items,
        final LabelChildOption options) {
    Check.notNull(label, "label"); //$NON-NLS-1$
    Check.notNull(items, "items"); //$NON-NLS-1$
    Check.notNull(options, "options"); //$NON-NLS-1$

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(items, workspaceName, workspaceOwner);

    /*
     * Resolve authorized user name (bug 5743)
     */
    label.setOwner(IdentityHelper.getUniqueNameIfCurrentUser(getConnection().getAuthorizedIdentity(),
            label.getOwner()));

    final AtomicReference<Failure[]> failuresHolder = new AtomicReference<Failure[]>();

    final LabelResult[] ret = getWebServiceLayer().labelItem(workspaceName.get(), workspaceOwner.get(), label,
            items, options, failuresHolder);

    reportFailures(failuresHolder.get());

    return ret;
}

From source file:cl.gisred.android.LectorActivity.java

private void cerrarFormCrear(boolean bSave, View v) {
    if (bSave) {//from w w  w.j  ava 2 s  . c o  m

        final AtomicReference<String> resp = new AtomicReference<>("");

        if (!validarForm(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            View vAction = getLayoutValidate(v);
            Map<String, Object> objectMap = new HashMap<>();
            for (View view : vAction.getTouchables()) {

                if (view.getClass().getGenericSuperclass().equals(EditText.class)) {
                    EditText oText = (EditText) view;

                    if (oText.getId() == R.id.txtNroMedidor) {
                        String oVal = (oText.getText().toString().isEmpty()) ? "0" : oText.getText().toString();
                        objectMap.put("nro_medidor", oVal);
                    }
                    if (oText.getId() == R.id.txtLectura) {
                        String oVal = (oText.getText().toString().isEmpty()) ? "0" : oText.getText().toString();
                        objectMap.put("lectura_actual", oVal);
                    }
                    if (oText.getId() == R.id.txtPoste)
                        objectMap.put("poste", oText.getText().toString());
                    if (oText.getId() == R.id.txtDireccion)
                        objectMap.put("direccion", oText.getText().toString());

                } else if (view.getClass().getGenericSuperclass().equals(Spinner.class)) {
                    Spinner oSpinner = (Spinner) view;
                    String sValue = oSpinner.getSelectedItem().toString();

                    if (oSpinner.getId() == R.id.spinnerEstado)
                        objectMap.put("estado", sValue);
                    else if (oSpinner.getId() == R.id.spinnerTipoEdific)
                        objectMap.put("tipo_edificacion", sValue);
                    else if (oSpinner.getId() == R.id.spinnerUser)
                        objectMap.put("lector", sValue);
                }
            }

            Graphic newFeatureGraphic = new Graphic(oUbicacion, null, objectMap);
            Graphic[] adds = { newFeatureGraphic };
            LyAddLectores.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {
                @Override
                public void onCallback(FeatureEditResult[][] featureEditResults) {
                    if (featureEditResults[0] != null) {
                        if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                            resp.set("Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.showConfirmation(LectorActivity.this, resp.get());
                                }
                            });
                        }
                    }
                }

                @Override
                public void onError(Throwable throwable) {
                    resp.set("Error al ingresar: " + throwable.getLocalizedMessage());
                    Log.w("onError", resp.get());

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(LectorActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }
    }

    bMapTap = false;
    oUbicacion = null;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    if (bVerCapas)
        toogleCapas(fabVerCapas);

    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuLectorActions.setVisibility(View.VISIBLE);
    fabShowForm.setVisibility(View.GONE);
    formCrear.dismiss();

    if (LyAddLectores != null)
        LyAddLectores.setVisible(true);
}

From source file:de.schildbach.pte.AbstractEfaProvider.java

protected NearbyLocationsResult mobileCoordRequest(final EnumSet<LocationType> types, final int lat,
        final int lon, final int maxDistance, final int maxStations) throws IOException {
    final HttpUrl.Builder url = coordEndpoint.newBuilder();
    appendXmlCoordRequestParameters(url, types, lat, lon, maxDistance, maxStations);
    final AtomicReference<NearbyLocationsResult> result = new AtomicReference<>();

    final HttpClient.Callback callback = new HttpClient.Callback() {
        @Override/*from  ww w . j  a  v a 2  s .  co m*/
        public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException {
            try {
                final XmlPullParser pp = parserFactory.newPullParser();
                pp.setInput(body.byteStream(), null); // Read encoding from XML declaration
                final ResultHeader header = enterEfa(pp);

                XmlPullUtil.enter(pp, "ci");

                XmlPullUtil.enter(pp, "request");
                XmlPullUtil.skipExit(pp, "request");

                final List<Location> stations = new ArrayList<>();

                if (XmlPullUtil.optEnter(pp, "pis")) {
                    while (XmlPullUtil.optEnter(pp, "pi")) {
                        final String name = normalizeLocationName(XmlPullUtil.optValueTag(pp, "de", null));
                        final String type = XmlPullUtil.valueTag(pp, "ty");
                        final LocationType locationType;
                        if ("STOP".equals(type))
                            locationType = LocationType.STATION;
                        else if ("POI_POINT".equals(type))
                            locationType = LocationType.POI;
                        else
                            throw new IllegalStateException("unknown type: " + type);

                        final String id = XmlPullUtil.valueTag(pp, "id");
                        XmlPullUtil.valueTag(pp, "omc");
                        XmlPullUtil.optValueTag(pp, "pid", null);
                        final String place = normalizeLocationName(XmlPullUtil.valueTag(pp, "locality"));
                        XmlPullUtil.valueTag(pp, "layer");
                        XmlPullUtil.valueTag(pp, "gisID");
                        XmlPullUtil.valueTag(pp, "ds");
                        XmlPullUtil.valueTag(pp, "stateless");
                        final Point coord = parseCoord(XmlPullUtil.valueTag(pp, "c"));

                        final Location location;
                        if (name != null)
                            location = new Location(locationType, id, coord, place, name);
                        else
                            location = new Location(locationType, id, coord, null, place);
                        stations.add(location);

                        XmlPullUtil.skipExit(pp, "pi");
                    }

                    XmlPullUtil.skipExit(pp, "pis");
                }

                XmlPullUtil.skipExit(pp, "ci");

                result.set(new NearbyLocationsResult(header, stations));
            } catch (final XmlPullParserException x) {
                throw new ParserException("cannot parse xml: " + bodyPeek, x);
            }
        }
    };

    if (httpPost)
        httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(),
                "application/x-www-form-urlencoded", httpReferer);
    else
        httpClient.getInputStream(callback, url.build(), httpReferer);

    return result.get();
}

From source file:cl.gisred.android.RegEquipoActivity.java

private void cerrarDialogCrear(boolean bSave, @Nullable View viewDialog) {
    final AtomicReference<String> resp = new AtomicReference<>("");

    if (bSave) {//from ww  w .  j  a va  2  s  .c om
        if (!validarVista(viewDialog)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            switch (idResLayoutSelect) {
            case R.layout.dialog_poste:
                oLyAddGraphs = LyAddPoste;
                break;
            case R.layout.dialog_direccion:
                oLyAddGraphs = LyAddDireccion;
                break;
            case R.layout.dialog_cliente:
                oLyAddGraphs = LyAddCliente;
                break;
            case R.layout.dialog_cliente_cnr:
                oLyAddGraphs = LyAddClienteCnr;
                break;
            }

            if (oLyAddGraphs != null) {
                View oView = getLayoutValidate(viewDialog);
                Util oUtil = new Util(oUbicacion);

                ArrayList<Map<String, Object>> oAttrToSave = oUtil.getAttrAddByView(oView, idResLayoutSelect,
                        empresa);

                Map<String, Object> attributes = oAttrToSave.get(0);
                Graphic newFeatureGraphic = new Graphic(oUbicacion, null, attributes);
                Graphic[] adds = { newFeatureGraphic };

                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                        || idResLayoutSelect == R.layout.dialog_cliente) {
                    addsUnion = Util.addAttrUnionPoint(oAttrToSave, oUbicacion);
                }

                oLyAddGraphs.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {

                    @Override
                    public void onCallback(FeatureEditResult[][] featureEditResults) {
                        if (featureEditResults[0] != null) {
                            if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                                resp.set(
                                        "Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                                        || idResLayoutSelect == R.layout.dialog_cliente)
                                    LyAddUnion.applyEdits(addsUnion, null, null, callBackUnion());

                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Util.showConfirmation(RegEquipoActivity.this, resp.get());
                                    }
                                });
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        resp.set("Error al grabar: " + throwable.getLocalizedMessage());
                        Log.w("onError", resp.get());

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(RegEquipoActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                });
            }
        }
    } else {
        resp.set("Cancelado");
        Toast.makeText(RegEquipoActivity.this, resp.get(), Toast.LENGTH_LONG).show();
    }

    bMapTap = false;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    oUbicacion = null;
    if (bVerCapas)
        toogleCapas(fabVerCapas);
    //setLayerAddToggle(false);
    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMicroActions.setVisibility(View.VISIBLE);
    fabShowDialog.setVisibility(View.GONE);
    dialogCrear.dismiss();
    if (oLyAddGraphs != null)
        oLyAddGraphs.setVisible(true);
}

From source file:cl.gisred.android.MicroMedidaActivity.java

private void cerrarDialogCrear(boolean bSave, @Nullable View viewDialog) {
    final AtomicReference<String> resp = new AtomicReference<>("");

    if (bSave) {//from   ww  w  .j a v  a2s . co  m
        if (!validarVista(viewDialog)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            switch (idResLayoutSelect) {
            case R.layout.dialog_poste:
                oLyAddGraphs = LyAddPoste;
                break;
            case R.layout.dialog_direccion:
                oLyAddGraphs = LyAddDireccion;
                break;
            case R.layout.dialog_cliente:
                oLyAddGraphs = LyAddCliente;
                break;
            case R.layout.dialog_cliente_cnr:
                oLyAddGraphs = LyAddClienteCnr;
                break;
            }

            if (oLyAddGraphs != null) {
                View oView = getLayoutValidate(viewDialog);
                Util oUtil = new Util(oUbicacion);

                ArrayList<Map<String, Object>> oAttrToSave = oUtil.getAttrAddByView(oView, idResLayoutSelect,
                        empresa);

                Map<String, Object> attributes = oAttrToSave.get(0);
                Graphic newFeatureGraphic = new Graphic(oUbicacion, null, attributes);
                Graphic[] adds = { newFeatureGraphic };

                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                        || idResLayoutSelect == R.layout.dialog_cliente) {
                    addsUnion = Util.addAttrUnionPoint(oAttrToSave, oUbicacion);
                }

                oLyAddGraphs.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {

                    @Override
                    public void onCallback(FeatureEditResult[][] featureEditResults) {
                        if (featureEditResults[0] != null) {
                            if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                                resp.set(
                                        "Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                                        || idResLayoutSelect == R.layout.dialog_cliente)
                                    LyAddUnion.applyEdits(addsUnion, null, null, callBackUnion());

                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Util.showConfirmation(MicroMedidaActivity.this, resp.get());
                                    }
                                });
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        resp.set("Error al grabar: " + throwable.getLocalizedMessage());
                        Log.w("onError", resp.get());

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MicroMedidaActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                });
            }
        }
    } else {
        resp.set("Cancelado");
        Toast.makeText(MicroMedidaActivity.this, resp.get(), Toast.LENGTH_LONG).show();
    }

    bMapTap = false;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    oUbicacion = null;
    if (bVerCapas)
        toogleCapas(fabVerCapas);
    //setLayerAddToggle(false);
    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMicroActions.setVisibility(View.VISIBLE);
    fabShowDialog.setVisibility(View.GONE);
    dialogCrear.dismiss();
    if (oLyAddGraphs != null)
        oLyAddGraphs.setVisible(true);
}