Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008, 2010 VMware Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: VMware Inc. - initial contribution /
 
 
 package org.eclipse.virgo.kernel.model.internal;
 
 import java.util.Map;
 import java.util.Set;
 
 import  org.eclipse.equinox.region.Region;
An abstract implementation of org.eclipse.virgo.kernel.model.Artifact that all implementations should extend.

Implements getDependents() by delegating to DependencyDeterminer found in the service registry. The appropriate DependencyDeterminer is located by finding a a service with the property artifactType with the a value equal to the value of getType().

equals(java.lang.Object) and hashCode() are also implemented to guarantee that equality is based on the type, name, and version of the artifact.

Concurrent Semantics
Threadsafe and all subclasses should be threadsafe

 
 public abstract class AbstractArtifact implements Artifact {
 
     private static final String FILTER_FORMAT = "(&(objectClass=%s)(artifactType=%s))";
 
     private final String type;
 
     private final String name;
 
     private final Version version;
 
     private final ServiceTracker<DependencyDeterminerDependencyDeterminer> dependencyDeterminerTracker;
 
     private final Region region;
 
     public AbstractArtifact(@NonNull BundleContext bundleContext, @NonNull String type, @NonNull String name, @NonNull Version version, @NonNull Region region) {
         this. = type;
         this. = name;
         this. = version;
         this. = region;
 
         Filter filter;
         try {
             filter = bundleContext.createFilter(String.format(DependencyDeterminer.class.getCanonicalName(), type));
         } catch (InvalidSyntaxException e) {
             throw new RuntimeException(String.format("Cannot create Service Registry filter for a DependencyDeterminer of type '%s'"type), e);
         }
         this. = new ServiceTracker<DependencyDeterminerDependencyDeterminer>(bundleContextfilternull);
         this..open();
     }

    
 
     public final String getType() {
         return this.;
     }

    
 
     public final String getName() {
         return this.;
     }

    
 
     public final Version getVersion() {
         return this.;
     }

    
 
     @Override
    public final Region getRegion() {
        return this.;
    }

    
    public final Set<ArtifactgetDependents() {
        Set<Artifactdependents = new HashSet<Artifact>();
        Object[] dependencyDeterminers = this..getServices();
        if (dependencyDeterminers != null) {
            for (Object dependencyDeterminer : dependencyDeterminers) {
                dependents.addAll(((DependencyDeterminerdependencyDeterminer).getDependents(this));
            }
        }
        return Collections.unmodifiableSet(dependents);
    }

    
    public Map<StringStringgetProperties() {
        return Collections.<StringStringemptyMap();
    }

    
    @Override
    public final int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        return result;
    }

    
    @Override
    public final boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof AbstractArtifact))
            return false;
        AbstractArtifact other = (AbstractArtifactobj;
        if ( == null) {
            if (other.name != null)
                return false;
        } else if (!.equals(other.name))
            return false;
        if ( == null) {
            if (other.region != null)
                return false;
        } else if (!.equals(other.region))
            return false;
        if ( == null) {
            if (other.type != null)
                return false;
        } else if (!.equals(other.type))
            return false;
        if ( == null) {
            if (other.version != null)
                return false;
        } else if (!.equals(other.version))
            return false;
        return true;
    }
    @Override
    public String toString() {
        return String.format("type: %s, name: %s, version: %s, region: " + (this. == null ? "?" : this..getName()), this.this.,
            this..toString());
    }
New to GrepCode? Check out our FAQ X