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.model.impl;
020:
021: import javax.xml.namespace.QName;
022:
023: import org.netbeans.modules.xslt.model.AttributeValueTemplate;
024:
025: /**
026: * @author ads
027: *
028: */
029: class AttributeValueTemplateImpl implements AttributeValueTemplate {
030:
031: AttributeValueTemplateImpl(XslComponentImpl parent, String value) {
032: assert value != null;
033: assert parent != null;
034:
035: myValue = value;
036: myParent = parent;
037: int begin = myValue.indexOf("{");
038: if (begin > -1) {
039: isTemplate = myValue.indexOf("}") > begin;
040: } else {
041: isTemplate = false;
042: }
043: }
044:
045: AttributeValueTemplateImpl(QName qName) {
046: myQName = qName;
047: isTemplate = false;
048: String localPart = qName.getLocalPart();
049: //String ns = qName.getNamespaceURI();
050: String prefix = qName.getPrefix();
051: if (prefix == null || prefix.length() == 0) {
052: myValue = localPart;
053: } else {
054: myValue = prefix + ":" + localPart;
055: }
056: }
057:
058: /* (non-Javadoc)
059: * @see org.netbeans.modules.xslt.model.AttributeValueTemplate#getQName()
060: */
061: public QName getQName() {
062: if (myQName != null) {
063: return myQName;
064: } else {
065: return QNameBuilder.createQName(getParent(), toString());
066: }
067: }
068:
069: /* (non-Javadoc)
070: * @see org.netbeans.modules.xslt.model.AttributeValueTemplate#isTemplate()
071: */
072: public boolean isTemplate() {
073: return isTemplate;
074: }
075:
076: /* (non-Javadoc)
077: * @see java.lang.Object#toString()
078: */
079: @Override
080: public String toString() {
081: return myValue;
082: }
083:
084: public static AttributeValueTemplateImpl creatAttributeValueTemplate(
085: XslComponentImpl parent, XslAttributes attr) {
086: String str = parent.getAttribute(attr);
087: return creatAttributeValueTemplate(parent, str);
088: }
089:
090: public static AttributeValueTemplateImpl creatAttributeValueTemplate(
091: XslComponentImpl parent, String value) {
092: if (value == null) {
093: return null;
094: }
095: return new AttributeValueTemplateImpl(parent, value);
096: }
097:
098: public static AttributeValueTemplateImpl creatAttributeValueTemplate(
099: QName qName) {
100: return new AttributeValueTemplateImpl(qName);
101: }
102:
103: private XslComponentImpl getParent() {
104: return myParent;
105: }
106:
107: private XslComponentImpl myParent;
108:
109: private String myValue;
110:
111: private boolean isTemplate;
112:
113: private QName myQName;
114:
115: }
|