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 org.netbeans.modules.xslt.tmap.model.api.Invoke;
022: import org.netbeans.modules.xslt.tmap.model.api.Operation;
023: import org.netbeans.modules.xslt.tmap.model.api.Param;
024: import org.netbeans.modules.xslt.tmap.model.api.Service;
025: import org.netbeans.modules.xslt.tmap.model.api.TMapComponent;
026: import org.netbeans.modules.xslt.tmap.model.api.TMapVisitor;
027: import org.netbeans.modules.xslt.tmap.model.api.Transform;
028: import org.netbeans.modules.xslt.tmap.model.api.TransformMap;
029: import org.w3c.dom.Element;
030:
031: /**
032: *
033: * @author Vitaly Bychkov
034: * @version 1.0
035: */
036: public class TMapComponentBuildVisitor implements TMapVisitor {
037:
038: private TMapModelImpl myModel;
039: private Element myElement;
040: private TMapComponent myResult;
041:
042: public TMapComponentBuildVisitor(TMapModelImpl model) {
043: assert model != null;
044: myModel = model;
045: }
046:
047: public TMapComponent createSubComponent(TMapComponent parent,
048: Element element) {
049: myElement = element;
050: String namespace = element.getNamespaceURI();
051: if (namespace == null
052: && parent instanceof TMapComponentAbstract) {
053: namespace = ((TMapComponentAbstract) parent)
054: .lookupNamespaceURI(element.getPrefix());
055: }
056:
057: if (TMapComponent.TRANSFORM_MAP_NS_URI.equals(namespace)) {
058: if (parent == null) {
059: if (TMapComponents.TRANSFORM_MAP.getTagName().equals(
060: getElement().getLocalName())) {
061: setResult(new TransformMapImpl(getModel(), element));
062: }
063: } else {
064: parent.accept(this );
065: }
066: }
067:
068: return myResult;
069: }
070:
071: public void visit(TransformMap transformMap) {
072: if (isAcceptable(TMapComponents.SERVICE)) {
073: setResult(new ServiceImpl(getModel(), getElement()));
074: }
075: }
076:
077: public void visit(Service service) {
078: if (isAcceptable(TMapComponents.OPERATION)) {
079: setResult(new OperationImpl(getModel(), getElement()));
080: }
081: }
082:
083: public void visit(Operation operation) {
084: if (isAcceptable(TMapComponents.INVOKE)) {
085: setResult(new InvokeImpl(getModel(), getElement()));
086: } else if (isAcceptable(TMapComponents.TRANSFORM)) {
087: setResult(new TransformImpl(getModel(), getElement()));
088: }
089: }
090:
091: public void visit(Invoke invoke) {
092:
093: }
094:
095: public void visit(Transform transform) {
096: if (isAcceptable(TMapComponents.PARAM)) {
097: setResult(new ParamImpl(getModel(), getElement()));
098: }
099: }
100:
101: public void visit(Param param) {
102: }
103:
104: void init() {
105: myResult = null;
106: myElement = null;
107: }
108:
109: public Element getElement() {
110: return myElement;
111: }
112:
113: private boolean isAcceptable(TMapComponents acceptedComponents) {
114: return acceptedComponents.getTagName().equals(getLocalName());
115: }
116:
117: private String getLocalName() {
118: return getElement().getLocalName();
119: }
120:
121: private TMapModelImpl getModel() {
122: return myModel;
123: }
124:
125: private void setResult(TMapComponent component) {
126: myResult = component;
127: }
128: }
|