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 java.net.URI;
022: import java.net.URISyntaxException;
023: import org.netbeans.modules.xml.xam.Reference;
024: import org.netbeans.modules.xslt.tmap.model.api.Param;
025: import org.netbeans.modules.xslt.tmap.model.api.ParamType;
026: import org.netbeans.modules.xslt.tmap.model.api.TMapAttributes;
027: import org.netbeans.modules.xslt.tmap.model.api.TMapReference;
028: import org.netbeans.modules.xslt.tmap.model.api.TMapVisitor;
029: import org.netbeans.modules.xslt.tmap.model.api.Variable;
030: import org.netbeans.modules.xslt.tmap.model.api.VariableDeclarator;
031: import org.netbeans.modules.xslt.tmap.model.api.VariableReference;
032: import org.openide.ErrorManager;
033: import org.w3c.dom.Element;
034:
035: /**
036: *
037: * @author Vitaly Bychkov
038: * @version 1.0
039: */
040: public class ParamImpl extends TMapComponentAbstract implements Param {
041:
042: public ParamImpl(TMapModelImpl model) {
043: this (model, createNewElement(TMapComponents.PARAM, model));
044: }
045:
046: public ParamImpl(TMapModelImpl model, Element element) {
047: super (model, element);
048: }
049:
050: public void accept(TMapVisitor visitor) {
051: visitor.visit(this );
052: }
053:
054: public Class<Param> getComponentType() {
055: return Param.class;
056: }
057:
058: public String getName() {
059: return getAttribute(TMapAttributes.NAME);
060: }
061:
062: public void setName(String name) {
063: setAttribute(Param.NAME, TMapAttributes.NAME, name);
064: }
065:
066: public ParamType getType() {
067: return ParamType
068: .parseParamType(getAttribute(TMapAttributes.TYPE));
069: }
070:
071: public void setType(ParamType type) {
072: setAttribute(Param.TYPE, TMapAttributes.TYPE, ParamType.INVALID
073: .equals(type) ? null : type);
074: }
075:
076: public String getValue() {
077: return getAttribute(TMapAttributes.VALUE);
078: }
079:
080: protected void setValue(String value) {
081: setAttribute(Param.VALUE, TMapAttributes.VALUE, value);
082: }
083:
084: // TODO m
085: public void setContent(String content) {
086: setText(Param.CONTENT, content);
087: }
088:
089: // TODO m
090: public String getContent() {
091: return getText();
092: }
093:
094: public VariableReference getVariableReference() {
095: return ParamType.PART.equals(getType()) ? getTMapVarReference(TMapAttributes.VALUE)
096: : null;
097: }
098:
099: public void setVariableReference(VariableReference varRef) {
100: setTMapVarReference(TMapAttributes.VALUE, varRef);
101: setType(ParamType.PART);
102: }
103:
104: public URI getUri() throws URISyntaxException {
105: URI uri = null;
106: if (ParamType.URI.equals(getType())) {
107: uri = new URI(getValue());
108: }
109: return uri;
110: }
111:
112: public void setUri(URI uri) {
113: setValue(uri.toString());
114: setType(ParamType.URI);
115: }
116:
117: public Reference[] getReferences() {
118: VariableReference varRef = getVariableReference();
119: Reference[] refs = null;
120: if (varRef != null) {
121: refs = new Reference[] { varRef, varRef.getPart() };
122: } else {
123: refs = new Reference[0];
124: }
125:
126: return refs;
127: }
128:
129: public void setLiteralValue(String value) {
130: setValue(value);
131: setType(ParamType.LITERAL);
132: }
133:
134: public String getLiteralValue() {
135: return ParamType.LITERAL.equals(getType()) ? getValue() : null;
136: }
137:
138: }
|