Package edu.isi.karma.rep.alignment

Source Code of edu.isi.karma.rep.alignment.LabeledLink

/*******************************************************************************
* Copyright 2012 University of Southern California
*
* 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.
*
* This code was developed by the Information Integration Group as part
* of the Karma project at the Information Sciences Institute of the
* University of Southern California.  For more information, publications,
* and related projects, please see: http://www.isi.edu/integration
******************************************************************************/
package edu.isi.karma.rep.alignment;

import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rits.cloning.Cloner;


public abstract class LabeledLink extends DefaultLink {
 
  private static final long serialVersionUID = 1L;
  static Logger logger = LoggerFactory.getLogger(LabeledLink.class);

  private Label label;
  private LinkStatus status;
  private LinkKeyInfo keyInfo;
  private Set<String> modelIds;
 
  public LabeledLink(String id, Label label, LinkType type) {
    super(id, type);
   
    init();
    if (label != null) this.label = label;
  }
 
  public LabeledLink(String id, Label label, LinkType type, LinkKeyInfo keyInfo) {
    super(id, type);

    this.init();
    if (label != null) this.label = label;
    if (keyInfo != null) this.keyInfo = keyInfo;
  }
 
  public LabeledLink(LabeledLink e) {
    super(e);
    if (e == null) this.init();
    else {
      this.label = e.label;
      this.status = e.status;
      this.keyInfo = e.keyInfo;
    }
  }
 
  private void init() {
    Label l = null;
    this.label = new Label(l);
    this.status = LinkStatus.Normal;
    this.keyInfo = LinkKeyInfo.None;
    this.modelIds = new HashSet<String>();
  }
 
  public Label getLabel() {
    return this.label;
  }
 
  public String getUri() {
    if (this.label != null)
      return this.getLabel().getUri();
    return null;
  }
 
  public String getLocalId() {
   
    String s = this.id;

    if (this.label.getNs() != null)
      s = s.replaceAll(this.label.getNs(), "");
   
    return s;
  }
 
  public String getDisplayId() {
   
    if (this.label.getPrefix() == null)
      return this.getLocalId();
   
    return this.label.getPrefix() + ":" + this.getLocalId();
  }
 
  public LinkStatus getStatus() {
    return status;
  }

  public void setStatus(LinkStatus status) {
    this.status = status;
  }

  public LinkKeyInfo getKeyType() {
    return keyInfo;
  }

  public void setKeyType(LinkKeyInfo keyType) {
    this.keyInfo = keyType;
  }
 
  public Set<String> getModelIds() {
    return modelIds;
  }

  public void setModelIds(Set<String> patternIds) {
    this.modelIds = patternIds;
  }

    public LabeledLink clone() {
     
      Cloner cloner = new Cloner();
      return cloner.deepClone(this);
    }

    public LabeledLink copy(String newId) {
     
    LabeledLink newLink = null;
    Label label = this.getLabel();
    if (this instanceof DataPropertyLink)
      newLink = new DataPropertyLink(newId, label);
    else if (this instanceof ObjectPropertyLink)
      newLink = new ObjectPropertyLink(newId, label, ((ObjectPropertyLink)this).getObjectPropertyType());
    else if (this instanceof SubClassLink)
      newLink = new SubClassLink(newId);
    else if (this instanceof ClassInstanceLink)
      newLink = new ClassInstanceLink(newId, this.getKeyType());
    else if (this instanceof ColumnSubClassLink)
      newLink = new ColumnSubClassLink(newId);
    else if (this instanceof DataPropertyOfColumnLink)
      newLink = new DataPropertyOfColumnLink(newId,
          ((DataPropertyOfColumnLink)this).getSpecializedColumnHNodeId(),
          ((DataPropertyOfColumnLink)this).getSpecializedLinkId()
          );
    else if (this instanceof ObjectPropertySpecializationLink)
      newLink = new ObjectPropertySpecializationLink(newId, ((ObjectPropertySpecializationLink)this).getSpecializedLinkId());
    else
      logger.error("cannot instanciate a link from the type: " + this.getType().toString());
   
    newLink.setStatus(this.getStatus());
    newLink.setModelIds(this.getModelIds());
    newLink.setKeyType(this.getKeyType());
   
    return newLink;
    }
}
TOP

Related Classes of edu.isi.karma.rep.alignment.LabeledLink

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.