Search in sources :

Example 76 with CheckForNull

use of javax.annotation.CheckForNull in project JMRI by JMRI.

the class StoreXmlConfigAction method getFileCustom.

/**
     * Do the filename handling:
     * <OL>
     * <LI>rescan directory to see any new files
     * <LI>Prompt user to select a file
     * <LI>adds .xml extension if needed
     * <LI>if that file exists, check with user
     * </OL>
     *
     * @param fileChooser the file chooser to use
     * @return the file to store or null if the user declined to store a file
     */
@CheckForNull
public static File getFileCustom(JFileChooser fileChooser) {
    fileChooser.rescanCurrentDirectory();
    int retVal = fileChooser.showDialog(null, null);
    if (retVal != JFileChooser.APPROVE_OPTION) {
        // give up if no file selected
        return null;
    }
    File file = fileChooser.getSelectedFile();
    if (fileChooser.getFileFilter() != fileChooser.getAcceptAllFileFilter()) {
        // append .xml to file name if needed
        String fileName = file.getAbsolutePath();
        String fileNameLC = fileName.toLowerCase();
        if (!fileNameLC.endsWith(".xml")) {
            fileName = fileName + ".xml";
            file = new File(fileName);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Save file: " + file.getPath());
    }
    // check for possible overwrite
    if (file.exists()) {
        int selectedValue = JOptionPane.showConfirmDialog(null, Bundle.getMessage("FileOverwriteWarning", file.getName()), Bundle.getMessage("OverwriteFile"), JOptionPane.OK_CANCEL_OPTION);
        if (selectedValue != JOptionPane.OK_OPTION) {
            return null;
        }
    }
    return file;
}
Also used : File(java.io.File) CheckForNull(javax.annotation.CheckForNull)

Example 77 with CheckForNull

use of javax.annotation.CheckForNull in project JMRI by JMRI.

the class LayoutBlock method getNextBlock.

/**
     * Used if we already know the block prior to our block, and the destination
     * block. direction, is optional and is used where the previousBlock is
     * equal to our block.
     */
@CheckForNull
public Block getNextBlock(Block previousBlock, Block destBlock) {
    int bestMetric = 965000;
    Block bestBlock = null;
    for (Routes r : routes) {
        if (r.getDestBlock() == destBlock) {
            //Check that the route through from the previous block, to the next hop is valid
            if (validThroughPath(previousBlock, r.getNextBlock())) {
                if (r.getMetric() < bestMetric) {
                    bestMetric = r.getMetric();
                    //bestBlock=r.getDestBlock();
                    bestBlock = r.getNextBlock();
                }
            }
        }
    }
    return bestBlock;
}
Also used : Block(jmri.Block) CheckForNull(javax.annotation.CheckForNull)

Example 78 with CheckForNull

use of javax.annotation.CheckForNull in project sling by apache.

the class SimpleDistributionQueue method remove.

@CheckForNull
public DistributionQueueEntry remove(@Nonnull String id) {
    DistributionQueueEntry toRemove = getItem(id);
    boolean removed = false;
    if (toRemove != null) {
        removed = queue.remove(toRemove.getItem());
    }
    log.debug("item with id {} removed from the queue: {}", id, removed);
    if (removed) {
        return toRemove;
    } else {
        return null;
    }
}
Also used : DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) CheckForNull(javax.annotation.CheckForNull)

Example 79 with CheckForNull

use of javax.annotation.CheckForNull in project sling by apache.

the class AbstractDistributionPackageBuilder method getPackage.

@CheckForNull
public DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String id) {
    DistributionPackage distributionPackage = SimpleDistributionPackage.fromIdString(id, type);
    // not a simple package
    if (distributionPackage == null) {
        if (id.startsWith("reference")) {
            String localId = id.substring("reference-".length());
            distributionPackage = new ReferencePackage(getPackageInternal(resourceResolver, localId));
        } else {
            distributionPackage = getPackageInternal(resourceResolver, id);
        }
    }
    return distributionPackage;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) CheckForNull(javax.annotation.CheckForNull)

Example 80 with CheckForNull

use of javax.annotation.CheckForNull in project sling by apache.

the class OsgiInstallerImpl method getInstallationState.

/**
     * @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
     */
@Override
public InstallationState getInstallationState() {
    synchronized (this.resourcesLock) {
        final InstallationState state = new InstallationState() {

            private final List<ResourceGroup> activeResources = new ArrayList<>();

            private final List<ResourceGroup> installedResources = new ArrayList<>();

            private final List<RegisteredResource> untransformedResources = new ArrayList<>();

            @Override
            public List<ResourceGroup> getActiveResources() {
                return activeResources;
            }

            @Override
            public List<ResourceGroup> getInstalledResources() {
                return installedResources;
            }

            @Override
            public List<RegisteredResource> getUntransformedResources() {
                return untransformedResources;
            }

            @Override
            public String toString() {
                return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
            }
        };
        for (final String entityId : this.persistentList.getEntityIds()) {
            if (!this.persistentList.isSpecialEntityId(entityId)) {
                final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
                final String alias = group.getAlias();
                final List<Resource> resources = new ArrayList<>();
                boolean first = true;
                boolean isActive = false;
                for (final TaskResource tr : group.getResources()) {
                    final ResourceState resourceState = tr.getState();
                    if (first) {
                        if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
                            isActive = true;
                        }
                        first = false;
                    }
                    resources.add(new Resource() {

                        @Override
                        public String getScheme() {
                            return tr.getScheme();
                        }

                        @Override
                        public String getURL() {
                            return tr.getURL();
                        }

                        @Override
                        public String getType() {
                            return tr.getType();
                        }

                        @Override
                        public InputStream getInputStream() throws IOException {
                            return tr.getInputStream();
                        }

                        @Override
                        public Dictionary<String, Object> getDictionary() {
                            return tr.getDictionary();
                        }

                        @Override
                        public String getDigest() {
                            return tr.getDigest();
                        }

                        @Override
                        public int getPriority() {
                            return tr.getPriority();
                        }

                        @Override
                        public String getEntityId() {
                            return tr.getEntityId();
                        }

                        @Override
                        public ResourceState getState() {
                            return resourceState;
                        }

                        @Override
                        public Version getVersion() {
                            return tr.getVersion();
                        }

                        @Override
                        public long getLastChange() {
                            return ((RegisteredResourceImpl) tr).getLastChange();
                        }

                        @Override
                        public Object getAttribute(final String key) {
                            return tr.getAttribute(key);
                        }

                        @Override
                        @CheckForNull
                        public String getError() {
                            return tr.getError();
                        }

                        @Override
                        public String toString() {
                            return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
                        }
                    });
                }
                final ResourceGroup rg = new ResourceGroup() {

                    @Override
                    public List<Resource> getResources() {
                        return resources;
                    }

                    @Override
                    public String getAlias() {
                        return alias;
                    }

                    @Override
                    public String toString() {
                        return "group[" + resources + "]";
                    }
                };
                if (isActive) {
                    state.getActiveResources().add(rg);
                } else {
                    state.getInstalledResources().add(rg);
                }
            }
        }
        Collections.sort(state.getActiveResources(), COMPARATOR);
        Collections.sort(state.getInstalledResources(), COMPARATOR);
        state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
        return state;
    }
}
Also used : Dictionary(java.util.Dictionary) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) InputStream(java.io.InputStream) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) ArrayList(java.util.ArrayList) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Resource(org.apache.sling.installer.api.info.Resource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) InstallableResource(org.apache.sling.installer.api.InstallableResource) IOException(java.io.IOException) InstallationState(org.apache.sling.installer.api.info.InstallationState) Version(org.osgi.framework.Version) CheckForNull(javax.annotation.CheckForNull) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResourceState(org.apache.sling.installer.api.tasks.ResourceState) TaskResourceGroup(org.apache.sling.installer.api.tasks.TaskResourceGroup) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4