KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xslt > model > impl > AttributeValueTemplateImpl


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xslt.model.impl;
20
21 import javax.xml.namespace.QName JavaDoc;
22
23 import org.netbeans.modules.xslt.model.AttributeValueTemplate;
24
25
26 /**
27  * @author ads
28  *
29  */

30 class AttributeValueTemplateImpl implements AttributeValueTemplate {
31     
32     AttributeValueTemplateImpl( XslComponentImpl parent, String JavaDoc value ) {
33         assert value!=null;
34         assert parent!=null;
35         
36         myValue = value;
37         myParent = parent;
38         int begin = myValue.indexOf( "{" );
39         if ( begin > -1 ) {
40             isTemplate = myValue.indexOf( "}" ) > begin;
41         }
42         else {
43             isTemplate = false;
44         }
45     }
46     
47     AttributeValueTemplateImpl( QName JavaDoc qName ) {
48         myQName = qName;
49         isTemplate = false;
50         String JavaDoc localPart = qName.getLocalPart();
51         //String ns = qName.getNamespaceURI();
52
String JavaDoc prefix = qName.getPrefix();
53         if ( prefix == null || prefix.length() == 0) {
54             myValue = localPart;
55         }
56         else {
57             myValue = prefix + ":" +localPart;
58         }
59     }
60
61     /* (non-Javadoc)
62      * @see org.netbeans.modules.xslt.model.AttributeValueTemplate#getQName()
63      */

64     public QName JavaDoc getQName() {
65         if ( myQName != null ) {
66             return myQName;
67         }
68         else {
69             return QNameBuilder.createQName( getParent(), toString() );
70         }
71     }
72
73     /* (non-Javadoc)
74      * @see org.netbeans.modules.xslt.model.AttributeValueTemplate#isTemplate()
75      */

76     public boolean isTemplate() {
77         return isTemplate;
78     }
79     
80     /* (non-Javadoc)
81      * @see java.lang.Object#toString()
82      */

83     @Override JavaDoc
84     public String JavaDoc toString()
85     {
86         return myValue;
87     }
88     
89     public static AttributeValueTemplateImpl creatAttributeValueTemplate(
90             XslComponentImpl parent, XslAttributes attr )
91     {
92         String JavaDoc str = parent.getAttribute( attr );
93         return creatAttributeValueTemplate( parent , str );
94     }
95     
96     public static AttributeValueTemplateImpl creatAttributeValueTemplate(
97             XslComponentImpl parent, String JavaDoc value )
98     {
99         if ( value == null ) {
100             return null;
101         }
102         return new AttributeValueTemplateImpl( parent , value );
103     }
104     
105     public static AttributeValueTemplateImpl creatAttributeValueTemplate(
106             QName JavaDoc qName )
107     {
108         return new AttributeValueTemplateImpl( qName );
109     }
110     
111     private XslComponentImpl getParent() {
112         return myParent;
113     }
114
115     private XslComponentImpl myParent;
116     
117     private String JavaDoc myValue;
118     
119     private boolean isTemplate;
120     
121     private QName JavaDoc myQName;
122     
123 }
124
Popular Tags