ws.ladder.model.Edge Maven / Gradle / Ivy
/**
* Ladder, empowering Model Driven Architecture in J2EE applications
*
* Copyright (c) 2012, Dilip Dalton
*
* 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.
*/
package ws.ladder.model;
public final class Edge {
final Node source;
final Node target;
final Property property;
public Edge(Node source, Node target, Property property) {
this.source = source;
this.target = target;
this.property = property;
}
public Property getProperty() {
return property;
}
public Node getSource() {
return source;
}
public Node getTarget() {
return target;
}
public boolean isRequired() {
return AbstractProperty.isRequired( property );
}
public boolean isCascaded() {
return AbstractProperty.isCascadable( property );
}
public boolean fromTransient() {
boolean result = !getSource().isPersistent();
// Check the owner of the collection
if(property == null) {
Node collection = getSource();
if(collection.getIncoming().size() == 1) {
Edge edgeFromOwner = collection.getIncoming().iterator().next();
result = !edgeFromOwner.source.isPersistent();
}
}
return result;
}
public boolean toTransient() {
return !getTarget().isPersistent();
}
public void link() {
target.addIncomingEdge(this);
source.addOutgoingEdge(this);
}
public void unlink() {
target.removeIncomingEdge(this);
source.removeOutgoingEdge(this);
}
public void disconnect() {
((ExtendedProperty)property).setValue(source, null);
unlink();
}
public void connect() {
link();
((ExtendedProperty)property).setValue(source, target.getInstance());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 0;
result = prime * result + ((source == null) ? 0 : System.identityHashCode(source));
result = prime * result + ((target == null) ? 0 : System.identityHashCode(target));
result = prime * result + ((property == null) ? 0 : System.identityHashCode(property));
return result;
}
@Override
public boolean equals(Object obj) {
if(obj == null)
return false;
if (this == obj)
return true;
if (getClass() != obj.getClass())
return false;
Edge other = (Edge) obj;
return source == other.source &&
target == other.target &&
property == other.property;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy