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.util.ArrayList;
022: import java.util.List;
023: import org.netbeans.modules.xml.xam.Reference;
024: import org.netbeans.modules.xslt.tmap.model.api.BooleanType;
025: import org.netbeans.modules.xslt.tmap.model.api.Invoke;
026: import org.netbeans.modules.xslt.tmap.model.api.Operation;
027: import org.netbeans.modules.xslt.tmap.model.api.TMapAttributes;
028: import org.netbeans.modules.xslt.tmap.model.api.TMapVisitor;
029: import org.netbeans.modules.xslt.tmap.model.api.Transform;
030: import org.netbeans.modules.xslt.tmap.model.api.TransformerDescriptor;
031: import org.netbeans.modules.xslt.tmap.model.api.Variable;
032: import org.netbeans.modules.xslt.tmap.model.api.VariableDeclarator;
033: import org.netbeans.modules.xslt.tmap.model.api.WSDLReference;
034: import org.w3c.dom.Element;
035:
036: /**
037: *
038: * @author Vitaly Bychkov
039: * @version 1.0
040: */
041: public class OperationImpl extends TMapComponentContainerImpl implements
042: Operation {
043:
044: public OperationImpl(TMapModelImpl model) {
045: this (model, createNewElement(TMapComponents.OPERATION, model));
046: }
047:
048: public OperationImpl(TMapModelImpl model, Element element) {
049: super (model, element);
050: }
051:
052: public void accept(TMapVisitor visitor) {
053: visitor.visit(this );
054: }
055:
056: public Reference<org.netbeans.modules.xml.wsdl.model.Operation> getOperation() {
057: return getWSDLReference(TMapAttributes.OPERATION_NAME,
058: org.netbeans.modules.xml.wsdl.model.Operation.class);
059: }
060:
061: public void setOperation(
062: WSDLReference<org.netbeans.modules.xml.wsdl.model.Operation> opRef) {
063: setWSDLReference(TMapAttributes.OPERATION_NAME, opRef);
064: }
065:
066: public Reference[] getReferences() {
067: return new Reference[] { getOperation() };
068: }
069:
070: public String getFile() {
071: return getAttribute(TMapAttributes.FILE);
072: }
073:
074: public void setFile(String locationURI) {
075: setAttribute(TransformerDescriptor.FILE, TMapAttributes.FILE,
076: locationURI);
077: }
078:
079: public BooleanType isTransformJbi() {
080: return BooleanType
081: .parseBooleanType(getAttribute(TMapAttributes.TRANSFORM_JBI));
082: }
083:
084: public void setTransformJbi(BooleanType boolVal) {
085: setAttribute(TransformerDescriptor.TRANSFORM_JBI,
086: TMapAttributes.TRANSFORM_JBI, boolVal);
087: }
088:
089: public Class<Operation> getComponentType() {
090: return Operation.class;
091: }
092:
093: public List<Invoke> getInvokes() {
094: return getChildren(Invoke.class);
095: }
096:
097: public void removeInvoke(Invoke invoke) {
098: removeChild(TYPE.getTagName(), invoke);
099: }
100:
101: public void addInvoke(Invoke invoke) {
102: addAfter(TYPE.getTagName(), invoke, TYPE.getChildTypes());
103: }
104:
105: public int getSizeOfInvokes() {
106: List<Invoke> invokes = getInvokes();
107: return invokes == null ? 0 : invokes.size();
108: }
109:
110: public List<Transform> getTransforms() {
111: return getChildren(Transform.class);
112: }
113:
114: public void removeTransforms(Transform transform) {
115: removeChild(TYPE.getTagName(), transform);
116: }
117:
118: public void addTransform(Transform transform) {
119: addAfter(TYPE.getTagName(), transform, TYPE.getChildTypes());
120: }
121:
122: public int getSizeOfTransform() {
123: List<Transform> transforms = getTransforms();
124: return transforms == null ? 0 : transforms.size();
125: }
126:
127: public Variable getInputVariable() {
128: String varName = getAttribute(TMapAttributes.INPUT_VARIABLE);
129:
130: Variable var = varName == null ? null : new InputVariableImpl(
131: getModel(), varName, this );
132: return var;
133: }
134:
135: public void setInputVariableName(String inputVariable) {
136: setAttribute(INPUT_VARIABLE, TMapAttributes.INPUT_VARIABLE,
137: inputVariable);
138: }
139:
140: public Variable getOutputVariable() {
141: String varName = getAttribute(TMapAttributes.OUTPUT_VARIABLE);
142:
143: Variable var = varName == null ? null : new OutputVariableImpl(
144: getModel(), varName, this );
145: return var;
146: }
147:
148: public void setOutputVariableName(String outputVariable) {
149: setAttribute(OUTPUT_VARIABLE, TMapAttributes.OUTPUT_VARIABLE,
150: outputVariable);
151: }
152:
153: public List<Variable> getVariables() {
154: List<Variable> opVars = new ArrayList<Variable>();
155: collectVariables(opVars, this );
156:
157: List<Invoke> invokes = getInvokes();
158: if (invokes != null && invokes.size() > 0) {
159: for (Invoke invoke : invokes) {
160: collectVariables(opVars, invoke);
161: }
162: }
163:
164: return opVars;
165: }
166:
167: private void collectVariables(List<Variable> vars,
168: VariableDeclarator varContainer) {
169: if (varContainer == null || vars == null) {
170: return;
171: }
172:
173: Variable tmpVar = varContainer.getInputVariable();
174: if (tmpVar != null) {
175: vars.add(tmpVar);
176: }
177:
178: tmpVar = varContainer.getOutputVariable();
179: if (tmpVar != null) {
180: vars.add(tmpVar);
181: }
182: }
183:
184: }
|