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.xsltmap;
020:
021: import java.util.Collection;
022: import org.netbeans.modules.soa.ui.axinodes.AxiomUtils;
023: import org.netbeans.modules.xml.axi.AXIComponent;
024: import org.netbeans.modules.xml.axi.AXIDocument;
025: import org.netbeans.modules.xml.axi.AXIModel;
026: import org.netbeans.modules.xml.axi.AXIModelFactory;
027: import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
028: import org.netbeans.modules.xml.schema.model.SchemaModel;
029: import org.netbeans.modules.xml.wsdl.model.Message;
030: import org.netbeans.modules.xml.wsdl.model.Operation;
031: import org.netbeans.modules.xml.wsdl.model.Part;
032: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
033: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
034: import org.netbeans.modules.xslt.tmap.util.Util;
035: import org.openide.filesystems.FileObject;
036:
037: /**
038: *
039: * @author Vitaly Bychkov
040: * @version 1.0
041: */
042: public abstract class AbstractTransformationDesc implements
043: TransformationDesc {
044: private String partnerLink;
045: private String roleName;
046: private String portType;
047: private String operation;
048: private String messageType;
049: private String file;
050: private boolean transformJBI;
051: private TransformationUC parentTUC;
052: private XsltMapModel model;
053:
054: public AbstractTransformationDesc(XsltMapModel model,
055: TransformationUC parent) {
056: this .parentTUC = parent;
057: this .model = model;
058: parentTUC.addTransformationDesc(this );
059: }
060:
061: public XsltMapModel getXsltMapModel() {
062: return model;
063: }
064:
065: public TransformationUC getParent() {
066: return parentTUC;
067: }
068:
069: public XsltMapModel getModel() {
070: return model;
071: }
072:
073: public String getPartnerLink() {
074: return partnerLink;
075: }
076:
077: public void setPartnerLink(String partnerLink) {
078: this .partnerLink = partnerLink;
079: }
080:
081: public String getRoleName() {
082: return roleName;
083: }
084:
085: public void setRoleName(String roleName) {
086: this .roleName = roleName;
087: }
088:
089: public String getPortType() {
090: return portType;
091: }
092:
093: public void setPortType(String portType) {
094: this .portType = portType;
095: }
096:
097: public void setOperation(String operation) {
098: this .operation = operation;
099: }
100:
101: public String getOperation() {
102: return operation;
103: }
104:
105: public String getMessageType() {
106: return messageType;
107: }
108:
109: public void setMessageType(String messageType) {
110: this .messageType = messageType;
111: }
112:
113: public String getFile() {
114: return file;
115: }
116:
117: public void setFile(String file) {
118: this .file = file;
119: }
120:
121: public String getTransformJBI() {
122: return Boolean.toString(transformJBI);
123: }
124:
125: public void setTransformJBI(boolean transformJBI) {
126: this .transformJBI = transformJBI;
127: }
128:
129: public void setTransformJBI(String transformJBI) {
130: this .transformJBI = "true".equals(transformJBI);
131: }
132:
133: public boolean isTransformJBI() {
134: return transformJBI;
135: }
136:
137: public boolean isEqualInputFile(FileObject xsltFile) {
138: String inputFile = getFile();
139: return inputFile != null && xsltFile != null
140: && inputFile.equals(xsltFile.getNameExt());
141: }
142:
143: public AXIModel getSourceAxiModel(FileObject projectRoot) {
144: assert projectRoot != null;
145: AXIModel axiSourceModel = null;
146: SchemaModel sourceSchema = getSourceSchema(projectRoot);
147: if (sourceSchema != null) {
148: axiSourceModel = AXIModelFactory.getDefault().getModel(
149: sourceSchema);
150: }
151:
152: return axiSourceModel;
153: }
154:
155: public SchemaModel getSourceSchema(FileObject projectRoot) {
156: if (isTransformJBI()) {
157: return getJBISourceSchema();
158: }
159:
160: assert projectRoot != null;
161: SchemaModel sourceSchema = null;
162: Operation operation = Util.findWsdlOperation(projectRoot, this );
163: if (operation != null) {
164: org.netbeans.modules.xml.wsdl.model.Input wsdlInput = operation
165: .getInput();
166: NamedComponentReference<Message> message = wsdlInput
167: .getMessage();
168: if (message == null) {
169: return null;
170: }
171:
172: sourceSchema = getMessageSchemaModel(operation.getModel(),
173: message);
174: }
175: return sourceSchema;
176: }
177:
178: public ReferenceableSchemaComponent getSourceType(
179: FileObject projectRoot) {
180: if (isTransformJBI()) {
181: return null;
182: }
183:
184: assert projectRoot != null;
185: ReferenceableSchemaComponent sourceSchemaComponent = null;
186: Operation operation = Util.findWsdlOperation(projectRoot, this );
187: if (operation != null) {
188: org.netbeans.modules.xml.wsdl.model.Input wsdlInput = operation
189: .getInput();
190: NamedComponentReference<Message> message = wsdlInput
191: .getMessage();
192: if (message == null) {
193: return null;
194: }
195:
196: sourceSchemaComponent = getMessageSchemaType(operation
197: .getModel(), message);
198: }
199:
200: return sourceSchemaComponent;
201: }
202:
203: public AXIComponent getPltSourceAXIType(FileObject projectRoot) {
204: assert projectRoot != null;
205: return getAXIComponent(getSourceType(projectRoot));
206: }
207:
208: private SchemaModel getJBISourceSchema() {
209: // TODO impl it
210: return null;
211: }
212:
213: private SchemaModel getJBITargetSchema() {
214: // TODO impl it
215: return null;
216: }
217:
218: /**
219: * returns first message part element/type schema model
220: */
221: private SchemaModel getMessageSchemaModel(WSDLModel wsdlModel,
222: NamedComponentReference<Message> message) {
223: if (wsdlModel == null || message == null) {
224: return null;
225: }
226: SchemaModel schemaModel = null;
227:
228: // look at parts
229: String elNamespace = null;
230: Class<? extends ReferenceableSchemaComponent> elType = null;
231: Collection<Part> parts = message.get().getParts();
232: Part partElem = null;
233: if (parts != null && parts.size() > 0) {
234: partElem = parts.iterator().next();
235: }
236:
237: NamedComponentReference<? extends ReferenceableSchemaComponent> element = partElem
238: .getElement();
239: if (element == null) {
240: element = partElem.getType();
241: }
242:
243: if (element != null && element.get() != null) {
244: schemaModel = element.get().getModel();
245: }
246:
247: return schemaModel;
248: }
249:
250: /**
251: * returns first message part type
252: */
253: private ReferenceableSchemaComponent getMessageSchemaType(
254: WSDLModel wsdlModel,
255: NamedComponentReference<Message> message) {
256: if (wsdlModel == null || message == null) {
257: return null;
258: }
259: ReferenceableSchemaComponent schemaComponent = null;
260:
261: // look at parts
262: String elNamespace = null;
263: Class<? extends ReferenceableSchemaComponent> elType = null;
264: Collection<Part> parts = message.get().getParts();
265: Part partElem = null;
266: if (parts != null && parts.size() > 0) {
267: partElem = parts.iterator().next();
268: }
269:
270: NamedComponentReference<? extends ReferenceableSchemaComponent> element = partElem
271: .getElement();
272: if (element == null) {
273: element = partElem.getType();
274: }
275:
276: // TODO r
277: // if (equalMessageType(element)) {
278: // schemaComponent = element.get();
279: // }
280: schemaComponent = element.get();
281:
282: return schemaComponent;
283: }
284:
285: private boolean equalMessageType(
286: NamedComponentReference<? extends ReferenceableSchemaComponent> element) {
287: String curMessageType = getMessageType();
288: if (curMessageType == null || element == null) {
289: return false;
290: }
291:
292: return curMessageType.equals(element.getRefString());
293: }
294:
295: public ReferenceableSchemaComponent getTargetType(
296: FileObject projectRoot) {
297: if (isTransformJBI()) {
298: return null;
299: }
300:
301: assert projectRoot != null;
302: ReferenceableSchemaComponent targetSchemaComponent = null;
303: Operation operation = Util.findWsdlOperation(projectRoot, this );
304: if (operation != null) {
305: org.netbeans.modules.xml.wsdl.model.Output wsdlOutput = operation
306: .getOutput();
307: NamedComponentReference<Message> message = wsdlOutput
308: .getMessage();
309: if (message == null) {
310: return null;
311: }
312:
313: targetSchemaComponent = getMessageSchemaType(operation
314: .getModel(), message);
315: }
316: return targetSchemaComponent;
317: }
318:
319: private AXIComponent getAXIComponent(
320: ReferenceableSchemaComponent schemaComponent) {
321: if (schemaComponent == null) {
322: return null;
323: }
324: AXIComponent axiComponent = null;
325:
326: AXIModel axiModel = AXIModelFactory.getDefault().getModel(
327: schemaComponent.getModel());
328: if (axiModel != null) {
329: axiComponent = AxiomUtils.findGlobalComponent(axiModel
330: .getRoot(), null, schemaComponent);
331: }
332:
333: return axiComponent;
334: }
335:
336: public AXIComponent getPltTargetAXIType(FileObject projectRoot) {
337: assert projectRoot != null;
338: return getAXIComponent(getTargetType(projectRoot));
339: }
340:
341: public SchemaModel getTargetSchema(FileObject projectRoot) {
342: if (isTransformJBI()) {
343: return getJBITargetSchema();
344: }
345:
346: assert projectRoot != null;
347: SchemaModel targetSchema = null;
348: Operation operation = Util.findWsdlOperation(projectRoot, this );
349: if (operation != null) {
350: org.netbeans.modules.xml.wsdl.model.Output wsdlOutput = operation
351: .getOutput();
352: if (wsdlOutput != null) {
353: NamedComponentReference<Message> message = wsdlOutput
354: .getMessage();
355: if (message == null) {
356: return null;
357: }
358:
359: targetSchema = getMessageSchemaModel(operation
360: .getModel(), message);
361: }
362: }
363: return targetSchema;
364: }
365:
366: public AXIModel getTargetAxiModel(FileObject projectRoot) {
367: assert projectRoot != null;
368: AXIModel axiTargetModel = null;
369: SchemaModel targetSchema = getTargetSchema(projectRoot);
370: if (targetSchema != null) {
371: axiTargetModel = AXIModelFactory.getDefault().getModel(
372: targetSchema);
373: }
374:
375: return axiTargetModel;
376: }
377: }
|