KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > impl > GlobalReferenceImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.impl;
21
22 import org.netbeans.modules.xml.wsdl.model.Definitions;
23 import org.netbeans.modules.xml.wsdl.model.Import;
24 import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent;
25 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
26 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase;
27 import org.netbeans.modules.xml.wsdl.model.visitor.FindReferencedVisitor;
28 import org.netbeans.modules.xml.xam.dom.AbstractNamedComponentReference;
29 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
30 import org.netbeans.modules.xml.xam.locator.CatalogModelException;
31
32 /**
33  *
34  * @author Nam Nguyen
35  * @author rico
36  */

37 public class GlobalReferenceImpl<T extends ReferenceableWSDLComponent>
38         extends AbstractNamedComponentReference<T> implements NamedComponentReference<T> {
39     
40     /** Creates a new instance of GlobalReferenceImpl */
41     //for use by factory, create from scratch
42
public GlobalReferenceImpl(
43             T referenced,
44             Class JavaDoc<T> type,
45             WSDLComponentBase parent) {
46         super(referenced, type, parent);
47     }
48     
49     //for use by resolve methods
50
public GlobalReferenceImpl(
51             Class JavaDoc<T> type,
52             WSDLComponentBase parent,
53             String JavaDoc refString){
54         super(type, parent, refString);
55     }
56     
57     protected Definitions getDefinitions() {
58         WSDLComponentBase wparent = WSDLComponentBase.class.cast(getParent());
59         return wparent.getModel().getDefinitions();
60     }
61     
62     public T get() {
63         WSDLComponentBase wparent = WSDLComponentBase.class.cast(getParent());
64         if (super.getReferenced() == null) {
65             String JavaDoc localName = getLocalName();
66             String JavaDoc namespace = getEffectiveNamespace();
67             WSDLModel model = wparent.getWSDLModel();
68             T target = null;
69             if (namespace != null && namespace.equals(model.getDefinitions().getTargetNamespace())) {
70                 target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType());
71             }
72             if (target == null) {
73                 for (Import i : wparent.getWSDLModel().getDefinitions().getImports()) {
74                     if (! i.getNamespace().equals(namespace)) {
75                         continue;
76                     }
77                     try {
78                         model = i.getImportedWSDLModel();
79                     } catch(CatalogModelException ex) {
80                         continue;
81                     }
82                     target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType());
83                     if (target != null) {
84                         break;
85                     }
86                 }
87             }
88             setReferenced(target);
89         }
90         return getReferenced();
91     }
92     
93     public WSDLComponentBase getParent() {
94         return (WSDLComponentBase) super.getParent();
95     }
96     
97     public String JavaDoc getEffectiveNamespace() {
98         if (refString == null) {
99             assert getReferenced() != null;
100             return getReferenced().getModel().getDefinitions().getTargetNamespace();
101         } else {
102             return getParent().lookupNamespaceURI(getPrefix());
103         }
104     }
105 }
106
Popular Tags