KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > importer > rose > parser > RoseNode


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: RoseNode.java,v 1.3 2005/06/12 13:36:38 emerks Exp $
16  */

17 package org.eclipse.emf.importer.rose.parser;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23 import java.util.regex.Matcher JavaDoc;
24 import java.util.regex.Pattern JavaDoc;
25
26 import org.eclipse.emf.importer.rose.builder.RoseStrings;
27
28
29 /**
30  * Is used to build a tree for Rose file.
31  */

32 public class RoseNode
33 {
34   public final static int STRING = 0;
35   public final static int STRING_SEQ = 1;
36   public final static int OBJECT = 2;
37   public final static int LIST = 3;
38   public final static int VALUE = 4;
39
40   protected String JavaDoc key;
41   protected String JavaDoc value;
42   protected RoseNode parent;
43   protected List JavaDoc nodes = new ArrayList JavaDoc();
44   protected int type;
45   protected String JavaDoc id;
46   protected boolean commit = true;
47   protected Object JavaDoc node;
48
49   public RoseNode(String JavaDoc key, String JavaDoc value, int type)
50   {
51     this.key = key;
52     this.value = value;
53     this.type = type;
54   }
55
56   public void setParent(RoseNode parent)
57   {
58     this.parent = parent;
59   }
60
61   public RoseNode getParent()
62   {
63     return parent;
64   }
65
66   public RoseNode getRoot()
67   {
68     RoseNode result = this;
69     for (RoseNode root = this.getParent(); root != null; root = root.getParent())
70     {
71       result = root;
72     }
73     return result;
74   }
75
76   public String JavaDoc getKey()
77   {
78     return key;
79   }
80
81   public String JavaDoc getValue()
82   {
83     return value;
84   }
85
86   public String JavaDoc getAllValues()
87   {
88     return getAllValues(false);
89   }
90
91   public String JavaDoc getAllValues(boolean preserveSpace)
92   {
93     if (type == STRING_SEQ)
94     {
95       StringBuffer JavaDoc temp = new StringBuffer JavaDoc();
96       for (int i = 0; i < nodes.size(); i++)
97       {
98         RoseNode n = (RoseNode)nodes.get(i);
99         temp.append(n.getValue());
100         if (preserveSpace && i < nodes.size() - 1)
101         {
102           temp.append('\n');
103         }
104       }
105       return temp.toString();
106     }
107     else
108     {
109       return preserveSpace ? Util.trimQuotes(value) : value;
110     }
111   }
112
113   public String JavaDoc getFilteredValues(String JavaDoc filter)
114   {
115     if (type == STRING_SEQ)
116     {
117       StringBuffer JavaDoc temp = new StringBuffer JavaDoc();
118       for (int i = 0; i < nodes.size(); i++)
119       {
120         RoseNode n = (RoseNode)nodes.get(i);
121         if (i == 0 && Util.getWord(n.getValue(), 1).equals(filter))
122         {
123           continue;
124         }
125         temp.append(n.getValue());
126         if (i < nodes.size() - 1)
127         {
128           temp.append('\n');
129         }
130       }
131       return temp.toString();
132     }
133     else
134     {
135       String JavaDoc val = Util.trimQuotes(value);
136       return Util.getWord(val, 1).equals(filter) ? "" : val;
137     }
138   }
139
140   public void setValue(String JavaDoc value)
141   {
142     this.value = value;
143   }
144
145   public boolean getCommit()
146   {
147     return commit;
148   }
149
150   public void setCommit(boolean b)
151   {
152     commit = b;
153   }
154
155   public String JavaDoc getId()
156   {
157     return id;
158   }
159
160   public String JavaDoc getAtId()
161   {
162     int ind = value.lastIndexOf("@");
163     return ind != -1 ? value.substring(ind + 1) : null;
164   }
165
166   public void setId(String JavaDoc id)
167   {
168     this.id = id;
169   }
170
171   public int getRoseNodeType()
172   {
173     return type;
174   }
175
176   public List JavaDoc getNodes()
177   {
178     return nodes;
179   }
180
181   public void addNode(RoseNode n)
182   {
183     n.parent = this;
184     nodes.add(n);
185   }
186
187   public void deleteNode(RoseNode n)
188   {
189     if (n != null)
190     {
191       nodes.remove(n);
192     }
193   }
194
195   public RoseNode findNodeWithKey(String JavaDoc key)
196   {
197     for (int i = 0; i < nodes.size(); i++)
198     {
199       RoseNode node = (RoseNode)nodes.get(i);
200       if (key.equals(node.getKey()))
201       {
202         return node;
203       }
204     }
205     return null;
206   }
207
208   public RoseNode findNodeWithValue(String JavaDoc value)
209   {
210     for (int i = 0; i < nodes.size(); i++)
211     {
212       RoseNode node = (RoseNode)nodes.get(i);
213       if (value.equals(node.getValue()))
214       {
215         return node;
216       }
217     }
218     return null;
219   }
220
221   public RoseNode findNodeWithWord(String JavaDoc w)
222   {
223     for (int i = 0; i < nodes.size(); i++)
224     {
225       RoseNode node = (RoseNode)nodes.get(i);
226       String JavaDoc value = node.getValue();
227       StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(value);
228       while (st.hasMoreTokens())
229       {
230         String JavaDoc tok = st.nextToken();
231         if (tok.equals(w))
232         {
233           return node;
234         }
235       }
236     }
237     return null;
238   }
239
240   public String JavaDoc getRoseId()
241   {
242     RoseNode node = findNodeWithKey("quid");
243     return node != null ? node.getValue() : null;
244   }
245
246   public String JavaDoc getRoseRefId()
247   {
248     RoseNode node = findNodeWithKey("quidu");
249     return node != null ? node.getValue() : null;
250   }
251
252   public String JavaDoc getRoseSupplier()
253   {
254     RoseNode node = findNodeWithKey("supplier");
255     return node != null ? Util.trimQuotes(node.getValue()) : null;
256   }
257
258   public void setNode(Object JavaDoc node)
259   {
260     this.node = node;
261   }
262
263   public Object JavaDoc getNode()
264   {
265     return node;
266   }
267
268   public String JavaDoc getType()
269   {
270     String JavaDoc attributeValue = getAttributeValue(RoseStrings.TYPE);
271     return attributeValue;
272   }
273
274   public String JavaDoc getStereotype()
275   {
276     String JavaDoc attributeValue = getAttributeValue(RoseStrings.STEREOTYPE);
277     return attributeValue;
278   }
279
280   public boolean isDerived()
281   {
282     String JavaDoc attributeValue = getAttributeValue(RoseStrings.DERIVED);
283     return "true".equalsIgnoreCase(attributeValue);
284   }
285
286   public boolean isAbstract()
287   {
288     String JavaDoc attributeValue = getAttributeValue(RoseStrings.ABSTRACT);
289     return "true".equalsIgnoreCase(attributeValue);
290   }
291
292   public boolean isNavigable()
293   {
294     String JavaDoc attributeValue = getAttributeValue(RoseStrings.IS_NAVIGABLE);
295     return "true".equalsIgnoreCase(attributeValue);
296   }
297
298   public boolean isAggregate()
299   {
300     String JavaDoc attributeValue = getAttributeValue(RoseStrings.IS_AGGREGATE);
301     return "true".equalsIgnoreCase(attributeValue);
302   }
303
304   public String JavaDoc getContainment()
305   {
306     String JavaDoc attributeValue = getAttributeValue(RoseStrings.CONTAINMENT);
307     return attributeValue;
308   }
309
310   public String JavaDoc getConstraints()
311   {
312     String JavaDoc attributeValue = getAttributeValue(RoseStrings.CONSTRAINTS);
313     return attributeValue;
314   }
315
316   public String JavaDoc getResult()
317   {
318     String JavaDoc attributeValue = getAttributeValue(RoseStrings.RESULT);
319     return attributeValue;
320   }
321
322   public String JavaDoc getExceptions()
323   {
324     String JavaDoc attributeValue = getAttributeValue(RoseStrings.EXCEPTIONS);
325     return attributeValue;
326   }
327
328   public String JavaDoc getSemantics()
329   {
330     RoseNode semantics = findNodeWithKey(RoseStrings.SEMANTICS);
331     return semantics == null ? null : semantics.getAttributeValue(RoseStrings.PDL);
332   }
333
334   public String JavaDoc getInitV()
335   {
336     String JavaDoc attributeValue = getAttributeValue(RoseStrings.INITV);
337     return attributeValue;
338   }
339
340   public String JavaDoc getDocumentation()
341   {
342     String JavaDoc attributeValue = getAttributeValue(RoseStrings.DOCUMENTATION);
343     return attributeValue;
344   }
345
346   public boolean isLoaded()
347   {
348     String JavaDoc attributeValue = getAttributeValue(RoseStrings.IS_LOADED);
349     return attributeValue == null || "true".equalsIgnoreCase(attributeValue);
350   }
351
352   protected String JavaDoc getAttributeValue(String JavaDoc key)
353   {
354     for (Iterator JavaDoc i = getNodes().iterator(); i.hasNext();)
355     {
356       RoseNode roseNode = (RoseNode)i.next();
357       if (roseNode.getRoseNodeType() == RoseNode.STRING)
358       {
359         String JavaDoc nodeKey = roseNode.getKey();
360         String JavaDoc nodeValue = roseNode.getValue();
361         if (nodeKey.equals(key))
362         {
363           nodeValue = dequote(nodeValue);
364           return nodeValue;
365         }
366       }
367       else if (roseNode.getRoseNodeType() == RoseNode.STRING_SEQ && roseNode.getKey().equals(key))
368       {
369         String JavaDoc separator = System.getProperty("line.separator");
370         List JavaDoc subNodes = roseNode.getNodes();
371         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
372         for (Iterator JavaDoc j = subNodes.iterator(); j.hasNext();)
373         {
374           RoseNode subNode = (RoseNode)j.next();
375           if (subNode.getRoseNodeType() == RoseNode.STRING)
376           {
377             if (subNode.getValue().equals(""))
378             {
379               result.append(separator);
380             }
381             else
382             {
383               if (result.length() != 0)
384               {
385                 result.append(separator);
386               }
387               result.append(subNode.getValue());
388             }
389           }
390         }
391         return result.toString();
392       }
393     }
394
395     return null;
396   }
397
398   public String JavaDoc getUML2MOFCorbaType()
399   {
400     String JavaDoc attributeValue = getAttributeValue("MOF", "uml2mof.corbaType");
401     return attributeValue;
402   }
403
404   public boolean isTransient()
405   {
406     String JavaDoc attributeValue = getAttributeValue("Ecore", "isTransient");
407     return "true".equalsIgnoreCase(attributeValue);
408   }
409
410   public boolean isVolatile()
411   {
412     String JavaDoc attributeValue = getAttributeValue("Ecore", "isVolatile");
413     return "true".equalsIgnoreCase(attributeValue);
414   }
415
416   public boolean isChangeable()
417   {
418     String JavaDoc attributeValue = getAttributeValue("Ecore", "isChangeable");
419     return !"false".equalsIgnoreCase(attributeValue);
420   }
421
422   public boolean isResolveProxies()
423   {
424     String JavaDoc attributeValue = getAttributeValue("Ecore", "isResolveProxies");
425     return !"false".equalsIgnoreCase(attributeValue);
426   }
427
428   public boolean isUnsettable()
429   {
430     String JavaDoc attributeValue = getAttributeValue("Ecore", "isUnsettable");
431     return "true".equalsIgnoreCase(attributeValue);
432   }
433
434   public boolean isID()
435   {
436     String JavaDoc attributeValue = getAttributeValue("Ecore", "isID");
437     return "true".equalsIgnoreCase(attributeValue);
438   }
439
440   public boolean isUnique()
441   {
442     String JavaDoc attributeValue = getAttributeValue("Ecore", "isUnique");
443     return !"false".equalsIgnoreCase(attributeValue);
444   }
445
446   public String JavaDoc getBasePackage()
447   {
448     String JavaDoc attributeValue = getAttributeValue("Ecore", "basePackage");
449     return attributeValue;
450   }
451
452   public String JavaDoc getPrefix()
453   {
454     String JavaDoc attributeValue = getAttributeValue("Ecore", "prefix");
455     return attributeValue;
456   }
457
458   public String JavaDoc getPackageName()
459   {
460     String JavaDoc attributeValue = getAttributeValue("Ecore", "packageName");
461     return attributeValue;
462   }
463
464   public String JavaDoc getClassifierName()
465   {
466     String JavaDoc attributeValue = getAttributeValue("Ecore", "classifierName");
467     return attributeValue;
468   }
469
470   public String JavaDoc getEcoreConstraints()
471   {
472     String JavaDoc attributeValue = getAttributeValue("Ecore", "constraints");
473     return attributeValue;
474   }
475
476   public String JavaDoc getReferenceName()
477   {
478     String JavaDoc attributeValue = getAttributeValue("Ecore", "referenceName");
479     return attributeValue;
480   }
481
482   public String JavaDoc getAttributeName()
483   {
484     String JavaDoc attributeValue = getAttributeValue("Ecore", "attributeName");
485     return attributeValue;
486   }
487
488   public String JavaDoc getOperationName()
489   {
490     String JavaDoc attributeValue = getAttributeValue("Ecore", "operationName");
491     return attributeValue;
492   }
493
494   public String JavaDoc getNsPrefix()
495   {
496     String JavaDoc attributeValue = getAttributeValue("Ecore", "nsPrefix");
497     if (attributeValue == null || attributeValue.length() == 0)
498     {
499       attributeValue = getAttributeValue("Ecore", "nsName");
500     }
501     return attributeValue;
502   }
503
504   public String JavaDoc getNsURI()
505   {
506     String JavaDoc attributeValue = getAttributeValue("Ecore", "nsURI");
507     return attributeValue;
508   }
509
510   public String JavaDoc getXMLName()
511   {
512     String JavaDoc attributeValue = getAttributeValue("Ecore", "xmlName");
513     return attributeValue;
514   }
515
516   public String JavaDoc getXMLNamespace()
517   {
518     String JavaDoc attributeValue = getAttributeValue("Ecore", "xmlNamespace");
519     return attributeValue;
520   }
521
522   protected static final Pattern JavaDoc FEATURE_VALUE_PATTERN = Pattern.compile("\\s*\\(\\s*\"FeatureKind\"\\s+([0-9]+)\\s*\\)");
523
524   public int getXMLFeatureKind()
525   {
526     String JavaDoc attributeValue = getAttributeValue("Ecore", "xmlFeatureKind");
527     if (attributeValue != null)
528     {
529       Matcher JavaDoc matcher = FEATURE_VALUE_PATTERN.matcher(attributeValue);
530       if (matcher.matches())
531       {
532         return Integer.parseInt(matcher.group(1));
533       }
534     }
535     return 0;
536   }
537
538   protected static final Pattern JavaDoc CONTENT_VALUE_PATTERN = Pattern.compile("\\s*\\(\\s*\"ContentKind\"\\s+([0-9]+)\\s*\\)");
539
540   public int getXMLContentKind()
541   {
542     String JavaDoc attributeValue = getAttributeValue("Ecore", "xmlContentKind");
543     if (attributeValue != null)
544     {
545       Matcher JavaDoc matcher = CONTENT_VALUE_PATTERN.matcher(attributeValue);
546       if (matcher.matches())
547       {
548         return Integer.parseInt(matcher.group(1));
549       }
550     }
551     return 0;
552   }
553
554   public static final int VISIBILITY_UNSPECIFIED = 0;
555   public static final int VISIBILITY_NONE = 1;
556   public static final int VISIBILITY_READ_ONLY = 2;
557   public static final int VISIBILITY_READ_WRITE = 3;
558   public static final int VISIBILITY_READ_ONLY_UNSETTABLE = 4;
559   public static final int VISIBILITY_READ_WRITE_UNSETTABLE = 5;
560
561   protected static final Pattern JavaDoc VISIBILITY_VALUE_PATTERN = Pattern.compile("\\s*\\(\\s*\"VisibilityKind\"\\s+([0-9]+)\\s*\\)");
562
563   public int getVisibility()
564   {
565     String JavaDoc attributeValue = getAttributeValue("Ecore", "visibility");
566     if (attributeValue != null)
567     {
568       Matcher JavaDoc matcher = VISIBILITY_VALUE_PATTERN.matcher(attributeValue);
569       if (matcher.matches())
570       {
571         return Integer.parseInt(matcher.group(1));
572       }
573     }
574     return VISIBILITY_UNSPECIFIED;
575   }
576
577   public String JavaDoc getAnnotation()
578   {
579     String JavaDoc attributeValue = getAttributeValue("Ecore", "annotation");
580     if ("".equals(attributeValue))
581     {
582       attributeValue = null;
583     }
584     return attributeValue;
585   }
586
587   /**
588    * This provides backwards compatibility for the renaming of "eCore" to
589    * "Ecore".
590    */

591   protected String JavaDoc getAttributeValue(String JavaDoc tool, String JavaDoc name)
592   {
593     String JavaDoc result = basicGetAttributeValue(tool, name);
594     if (result == null && "Ecore".equals(tool))
595     {
596       result = basicGetAttributeValue("eCore", name);
597     }
598     return result;
599   }
600
601   protected String JavaDoc basicGetAttributeValue(String JavaDoc tool, String JavaDoc name)
602   {
603     RoseNode attributeListNode = findNodeWithKey(RoseStrings.ATTRIBUTES);
604
605     String JavaDoc value = getAttributeValueInAttributeList(attributeListNode, tool, name);
606
607     if (value == null)
608     {
609       value = getAttributeValueInAttributeList(getDefaultAttributeList(tool), tool, name);
610     }
611
612     return value;
613   }
614
615   private String JavaDoc getAttributeValueInAttributeList(RoseNode attributeListNode, String JavaDoc tool, String JavaDoc name)
616   {
617     if (attributeListNode != null)
618     {
619       List JavaDoc attributeNodes = attributeListNode.getNodes();
620       if (attributeNodes != null)
621       {
622         for (Iterator JavaDoc i = attributeNodes.iterator(); i.hasNext();)
623         {
624           RoseNode attributeNode = (RoseNode)i.next();
625           List JavaDoc nodes = attributeNode.getNodes();
626           if (nodes != null)
627           {
628             String JavaDoc setName = "";
629             String JavaDoc tagName = "";
630             String JavaDoc valueName = "";
631             for (Iterator JavaDoc j = nodes.iterator(); j.hasNext();)
632             {
633               RoseNode node = (RoseNode)j.next();
634               if (node.getRoseNodeType() == RoseNode.STRING)
635               {
636                 String JavaDoc stringV = dequote(node.getValue());
637                 if (node.getKey().equals(RoseStrings.TOOL))
638                 {
639                   setName = stringV;
640                 }
641                 else if (node.getKey().equals(RoseStrings.NAME))
642                 {
643                   tagName = stringV;
644                 }
645                 else if (node.getKey().equals(RoseStrings.VALUE))
646                 {
647                   valueName = stringV;
648                 }
649               }
650               else if (node.getRoseNodeType() == RoseNode.STRING_SEQ)
651               {
652                 List JavaDoc subSubNodes = node.getNodes();
653                 String JavaDoc stringV = "";
654                 for (Iterator JavaDoc k = subSubNodes.iterator(); k.hasNext();)
655                 {
656                   RoseNode subSubNode = (RoseNode)k.next();
657                   if (subSubNode.getRoseNodeType() == RoseNode.STRING)
658                   {
659                     if (stringV.length() > 0)
660                     {
661                       stringV += " ";
662                     }
663                     stringV += subSubNode.getValue();
664                   }
665                 }
666                 if (node.getKey().equals(RoseStrings.TOOL))
667                 {
668                   setName = stringV;
669                 }
670                 else if (node.getKey().equals(RoseStrings.NAME))
671                 {
672                   tagName = stringV;
673                 }
674                 else if (node.getKey().equals(RoseStrings.VALUE))
675                 {
676                   valueName = stringV;
677                 }
678               }
679               else if (node.getRoseNodeType() == RoseNode.VALUE)
680               {
681                 List JavaDoc stringNodes = node.getNodes();
682                 if (stringNodes != null && stringNodes.size() == 1)
683                 {
684                   RoseNode stringNode = (RoseNode)stringNodes.get(0);
685                   String JavaDoc stringV = "";
686                   if (stringNode.getRoseNodeType() == RoseNode.STRING)
687                   {
688                     stringV = stringNode.getValue();
689                   }
690                   else if (stringNode.getRoseNodeType() == RoseNode.STRING_SEQ)
691                   {
692                     for (Iterator JavaDoc k = stringNode.getNodes().iterator(); k.hasNext();)
693                     {
694                       RoseNode subSubNode = (RoseNode)k.next();
695                       if (subSubNode.getRoseNodeType() == RoseNode.STRING)
696                       {
697                         if (stringV.length() > 0)
698                         {
699                           stringV += " ";
700                         }
701                         stringV += subSubNode.getValue();
702                       }
703                     }
704                   }
705                   stringV = dequote(stringV);
706                   if (node.getKey().equals(RoseStrings.TOOL))
707                   {
708                     setName = stringV;
709                   }
710                   else if (node.getKey().equals(RoseStrings.NAME))
711                   {
712                     tagName = stringV;
713                   }
714                   else if (node.getKey().equals(RoseStrings.VALUE))
715                   {
716                     valueName = stringV;
717                   }
718                 }
719               }
720             }
721             if (setName.equals(tool) && tagName.equals(name))
722             {
723               return valueName;
724             }
725           }
726         }
727       }
728     }
729     return null;
730   }
731
732   private RoseNode getDefaultAttributeList(String JavaDoc tool)
733   {
734     RoseNode attributeListNode = null;
735     RoseNode rootNode = getRoot();
736     String JavaDoc rootNodeValue = rootNode.getValue();
737     String JavaDoc rootObjectType = Util.getType(rootNodeValue);
738
739     if (rootObjectType.equals(RoseStrings.DESIGN))
740     {
741       String JavaDoc objectType = Util.getType(getValue());
742       RoseNode defaultProperties = rootNode.findNodeWithKey(RoseStrings.PROPERTIES);
743       if (defaultProperties != null)
744       {
745         RoseNode attributes = defaultProperties.findNodeWithKey(RoseStrings.ATTRIBUTES);
746         for (Iterator JavaDoc i = attributes.getNodes().iterator(); i.hasNext();)
747         {
748           RoseNode attribute = (RoseNode)i.next();
749           RoseNode toolNode = attribute.findNodeWithKey(RoseStrings.TOOL);
750           if (toolNode != null && Util.trimQuotes(toolNode.getValue()).equals(tool))
751           {
752             RoseNode nameNode = attribute.findNodeWithKey(RoseStrings.NAME);
753             String JavaDoc theName = Util.trimQuotes(nameNode.getValue());
754             if (objectType.equals(RoseStrings.CLASSATTRIBUTE) && theName.equals(RoseStrings.DEFAULT_ATTRIBUTE))
755             {
756               attributeListNode = attribute.findNodeWithKey(RoseStrings.VALUE);
757               break;
758             }
759             else if (objectType.equals(RoseStrings.CLASS) && theName.equals(RoseStrings.DEFAULT_CLASS))
760             {
761               attributeListNode = attribute.findNodeWithKey(RoseStrings.VALUE);
762               break;
763             }
764             else if (objectType.equals(RoseStrings.CLASS_CATEGORY) && theName.equals(RoseStrings.DEFAULT_CATEGORY))
765             {
766               attributeListNode = attribute.findNodeWithKey(RoseStrings.VALUE);
767               break;
768             }
769             else if (objectType.equals(RoseStrings.OPERATION) && theName.equals(RoseStrings.DEFAULT_OPERATION))
770             {
771               attributeListNode = attribute.findNodeWithKey(RoseStrings.VALUE);
772               break;
773             }
774             else if (objectType.equals(RoseStrings.ROLE) && theName.equals(RoseStrings.DEFAULT_ROLE))
775             {
776               attributeListNode = attribute.findNodeWithKey(RoseStrings.VALUE);
777               break;
778             }
779           }
780         }
781       }
782     }
783     return attributeListNode;
784   }
785
786   public String JavaDoc getRoleMultiplicity()
787   {
788     List JavaDoc nodes = getNodes();
789     for (int i = 0; i < nodes.size(); i++)
790     {
791       RoseNode node = (RoseNode)nodes.get(i);
792       if (node.getRoseNodeType() == RoseNode.VALUE)
793       {
794         String JavaDoc objKey = node.getKey();
795         String JavaDoc objType = Util.getType(node.getValue());
796         if (objKey.equals(RoseStrings.CLIENT_CARDINALITY) && objType.equals(RoseStrings.CARDINALITY))
797         {
798           List JavaDoc subNodes = node.getNodes();
799           String JavaDoc value = "";
800           for (int j = 0; j < subNodes.size(); j++)
801           {
802             // size should be 1
803
RoseNode subNode = (RoseNode)subNodes.get(j);
804             if (subNode.getRoseNodeType() == RoseNode.STRING)
805             {
806               value = subNode.getValue();
807               value = value.substring(1, value.length() - 1);
808             }
809             else if (subNode.getRoseNodeType() == RoseNode.STRING_SEQ)
810             {
811               // could this happen?
812
List JavaDoc subSubNodes = subNode.getNodes();
813               for (int k = 0; k < subSubNodes.size(); k++)
814               {
815                 RoseNode subSubNode = (RoseNode)subSubNodes.get(k);
816                 if (subSubNode.getRoseNodeType() == RoseNode.STRING)
817                   value = subSubNode.getValue() + "|#" + value;
818               }
819             }
820           }
821           return value;
822         }
823       }
824     }
825     return null;
826   }
827
828   protected static String JavaDoc dequote(String JavaDoc s)
829   {
830     if (s != null && s.length() >= 2 && s.charAt(0) == '\"' && s.charAt(s.length() - 1) == '\"')
831     {
832       s = s.substring(1, s.length() - 1);
833       for (int i = s.indexOf("\\\\"); i != -1; i = s.indexOf("\\\\"))
834       {
835         s = s.substring(0, i) + s.substring(i + 1, s.length());
836       }
837     }
838     return s;
839   }
840 }
841
Popular Tags