001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.mapper.multiview;
021:
022: import java.lang.ref.WeakReference;
023: import org.netbeans.modules.bpel.model.api.BpelEntity;
024: import org.netbeans.modules.bpel.model.api.BpelModel;
025: import org.openide.nodes.Node;
026: import org.openide.util.Lookup;
027:
028: /**
029: * Immutable holder of the current state of the BPEL mapper.
030: *
031: * @author Vitaly Bychkov
032: */
033: public class BpelDesignContextImpl implements BpelDesignContext {
034:
035: private WeakReference<Node> mActivatedNode;
036: private Lookup mLookup;
037: private WeakReference<BpelEntity> mSelectedEntityRef;
038: private WeakReference<BpelEntity> mGraphEntityRef;
039: private WeakReference<BpelEntity> mContextEntityRef;
040: private String mMessage;
041:
042: public BpelDesignContextImpl(BpelEntity contextEntity,
043: BpelEntity graphEntity, BpelEntity selectedEntity,
044: Node node, Lookup lookup) {
045: mActivatedNode = new WeakReference<Node>(node);
046: mLookup = lookup;
047: mContextEntityRef = new WeakReference<BpelEntity>(contextEntity);
048: mGraphEntityRef = new WeakReference<BpelEntity>(graphEntity);
049: mSelectedEntityRef = new WeakReference<BpelEntity>(
050: selectedEntity);
051: }
052:
053: public BpelDesignContextImpl(String message) {
054: this (null, null, null, null, null);
055: mMessage = message;
056: }
057:
058: public BpelEntity getContextEntity() {
059: return mContextEntityRef.get();
060: }
061:
062: public BpelEntity getGraphEntity() {
063: BpelEntity result = mGraphEntityRef.get();
064: if (result != null) {
065: if (result.isInDocumentModel()) {
066: return result;
067: }
068: }
069: return getContextEntity();
070: }
071:
072: public BpelEntity getSelectedEntity() {
073: BpelEntity result = mSelectedEntityRef.get();
074: if (result != null) {
075: if (result.isInDocumentModel()) {
076: return result;
077: }
078: }
079: return getGraphEntity();
080: }
081:
082: public Node getActivatedNode() {
083: return mActivatedNode.get();
084: }
085:
086: public Lookup getLookup() {
087: return mLookup;
088: }
089:
090: public BpelModel getBpelModel() {
091: if (mContextEntityRef != null) {
092: BpelEntity entity = mContextEntityRef.get();
093: if (entity != null) {
094: return entity.getBpelModel();
095: }
096: }
097: return null;
098: }
099:
100: @Override
101: public String toString() {
102: return "ContextEntity: " + mContextEntityRef + "GraphEntity: "
103: + mGraphEntityRef + "SelectedEntity: "
104: + mSelectedEntityRef + " Lookup: " + mLookup; // NOI18N
105: }
106:
107: @Override
108: public boolean equals(Object otherObj) {
109: if (otherObj instanceof BpelDesignContext) {
110: BpelDesignContext otherContext = (BpelDesignContext) otherObj;
111: if (otherContext.getContextEntity() == getContextEntity()
112: && otherContext.getGraphEntity() == getGraphEntity()
113: && otherContext.getSelectedEntity() == getSelectedEntity()
114: && otherContext.getLookup() == getLookup()) {
115: return true;
116: }
117: }
118: return false;
119: }
120:
121: public String getMessage() {
122: return mMessage;
123: }
124:
125: }
|