01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: AutoLinkDeclaration.java 3701 2007-03-18 12:24:23Z gbevin $
07: */
08: package com.uwyn.rife.engine;
09:
10: import java.util.Collection;
11:
12: class AutoLinkDeclaration extends AbstractLogicLinkDeclaration {
13: private ElementInfoBuilder mElementInfoBuilder = null;
14:
15: AutoLinkDeclaration(ElementInfoBuilder elementInfoBuilder,
16: String srcExit, String destId, boolean cancelInheritance,
17: boolean cancelEmbedding, boolean redirect,
18: boolean cancelContinuations) {
19: super (elementInfoBuilder.getSiteBuilder(), srcExit, destId,
20: false, cancelInheritance, cancelEmbedding, redirect,
21: cancelContinuations);
22:
23: mElementInfoBuilder = elementInfoBuilder;
24: }
25:
26: void registerFlowAndDataLinks() {
27: FlowLinkBuilder flowlink_builder = new FlowLinkBuilder(
28: mElementInfoBuilder, getSrcExit());
29: flowlink_builder.destId(getDestId()).cancelInheritance(
30: cancelInheritance()).cancelEmbedding(cancelEmbedding())
31: .redirect(isRedirect());
32:
33: FlowLink flowlink = flowlink_builder.getFlowLinkDeclaration()
34: .getFlowLink();
35:
36: ElementInfo src_element_info = mElementInfoBuilder
37: .getElementDeclaration().getElementInfo();
38:
39: // automatically add datalinks for outputs that have inputs with the same name in the target element
40: Collection<String> output_names = src_element_info
41: .getOutputNames();
42: Collection<String> input_names = flowlink.getTarget()
43: .getInputNames();
44: for (String output_name : output_names) {
45: if (input_names.contains(output_name)) {
46: flowlink_builder.addDataLink(output_name, output_name);
47: }
48: }
49:
50: // automatically add datalinks for named outbeans that have named inbeans with the same name in the target element
51: Collection<String> outbean_names = src_element_info
52: .getNamedOutbeanNames();
53: Collection<String> inbean_names = flowlink.getTarget()
54: .getNamedInbeanNames();
55: for (String outbean_name : outbean_names) {
56: if (inbean_names.contains(outbean_name)) {
57: flowlink_builder.addDataLinkBean(outbean_name,
58: outbean_name);
59: }
60: }
61:
62: flowlink_builder.leaveFlowLink();
63:
64: mElementInfoBuilder
65: .registerFlowAndDataLinksInSite(flowlink_builder
66: .getFlowLinkDeclaration());
67: }
68:
69: String getDestId() {
70: String destid = super .getDestId();
71: if (null == destid || 0 == destid.length()) {
72: return getSrcExit();
73: }
74:
75: return destid;
76: }
77:
78: public boolean equals(Object other) {
79: if (!(other instanceof AutoLinkDeclaration)) {
80: return false;
81: }
82:
83: return super.equals(other);
84: }
85: }
|