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: package org.netbeans.modules.xslt.tmap.model.impl;
020:
021: import org.netbeans.modules.xml.xam.AbstractComponent;
022: import org.netbeans.modules.xml.xam.dom.Attribute;
023: import org.netbeans.modules.xslt.tmap.model.api.MappedReference;
024: import org.netbeans.modules.xslt.tmap.model.api.TMapReference;
025: import org.netbeans.modules.xslt.tmap.model.api.TMapReferenceable;
026:
027: /**
028: *
029: * @author Vitaly Bychkov
030: * @version 1.0
031: */
032: public class TMapReferenceImpl<T extends TMapReferenceable> extends
033: AbstractReference<T> implements TMapReference<T>,
034: MappedReference {
035:
036: private Attribute myAttribute;
037: private TMapReferenceBuilder.TMapResolver myResolver;
038: private boolean isResolved;
039:
040: TMapReferenceImpl(T target, Class<T> type,
041: AbstractComponent parent, String value,
042: TMapReferenceBuilder.TMapResolver resolver) {
043: super (type, parent, value);
044: setReferenced(target);
045: myResolver = resolver;
046: if (target != null) {
047: setResolved();
048: }
049: }
050:
051: TMapReferenceImpl(Class<T> type, AbstractComponent parent,
052: String value, TMapReferenceBuilder.TMapResolver resolver) {
053: super (type, parent, value);
054: myResolver = resolver;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.netbeans.modules.xml.xam.Reference#get()
059: */
060: public T get() {
061: if (getReferenced() == null) {
062: T ret = myResolver.resolve(this );
063: setReferenced(ret);
064: return ret;
065: }
066: return getReferenced();
067: }
068:
069: /* (non-Javadoc)
070: * @see org.netbeans.modules.bpel.model.api.references.Reference#isResolved()
071: */
072: public boolean isResolved() {
073: return isResolved;
074: }
075:
076: /* (non-Javadoc)
077: * @see org.netbeans.modules.xml.xam.AbstractReference#references(T)
078: */
079: @Override
080: public boolean references(T component) {
081: if (!myResolver.haveRefString(this , component)) {
082: return false;
083: }
084: return super .references(component);
085: }
086:
087: /* (non-Javadoc)
088: * @see org.netbeans.modules.xslt.tmap.model.api.MappedReference#getAttribute()
089: */
090: public Attribute getAttribute() {
091: return myAttribute;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.netbeans.modules.xslt.tmap.model.api.MappedReference#setAttribute(org.netbeans.modules.xml.xam.dom.Attribute)
096: */
097: public void setAttribute(Attribute attr) {
098: myAttribute = attr;
099: }
100:
101: protected void setResolved() {
102: isResolved = true;
103: }
104:
105: @Override
106: protected void setReferenced(T referenced) {
107: super.setReferenced(referenced);
108: if (referenced != null) {
109: setResolved();
110: }
111: }
112: }
|