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.wsdl.model.ReferenceableWSDLComponent;
022: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
023: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
024: import org.netbeans.modules.xslt.tmap.model.api.WSDLReference;
025: import org.netbeans.modules.xslt.tmap.model.impl.AttributesType.AttrType;
026:
027: /**
028: * @author ads
029: * @author Vitaly Bychkov
030: * @version 1.0
031: */
032: public class GlobalWSDLReferenceImpl<T extends ReferenceableWSDLComponent>
033: extends AbstractNamedComponentReference<T> implements
034: NamedComponentReference<T>, WSDLReference<T> {
035:
036: //// public GlobalWSDLReferenceImpl(
037: //// T referenced,
038: //// Class<T> type,
039: //// AbstractDocumentComponent parent) {
040: //// super(referenced, type, parent);
041: //// }
042: ////
043: //// public GlobalWSDLReferenceImpl(
044: //// Class<T> type,
045: //// AbstractDocumentComponent parent,
046: //// String refString){
047: //// super(type, parent, refString);
048: //// }
049: ////
050: //// // impl getted from org.netbeans.modules.xml.wsdl.model.impl#GlobalReferenceImpl
051: //// public T get() {
052: //// WSDLComponentBase wparent = WSDLComponentBase.class.cast(getParent());
053: //// if (super.getReferenced() == null) {
054: //// String localName = getLocalName();
055: //// String namespace = getEffectiveNamespace();
056: //// WSDLModel model = wparent.getWSDLModel();
057: //// T target = null;
058: //// if (namespace != null && namespace.equals(model.getDefinitions().getTargetNamespace())) {
059: //// target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType());
060: //// }
061: //// if (target == null) {
062: //// for (Import i : wparent.getWSDLModel().getDefinitions().getImports()) {
063: //// if (! i.getNamespace().equals(namespace)) {
064: //// continue;
065: //// }
066: //// try {
067: //// model = i.getImportedWSDLModel();
068: //// } catch(CatalogModelException ex) {
069: //// continue;
070: //// }
071: //// target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType());
072: //// if (target != null) {
073: //// break;
074: //// }
075: //// }
076: //// }
077: //// setReferenced(target);
078: //// }
079: //// return getReferenced();
080: //// }
081: ////
082: //// public WSDLComponentBase getParent() {
083: //// return (WSDLComponentBase) super.getParent();
084: //// }
085: ////
086: //// public String getEffectiveNamespace() {
087: //// if (refString == null) {
088: //// assert getReferenced() != null;
089: //// return getReferenced().getModel().getDefinitions().getTargetNamespace();
090: //// } else {
091: //// return getParent().lookupNamespaceURI(getPrefix());
092: //// }
093: //// }
094: //////
095: ////
096: //// /* (non-Javadoc)
097: //// * @see org.netbeans.modules.bpel.model.impl.references.BpelAttributesType#getAttributeType()
098: //// */
099: //// public AttrType getAttributeType() {
100: //// return AttrType.QNAME;
101: //// }
102: GlobalWSDLReferenceImpl(Class<T> type,
103: AbstractDocumentComponent parent, String refString,
104: WSDLReferenceBuilder.WSDLResolver resolver) {
105: super (type, parent, refString);
106: myResolver = resolver;
107: }
108:
109: GlobalWSDLReferenceImpl(T target, Class<T> type,
110: AbstractDocumentComponent parent,
111: WSDLReferenceBuilder.WSDLResolver resolver) {
112: super (target, type, parent);
113: myResolver = resolver;
114: }
115:
116: /* (non-Javadoc)
117: * @see org.netbeans.modules.xml.xam.Reference#get()
118: */
119: public T get() {
120: if (getReferenced() == null) {
121: T ret = myResolver.resolve(this );
122: setReferenced(ret);
123: return ret;
124: }
125: return getReferenced();
126: }
127:
128: /* (non-Javadoc)
129: * @see org.netbeans.modules.xml.xam.NamedComponentReference#getEffectiveNamespace()
130: */
131: public String getEffectiveNamespace() {
132: /*
133: * Note : refString is not MAIN data in reference.
134: * Reference could be created by existed element.
135: * In this case namespace should be asked at this element.
136: * Parent element could not have any prefix for this namepace yet.
137: *
138: * Otherwise - element was DEFENITLEY created via
139: * reference. And in this case we can try to ask
140: * namespace via prefix at parent element.
141: */
142: if (isBroken()) {
143: assert refString != null;
144: return ((TMapComponentAbstract) getParent())
145: .getNamespaceContext().getNamespaceURI(getPrefix());
146: } else {
147: return getReferenced().getModel().getDefinitions()
148: .getTargetNamespace();
149: }
150: }
151:
152: /* (non-Javadoc)
153: * @see org.netbeans.modules.bpel.model.impl.references.BpelAttributesType#getAttributeType()
154: */
155: public AttrType getAttributeType() {
156: return AttrType.QNAME;
157: }
158:
159: private WSDLReferenceBuilder.WSDLResolver myResolver;
160: }
|