X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fsubscription%2FFindSubscription.java;h=916adca9f37aa751b7b0f05d1a7fe0496c11bb98;hb=76061fee3ffb1b66ed4d78ce711ab44f38b7ffdf;hp=06905d2eb9e1222e76d4ac5c40a27acbe09e3234;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/FindSubscription.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/FindSubscription.java index 06905d2eb..916adca9f 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/FindSubscription.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/FindSubscription.java @@ -1,84 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.subscription; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.utils.ObjectUtils; - -/** - * This query finds subscription using label as keyword. - * If multiple subscriptions have the - * - * @author toni.kalajainen - */ -public class FindSubscription extends UniqueRead { - - Resource model; - String id, label; - - public FindSubscription( Resource model, String id, String label ) - { - this.model = model; - this.id = id; - this.label = label; - } - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - ModelingResources MOD = ModelingResources.getInstance(graph); - - for (Resource r : graph.getObjects(model, L0.ConsistsOf)) - { - if ( !graph.isInstanceOf(r, MOD.Subscription) ) continue; - - if ( this.id!=null ) { - String name = graph.getPossibleRelatedValue(r, L0.HasName); - if ( !name.equals(this.id)) continue; - } - - if ( this.label!=null ) { - String label = graph.getPossibleRelatedValue(r, L0.HasLabel); - if ( !label.equals(this.label)) continue; - } - - return r; - } - - return null; - } - - @Override - public int hashCode() { - return model.hashCode() + (id!=null?id.hashCode():0) + (label!=null?label.hashCode():0); - } - - @Override - public boolean equals(Object object) { - if (this == object) return true; - if (object == null) return false; - if (getClass() != object.getClass()) return false; - FindSubscription r = (FindSubscription) object; - - if ( !ObjectUtils.objectEquals(id, r.id) ) return false; - if ( !ObjectUtils.objectEquals(label, r.label)) return false; - - return true; - } - - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.subscription; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.utils.ObjectUtils; + +/** + * This query finds subscription using label as keyword. + * If multiple subscriptions have the + * + * @author toni.kalajainen + */ +public class FindSubscription extends UniqueRead { + + Resource model; + String id, label; + + public FindSubscription( Resource model, String id, String label ) + { + this.model = model; + this.id = id; + this.label = label; + } + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + + for (Resource r : graph.getObjects(model, L0.ConsistsOf)) + { + if ( !graph.isInstanceOf(r, MOD.Subscription) ) continue; + + if ( this.id!=null ) { + String name = graph.getPossibleRelatedValue(r, L0.HasName); + if ( !name.equals(this.id)) continue; + } + + if ( this.label!=null ) { + String label = graph.getPossibleRelatedValue(r, L0.HasLabel); + if ( !label.equals(this.label)) continue; + } + + return r; + } + + return null; + } + + @Override + public int hashCode() { + return model.hashCode() + (id!=null?id.hashCode():0) + (label!=null?label.hashCode():0); + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null) return false; + if (getClass() != object.getClass()) return false; + FindSubscription r = (FindSubscription) object; + + if ( !ObjectUtils.objectEquals(id, r.id) ) return false; + if ( !ObjectUtils.objectEquals(label, r.label)) return false; + + return true; + } + + +}