001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.node.protocol;
020
021import org.jppf.location.Location;
022
023/**
024 * A simple implementation of the {@link ClassPathElement} interface.
025 * @author Laurent Cohen
026 */
027public class ClassPathElementImpl implements ClassPathElement {
028  /**
029   * Explicit serialVersionUID.
030   */
031  private static final long serialVersionUID = 1L;
032  /**
033   * The location of this classpath element in the client environment.
034   */
035  protected final Location<?> localLocation;
036  /**
037   * The location of this classpath element in the node environment.
038   */
039  protected final Location<?> remoteLocation;
040  /**
041   * The name of this classpath element.
042   */
043  protected final String name;
044
045  /**
046   * Initialize this classpath element with the specified name and local location.
047   * The remote location is set to the same location.
048   * @param name the name of this classpath element.
049   * @param location the location of this classpath element.
050   */
051  protected ClassPathElementImpl(final String name, final Location<?> location) {
052    this.name = name;
053    this.localLocation = location;
054    this.remoteLocation = this.localLocation;
055  }
056
057  /**
058   * Initialize this classpath element with the specified name and local location.
059   * The remote location is set to the same location.
060   * @param name the name of this classpath element.
061   * @param localLocation the location of this classpath element in the client environment.
062   * @param remoteLocation the location of this classpath element in the node environment.
063   */
064  protected ClassPathElementImpl(final String name, final Location<?> localLocation, final Location<?> remoteLocation) {
065    this.name = name;
066    this.localLocation = localLocation;
067    this.remoteLocation = remoteLocation;
068  }
069
070  @Override
071  public String getName() {
072    return name;
073  }
074
075  @Override
076  public Location<?> getLocalLocation() {
077    return localLocation;
078  }
079
080  @Override
081  public Location<?> getRemoteLocation() {
082    return remoteLocation;
083  }
084
085  /**
086   * This default implementation always return true.
087   * @return <code>true</code>.
088   */
089  @Override
090  public boolean validate() {
091    return true;
092  }
093
094  @Override
095  public String toString() {
096    return name;
097  }
098}