01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.bpel.editors.api.utils;
20:
21: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
22: import org.netbeans.modules.xml.xam.Component;
23: import org.netbeans.modules.xml.xam.Named;
24: import org.netbeans.modules.xml.xam.dom.DocumentComponent;
25:
26: /**
27: *
28: * @author Vitaly
29: * @version 1.0
30: */
31: public interface HtmlNameManager {
32: boolean accept(NodeType nodeType, Object reference);
33:
34: String getHtmlName(NodeType nodeType, Object reference);
35:
36: final HtmlNameManager[] HTML_NAME_MANAGERS = new HtmlNameManager[] { new ShortHtmlNameManager() };
37:
38: class ShortHtmlNameManager implements HtmlNameManager {
39: public boolean accept(NodeType nodeType, Object reference) {
40: return reference instanceof Component;
41: }
42:
43: public String getHtmlName(NodeType nodeType, Object reference) {
44: if (!accept(nodeType, reference)) {
45: return null;
46: }
47:
48: String refName = null;
49: if (reference instanceof Named) {
50: refName = ((Named) reference).getName();
51: }
52:
53: if (refName == null && nodeType != null
54: && !NodeType.UNKNOWN_TYPE.equals(nodeType)) {
55: refName = nodeType.getDisplayName();
56: }
57:
58: if (refName == null
59: && reference instanceof DocumentComponent) {
60: refName = org.netbeans.modules.bpel.editors.api.utils.Util
61: .getTagName((DocumentComponent) reference);
62: }
63:
64: refName = refName == null ? "" : refName;
65:
66: return org.netbeans.modules.bpel.editors.api.utils.Util
67: .getCorrectedHtmlRenderedString(refName);
68: }
69: }
70:
71: class Util {
72: private Util() {
73: }
74: }
75:
76: }
|