Skip to content

Commit f968c82

Browse files
author
Gary Brown
committed
Remove declaration model component and validation rule - need to check for duplicate declarations in a different way.
1 parent f7c2a14 commit f968c82

File tree

10 files changed

+148
-95
lines changed

10 files changed

+148
-95
lines changed

integration/eclipse/plugins/org.scribble.protocol.designer/src/java/org/scribble/protocol/designer/editor/outliner/DefaultModelOutliner.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ public String getLabel(ModelReference ref, Object obj) {
4141

4242
if (ret == null) {
4343

44+
/* TODO:
45+
* Find way to extract name from protocol objects.
46+
*
4447
if (obj instanceof org.scribble.protocol.model.Declaration) {
4548
ret = ((org.scribble.protocol.model.Declaration)obj).getName();
4649
}
50+
*/
4751
}
4852

4953
return(ret);
@@ -64,9 +68,11 @@ public org.eclipse.swt.graphics.Image getImage(ModelReference ref, Object obj) {
6468

6569
if (ret == null) {
6670

67-
if (obj instanceof org.scribble.protocol.model.Declaration) {
68-
ret = ScribbleImages.getImage("declaration.png");
69-
} else if (obj instanceof org.scribble.protocol.model.Activity) {
71+
/*
72+
* TODO:
73+
* Find way to derive images from the relevant model types
74+
*/
75+
if (obj instanceof org.scribble.protocol.model.Activity) {
7076
ret = ScribbleImages.getImage("activity.png");
7177
}
7278
}

modules/org.scribble.protocol.conformance/src/main/java/org/scribble/protocol/conformance/impl/BehaviourList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected java.util.Map<String,String> getNameMap(java.util.List<DeclarationBind
158158
while (iter.hasNext()) {
159159
DeclarationBinding db=iter.next();
160160

161-
ret.put(db.getBoundName(), db.getDeclaration().getName());
161+
ret.put(db.getBoundName(), db.getLocalName());
162162
}
163163

164164
return(ret);

modules/org.scribble.protocol.parser/src/main/java/org/scribble/protocol/parser/antlr/ProtocolTreeAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void addChild(Object parent, Object child) {
268268
java.util.List list=(java.util.List)
269269
pds[i].getReadMethod().invoke(parent);
270270

271-
_log.finest("Adding "+child+" to list: "+
271+
_log.info("Adding "+child+" to list: "+
272272
list+" on parent "+parent);
273273
list.add(child);
274274
}

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/Channel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* This class represents the channel declaration.
2121
*/
22-
public class Channel extends Declaration {
22+
public class Channel extends ModelObject {
2323

2424
private static final long serialVersionUID = 1158151945766114601L;
2525

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/DeclarationBinding.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ public DeclarationBinding() {
3131
}
3232

3333
/**
34-
* This constructor initializes the declaration and bound
34+
* This constructor initializes the declaration (local name) and bound
3535
* name.
3636
*
37-
* @param decl The declaration
37+
* @param localName The local name
3838
* @param boundName The bound name
3939
*/
40-
public DeclarationBinding(Declaration decl, String boundName) {
41-
m_declaration = decl;
40+
public DeclarationBinding(String localName, String boundName) {
41+
m_localName = localName;
4242
m_boundName = boundName;
4343
}
4444

4545
/**
46-
* This method sets the declaration.
46+
* This method sets the local name.
4747
*
48-
* @param decl The declaration
48+
* @param localName The local name
4949
*/
50-
public void setDeclaration(Declaration decl) {
51-
m_declaration = decl;
50+
public void setLocalName(String localName) {
51+
m_localName = localName;
5252
}
5353

5454
/**
55-
* This method returns the declaration.
55+
* This method returns the local name.
5656
*
57-
* @return The declaration
57+
* @return The local name
5858
*/
59-
public Declaration getDeclaration() {
60-
return(m_declaration);
59+
public String getLocalName() {
60+
return(m_localName);
6161
}
6262

6363
/**
@@ -88,6 +88,6 @@ public void visit(Visitor visitor) {
8888
visitor.visitDeclarationBinding(this);
8989
}
9090

91-
private Declaration m_declaration=null;
91+
private String m_localName=null;
9292
private String m_boundName=null;
9393
}

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/ModelInclude.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public java.util.List<DeclarationBinding> getBindings() {
4242
* @param decl The declaration
4343
* @return The declaration binding, or null if not found
4444
*/
45-
public DeclarationBinding getDeclarationBinding(Declaration decl) {
45+
public DeclarationBinding getDeclarationBinding(String declName) {
4646
DeclarationBinding ret=null;
4747

4848
java.util.Iterator<DeclarationBinding> iter=getBindings().iterator();
4949

5050
while (ret == null && iter.hasNext()) {
5151
ret = iter.next();
5252

53-
if (ret.getDeclaration() != decl) {
53+
if (ret.getLocalName().equals(declName) == false) {
5454
ret = null;
5555
}
5656
}

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/Participant.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* This class represents a role.
2121
*
2222
*/
23-
public class Participant extends Declaration {
23+
public class Participant extends ModelObject {
2424

2525
private static final long serialVersionUID = 3368940100177769548L;
2626

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/Protocol.java

-72
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.scribble.protocol.model;
1818

19-
2019
/**
2120
* This class represents the protocol notation.
2221
*/
@@ -231,77 +230,6 @@ public Protocol getSubProtocol(SubProtocolPath subPath) {
231230
return(ret);
232231
}
233232

234-
/**
235-
* This method return the top level declarations associated
236-
* with the definition.
237-
*
238-
* @return The declarations
239-
*/
240-
public java.util.Set<Declaration> getDeclarations() {
241-
java.util.Set<Declaration> ret=new java.util.HashSet<Declaration>();
242-
243-
// Check if definition has a located role
244-
if (getLocatedName().getParticipant() != null) {
245-
ret.add(getLocatedName().getParticipant());
246-
}
247-
248-
// Check activities for suitable declarations
249-
java.util.Iterator<Activity> iter=getBlock().getContents().iterator();
250-
251-
while (iter.hasNext()) {
252-
Activity act=iter.next();
253-
254-
if (act instanceof ParticipantList) {
255-
ret.addAll(((ParticipantList)act).getParticipants());
256-
} else if (act instanceof ChannelList) {
257-
ret.addAll(((ChannelList)act).getChannels());
258-
}
259-
}
260-
261-
return(ret);
262-
}
263-
264-
/**
265-
* This method returns the named top level declaration,
266-
* associated with this definition.
267-
*
268-
* @param name The declaration name
269-
* @return The declaration, or null if not found
270-
*/
271-
public Declaration getDeclaration(String name) {
272-
Declaration ret=null;
273-
274-
java.util.Iterator<Declaration> iter=getDeclarations().iterator();
275-
while (ret == null && iter.hasNext()) {
276-
ret = iter.next();
277-
278-
if (ret.getName().equals(name) == false) {
279-
ret = null;
280-
}
281-
}
282-
283-
return(ret);
284-
}
285-
286-
/**
287-
* This method returns the list of roles defined at
288-
* the top level of the definition.
289-
*
290-
* @return The list of roles
291-
*/
292-
public java.util.List<Participant> getRoles() {
293-
java.util.List<Participant> ret=new java.util.Vector<Participant>();
294-
295-
for (int i=0; i < getBlock().getContents().size(); i++) {
296-
297-
if (getBlock().getContents().get(i) instanceof ParticipantList) {
298-
ret.addAll(((ParticipantList)getBlock().getContents().get(i)).getParticipants());
299-
}
300-
}
301-
302-
return(ret);
303-
}
304-
305233
/**
306234
* This method returns the optional located role
307235
* associated with the enclosing definition.

modules/org.scribble.protocol/src/main/java/org/scribble/protocol/model/Recursion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* This class represents the RecursionBlock construct.
2121
*
2222
*/
23-
public class Recursion extends Declaration
23+
public class Recursion extends ModelObject
2424
implements SinglePathBehaviour {
2525

2626
private static final long serialVersionUID = -3777899920653462575L;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2009 Scribble.org
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package org.scribble.protocol.validation.rules;
18+
19+
import java.util.logging.Logger;
20+
21+
import org.scribble.common.logging.Journal;
22+
import org.scribble.protocol.model.Activity;
23+
import org.scribble.protocol.model.Block;
24+
import org.scribble.protocol.model.ModelObject;
25+
import org.scribble.protocol.model.Protocol;
26+
import org.scribble.protocol.validation.ProtocolComponentValidatorRule;
27+
28+
/**
29+
* This class provides the validation util for the Declaration
30+
* model component.
31+
*
32+
*/
33+
public class DeclarationValidatorUtil {
34+
35+
private static final Logger _log=Logger.getLogger(DeclarationValidatorUtil.class.getName());
36+
37+
/**
38+
* This method validates the supplied model object.
39+
*
40+
* @param obj The model object being validated
41+
* @param logger The logger
42+
*/
43+
public static void validate(ModelObject obj,
44+
Journal logger) {
45+
46+
/*
47+
* TODO: Change implementation so that the enclosing protocol is
48+
* processed to build up the declarations within the scope,
49+
* and when the current declaration is checked, it should see
50+
* whether the name is already in the declarations.
51+
*
52+
53+
// Check name has been defined
54+
if (elem.getName() != null &&
55+
elem.getName().trim().length() >= 0) {
56+
57+
// Check all grouping constructs containing the
58+
// declaration, to ensure that only one declaration
59+
// exists with this name, in the scope
60+
Block b=null;
61+
Activity cur=elem;
62+
63+
if (cur.getParent() instanceof Block) {
64+
b = (Block)elem.getParent();
65+
}
66+
67+
while (cur != null && b != null) {
68+
int index=b.indexOf(cur);
69+
70+
if (index == -1) {
71+
_log.warning("Declaration not part of parent block");
72+
cur = null;
73+
} else {
74+
for (int i=0; i < index; i++) {
75+
ModelObject mo=b.get(i);
76+
77+
if (mo instanceof Declaration) {
78+
Declaration decl=(Declaration)mo;
79+
80+
if (decl.getName() != null &&
81+
elem.getName().equals(decl.getName())) {
82+
logger.error(org.scribble.common.util.MessageUtil.format(
83+
java.util.PropertyResourceBundle.getBundle(
84+
"org.scribble.protocol.validation.rules.Messages"),
85+
"_EXISTING_DECLARATION",
86+
new String[]{elem.getName()}),
87+
obj.getProperties());
88+
89+
// Quit loop
90+
cur = null;
91+
}
92+
}
93+
}
94+
95+
if (cur != null) {
96+
97+
if (b.getParent() instanceof Activity) {
98+
cur = (Activity)b.getParent();
99+
100+
// Only continue if the current object
101+
// is not a definition, and it is contained
102+
// inside a block
103+
if ((cur instanceof Protocol) == false &&
104+
cur.getParent() instanceof Block) {
105+
b = (Block)cur.getParent();
106+
} else {
107+
b = null;
108+
}
109+
} else {
110+
b = null;
111+
cur = null;
112+
}
113+
}
114+
}
115+
}
116+
}
117+
*/
118+
}
119+
}

0 commit comments

Comments
 (0)