KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > actions > DeleteAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.actions;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedHashSet JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
35 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
36 import org.apache.directory.ldapstudio.browser.core.jobs.DeleteAttributesValueJob;
37 import org.apache.directory.ldapstudio.browser.core.jobs.DeleteEntriesJob;
38 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
39 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
40 import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
41 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
42 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
43 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
44 import org.apache.directory.ldapstudio.browser.core.model.IValue;
45 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
46 import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
47 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
48 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
49 import org.eclipse.jface.dialogs.MessageDialog;
50 import org.eclipse.jface.resource.ImageDescriptor;
51 import org.eclipse.ui.ISharedImages;
52 import org.eclipse.ui.PlatformUI;
53 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
54
55
56 /**
57  * This Action implements the Delete Action. It deletes Connections, Entries, Searches, Bookmarks, Attributes or Values.
58  *
59  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
60  * @version $Rev$, $Date$
61  */

62 public class DeleteAction extends BrowserAction
63 {
64     /**
65      * {@inheritDoc}
66      */

67     public String JavaDoc getText()
68     {
69         try
70         {
71             IConnection[] connections = getConnections();
72             IEntry[] entries = getEntries();
73             ISearch[] searches = getSearches();
74             IBookmark[] bookmarks = getBookmarks();
75             IAttribute[] attributes = getAttributes();
76             IValue[] values = getValues();
77
78             if ( connections.length > 0 && entries.length == 0 && searches.length == 0 && bookmarks.length == 0
79                 && attributes.length == 0 && values.length == 0 )
80             {
81                 return connections.length > 1 ? "Delete Connections" : "Delete Connection";
82             }
83             if ( entries.length > 0 && connections.length == 0 && searches.length == 0 && bookmarks.length == 0
84                 && attributes.length == 0 && values.length == 0 )
85             {
86                 return entries.length > 1 ? "Delete Entries" : "Delete Entry";
87             }
88             if ( searches.length > 0 && connections.length == 0 && entries.length == 0 && bookmarks.length == 0
89                 && attributes.length == 0 && values.length == 0 )
90             {
91                 return searches.length > 1 ? "Delete Searches" : "Delete Search";
92             }
93             if ( bookmarks.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
94                 && attributes.length == 0 && values.length == 0 )
95             {
96                 return bookmarks.length > 1 ? "Delete Bookmarks" : "Delete Bookmark";
97             }
98             if ( attributes.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
99                 && bookmarks.length == 0 && values.length == 0 )
100             {
101                 return attributes.length > 1 ? "Delete Attributes" : "Delete Attribute";
102             }
103             if ( values.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
104                 && bookmarks.length == 0 && attributes.length == 0 )
105             {
106                 return values.length > 1 ? "Delete Values" : "Delete Value";
107             }
108         }
109         catch ( Exception JavaDoc e )
110         {
111         }
112
113         return "Delete";
114     }
115
116
117     /**
118      * {@inheritDoc}
119      */

120     public ImageDescriptor getImageDescriptor()
121     {
122         return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_DELETE );
123     }
124
125
126     /**
127      * {@inheritDoc}
128      */

129     public String JavaDoc getCommandId()
130     {
131         return IWorkbenchActionDefinitionIds.DELETE;
132     }
133
134
135     /**
136      * {@inheritDoc}
137      */

138     public void run()
139     {
140         try
141         {
142             IConnection[] connections = getConnections();
143             IEntry[] entries = getEntries();
144             ISearch[] searches = getSearches();
145             IBookmark[] bookmarks = getBookmarks();
146             IAttribute[] attributes = getAttributes();
147             IValue[] values = getValues();
148
149             StringBuffer JavaDoc message = new StringBuffer JavaDoc();
150
151             if ( connections.length > 0 )
152             {
153                 if ( connections.length <= 5 )
154                 {
155                     message.append( connections.length == 1 ? "Are your sure to delete the following connection?"
156                         : "Are your sure to delete the following connections?" );
157                     for ( int i = 0; i < connections.length; i++ )
158                     {
159                         message.append( BrowserCoreConstants.LINE_SEPARATOR );
160                         message.append( " - " );
161                         message.append( connections[i].getName() );
162                     }
163                 }
164                 else
165                 {
166                     message.append( "Are your sure to delete the selected connections?" );
167                 }
168                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
169                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
170             }
171
172             if ( entries.length > 0 )
173             {
174                 if ( entries.length <= 5 )
175                 {
176                     message
177                         .append( entries.length == 1 ? "Are your sure to delete the following entry, including all children?"
178                             : "Are your sure to delete the following entries, including all children?" );
179                     for ( int i = 0; i < entries.length; i++ )
180                     {
181                         message.append( BrowserCoreConstants.LINE_SEPARATOR );
182                         message.append( " - " );
183                         message.append( entries[i].getDn() );
184                     }
185                 }
186                 else
187                 {
188                     message.append( "Are your sure to delete the selected entries, including all children?" );
189                 }
190                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
191                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
192             }
193
194             if ( searches.length > 0 )
195             {
196                 if ( searches.length <= 5 )
197                 {
198                     message.append( searches.length == 1 ? "Are your sure to delete the following search?"
199                         : "Are your sure to delete the following searches?" );
200                     for ( int i = 0; i < searches.length; i++ )
201                     {
202                         message.append( BrowserCoreConstants.LINE_SEPARATOR );
203                         message.append( " - " );
204                         message.append( searches[i].getName() );
205                     }
206                 }
207                 else
208                 {
209                     message.append( "Are your sure to delete the selected searches?" );
210                 }
211                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
212                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
213             }
214
215             if ( bookmarks.length > 0 )
216             {
217                 if ( bookmarks.length <= 5 )
218                 {
219                     message.append( bookmarks.length == 1 ? "Are your sure to delete the following bookmark?"
220                         : "Are your sure to delete the following bookmarks?" );
221                     for ( int i = 0; i < bookmarks.length; i++ )
222                     {
223                         message.append( BrowserCoreConstants.LINE_SEPARATOR );
224                         message.append( " - " );
225                         message.append( bookmarks[i].getName() );
226                     }
227                 }
228                 else
229                 {
230                     message.append( "Are your sure to delete the selected bookmarks?" );
231                 }
232                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
233                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
234             }
235
236             if ( attributes.length > 0 )
237             {
238                 if ( attributes.length <= 5 )
239                 {
240                     message.append( attributes.length == 1 ? "Are your sure to delete the following attribute?"
241                         : "Are your sure to delete the following attribute?" );
242                     for ( int i = 0; i < attributes.length; i++ )
243                     {
244                         message.append( BrowserCoreConstants.LINE_SEPARATOR );
245                         message.append( " - " );
246                         message.append( attributes[i].getDescription() );
247                     }
248                 }
249                 else
250                 {
251                     message.append( "Are your sure to delete the selected attributes?" );
252                 }
253                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
254                 message.append( BrowserCoreConstants.LINE_SEPARATOR );
255             }
256
257             if ( values.length > 0 )
258             {
259                 boolean emptyValuesOnly = true;
260                 for ( int i = 0; i < values.length; i++ )
261                 {
262                     if ( !values[i].isEmpty() )
263                     {
264                         emptyValuesOnly = false;
265                     }
266                 }
267                 if ( !emptyValuesOnly )
268                 {
269                     if ( values.length <= 5 )
270                     {
271                         message.append( values.length == 1 ? "Are your sure to delete the following value?"
272                             : "Are your sure to delete the following values?" );
273                         for ( int i = 0; i < values.length; i++ )
274                         {
275                             message.append( BrowserCoreConstants.LINE_SEPARATOR );
276                             message.append( " - " );
277                             message.append( values[i].toString() );
278                         }
279                     }
280                     else
281                     {
282                         message.append( "Are your sure to delete the selected values?" );
283                     }
284                     message.append( BrowserCoreConstants.LINE_SEPARATOR );
285                     message.append( BrowserCoreConstants.LINE_SEPARATOR );
286                 }
287             }
288
289             if ( message.length() == 0 || MessageDialog.openConfirm( getShell(), getText(), message.toString() ) )
290             {
291
292                 if ( connections.length > 0 )
293                 {
294                     deleteConnections( connections );
295                 }
296                 if ( entries.length > 0 )
297                 {
298                     deleteEntries( entries );
299                 }
300                 if ( searches.length > 0 )
301                 {
302                     deleteSearches( searches );
303                 }
304                 if ( bookmarks.length > 0 )
305                 {
306                     deleteBookmarks( bookmarks );
307                 }
308                 if ( attributes.length + values.length > 0 )
309                 {
310
311                     List JavaDoc attributeList = new ArrayList JavaDoc( Arrays.asList( attributes ) );
312                     List JavaDoc valueList = new ArrayList JavaDoc( Arrays.asList( values ) );
313
314                     // filter empty attributes and values
315
for ( Iterator JavaDoc it = attributeList.iterator(); it.hasNext(); )
316                     {
317                         IAttribute att = ( IAttribute ) it.next();
318                         IValue[] vals = att.getValues();
319                         for ( int i = 0; i < vals.length; i++ )
320                         {
321                             if ( vals[i].isEmpty() )
322                             {
323                                 att.deleteEmptyValue();
324                             }
325                         }
326                         if ( att.getValueSize() == 0 )
327                         {
328                             try
329                             {
330                                 att.getEntry().deleteAttribute( att );
331                             }
332                             catch ( ModelModificationException e )
333                             {
334                             }
335                             it.remove();
336                         }
337                     }
338                     for ( Iterator JavaDoc it = valueList.iterator(); it.hasNext(); )
339                     {
340                         IValue value = ( IValue ) it.next();
341                         if ( value.isEmpty() )
342                         {
343                             value.getAttribute().deleteEmptyValue();
344                             it.remove();
345                         }
346                     }
347
348                     if ( !attributeList.isEmpty() || !valueList.isEmpty() )
349                     {
350                         deleteAttributesAndValues( ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList
351                             .size()] ), ( IValue[] ) valueList.toArray( new IValue[valueList.size()] ) );
352                     }
353                 }
354             }
355         }
356         catch ( Exception JavaDoc e )
357         {
358         }
359     }
360
361
362     /**
363      * {@inheritDoc}
364      */

365     public boolean isEnabled()
366     {
367         try
368         {
369             IConnection[] connections = getConnections();
370             IEntry[] entries = getEntries();
371             ISearch[] searches = getSearches();
372             IBookmark[] bookmarks = getBookmarks();
373             IAttribute[] attributes = getAttributes();
374             IValue[] values = getValues();
375
376             return connections.length + entries.length + searches.length + bookmarks.length + attributes.length
377                 + values.length > 0;
378
379         }
380         catch ( Exception JavaDoc e )
381         {
382             // e.printStackTrace();
383
return false;
384         }
385     }
386
387
388     /**
389      * Gets the Connections
390      *
391      * @return
392      * the Connections
393      * @throws Exception
394      * when a is opened
395      */

396     protected IConnection[] getConnections() throws Exception JavaDoc
397     {
398         for ( int i = 0; i < getSelectedConnections().length; i++ )
399         {
400             if ( getSelectedConnections()[i].isOpened() )
401             {
402                 throw new Exception JavaDoc();
403             }
404         }
405
406         return getSelectedConnections();
407     }
408
409
410     /**
411      * Deletes Connections
412      *
413      * @param connections
414      * the Connections to delete
415      */

416     protected void deleteConnections( IConnection[] connections )
417     {
418         for ( int i = 0; i < connections.length; i++ )
419         {
420             BrowserCorePlugin.getDefault().getConnectionManager().removeConnection( connections[i] );
421         }
422     }
423
424
425     /**
426      * Gets the Entries.
427      *
428      * @return
429      * the Entries
430      * @throws Exception
431      * when an Entry has parent Entries
432      */

433     protected IEntry[] getEntries() throws Exception JavaDoc
434     {
435         LinkedHashSet JavaDoc entriesSet = new LinkedHashSet JavaDoc();
436         for ( int i = 0; i < getSelectedEntries().length; i++ )
437         {
438             if ( !getSelectedEntries()[i].hasParententry() )
439             {
440                 throw new Exception JavaDoc();
441             }
442             entriesSet.add( getSelectedEntries()[i] );
443         }
444         for ( int i = 0; i < this.getSelectedSearchResults().length; i++ )
445         {
446             if ( !getSelectedSearchResults()[i].getEntry().hasParententry() )
447             {
448                 throw new Exception JavaDoc();
449             }
450             entriesSet.add( this.getSelectedSearchResults()[i].getEntry() );
451         }
452
453         IEntry[] allEntries = ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] );
454         for ( int i = 0; i < allEntries.length; i++ )
455         {
456             IEntry entry = allEntries[i];
457             if ( entriesSet.contains( entry.getParententry() ) )
458             {
459                 entriesSet.remove( entry );
460             }
461         }
462
463         return ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] );
464     }
465
466
467     /**
468      * Deletes Entries
469      *
470      * @param entries
471      * the Entries to delete
472      */

473     protected void deleteEntries( IEntry[] entries )
474     {
475         new DeleteEntriesJob( entries ).execute();
476     }
477
478
479     /**
480      * Gets the Searches
481      *
482      * @return
483      * the Searches
484      * @throws Exception
485      */

486     protected ISearch[] getSearches() throws Exception JavaDoc
487     {
488         return getSelectedSearches();
489     }
490
491
492     /**
493      * Delete Searches
494      *
495      * @param searches
496      * the Searches to delete
497      */

498     protected void deleteSearches( ISearch[] searches )
499     {
500         for ( int i = 0; i < searches.length; i++ )
501         {
502             ISearch search = searches[i];
503             search.getConnection().getSearchManager().removeSearch( search );
504         }
505     }
506
507
508     /**
509      * Get the Bookmarks
510      *
511      * @return
512      * @throws Exception
513      */

514     protected IBookmark[] getBookmarks() throws Exception JavaDoc
515     {
516         return getSelectedBookmarks();
517     }
518
519
520     /**
521      * Delete Bookmarks
522      *
523      * @param bookmarks
524      * the Bookmarks to delete
525      */

526     protected void deleteBookmarks( IBookmark[] bookmarks )
527     {
528         for ( int i = 0; i < bookmarks.length; i++ )
529         {
530             IBookmark bookmark = bookmarks[i];
531             bookmark.getConnection().getBookmarkManager().removeBookmark( bookmark );
532         }
533     }
534
535
536     /**
537      * Gets the Attributes
538      *
539      * @return
540      * the Attributes
541      * @throws Exception
542      */

543     protected IAttribute[] getAttributes() throws Exception JavaDoc
544     {
545
546         for ( int i = 0; i < getSelectedAttributes().length; i++ )
547         {
548             // check if a non-modifyable, must or objectClass attribute is
549
// selected
550
IAttribute att = getSelectedAttributes()[i];
551             if ( !SchemaUtils.isModifyable( att.getAttributeTypeDescription() ) || att.isMustAttribute()
552                 || att.isObjectClassAttribute() )
553             {
554                 throw new Exception JavaDoc();
555             }
556         }
557
558         for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
559         {
560             // check if a non-modifyable, must or objectClass attribute is
561
// selected
562
AttributeHierarchy ah = getSelectedAttributeHierarchies()[i];
563             for ( Iterator JavaDoc it = ah.iterator(); it.hasNext(); )
564             {
565                 IAttribute attribute = ( IAttribute ) it.next();
566                 if ( !SchemaUtils.isModifyable( attribute.getAttributeTypeDescription() )
567                     || attribute.isMustAttribute() || attribute.isObjectClassAttribute() )
568                 {
569                     throw new Exception JavaDoc();
570                 }
571             }
572         }
573
574         List JavaDoc attributeList = new ArrayList JavaDoc();
575
576         // add selected attributes
577
for ( int i = 0; i < getSelectedAttributes().length; i++ )
578         {
579             IAttribute attribute = getSelectedAttributes()[i];
580             if ( attribute != null && attribute.getValueSize() > 0 )
581             {
582                 attributeList.add( attribute );
583             }
584         }
585
586         // add selected hierarchies
587
for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
588         {
589             // check if a operational, must or objectClass attribute is
590
// selected
591
AttributeHierarchy ah = getSelectedAttributeHierarchies()[i];
592             for ( Iterator JavaDoc it = ah.iterator(); it.hasNext(); )
593             {
594                 IAttribute attribute = ( IAttribute ) it.next();
595                 if ( attribute != null && attribute.getValueSize() > 0 )
596                 {
597                     attributeList.add( attribute );
598                 }
599             }
600         }
601
602         // check if ALL values of an attribute are selected -> delete whole
603
// attribute
604
Map JavaDoc attributeNameToSelectedValuesCountMap = new HashMap JavaDoc();
605         for ( int i = 0; i < getSelectedValues().length; i++ )
606         {
607             if ( !attributeNameToSelectedValuesCountMap.containsKey( getSelectedValues()[i].getAttribute()
608                 .getDescription() ) )
609             {
610                 attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
611                     new Integer JavaDoc( 0 ) );
612             }
613             int count = ( ( Integer JavaDoc ) attributeNameToSelectedValuesCountMap.get( getSelectedValues()[i].getAttribute()
614                 .getDescription() ) ).intValue() + 1;
615             attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
616                 new Integer JavaDoc( count ) );
617             if ( count >= getSelectedValues()[i].getAttribute().getValueSize() )
618             {
619                 IAttribute attribute = getSelectedValues()[i].getAttribute();
620                 if ( attribute != null && !attributeList.contains( attribute ) )
621                 {
622                     attributeList.add( attribute );
623                 }
624             }
625         }
626
627         return ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList.size()] );
628     }
629
630
631     /**
632      * Gets the Values
633      *
634      * @return
635      * the Values
636      * @throws Exception
637      */

638     protected IValue[] getValues() throws Exception JavaDoc
639     {
640
641         Map JavaDoc attributeNameToSelectedValuesCountMap = new HashMap JavaDoc();
642         Set JavaDoc selectedObjectClasses = new HashSet JavaDoc();
643         for ( int i = 0; i < getSelectedValues().length; i++ )
644         {
645             // check if a value of an operational attribute is selected
646
if ( !SchemaUtils.isModifyable( getSelectedValues()[i].getAttribute().getAttributeTypeDescription() ) )
647             {
648                 throw new Exception JavaDoc();
649             }
650
651             // check if (part of) RDN is selected
652
RDNPart[] parts = this.getSelectedValues()[i].getAttribute().getEntry().getRdn().getParts();
653             for ( int p = 0; p < parts.length; p++ )
654             {
655                 if ( getSelectedValues()[i].getAttribute().getDescription().equals( parts[p].getType() )
656                     && getSelectedValues()[i].getStringValue().equals( parts[p].getValue() ) )
657                 {
658                     throw new Exception JavaDoc();
659                 }
660             }
661
662             // check if a required objectClass is selected
663
if ( getSelectedValues()[i].getAttribute().isObjectClassAttribute() )
664             {
665                 selectedObjectClasses.add( getSelectedValues()[i].getStringValue() );
666             }
667
668             // check if ALL values of objectClass or a MUST attribute are
669
// selected
670
if ( !attributeNameToSelectedValuesCountMap.containsKey( getSelectedValues()[i].getAttribute()
671                 .getDescription() ) )
672             {
673                 attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
674                     new Integer JavaDoc( 0 ) );
675             }
676             int count = ( ( Integer JavaDoc ) attributeNameToSelectedValuesCountMap.get( getSelectedValues()[i].getAttribute()
677                 .getDescription() ) ).intValue() + 1;
678             attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
679                 new Integer JavaDoc( count ) );
680             if ( ( getSelectedValues()[i].getAttribute().isObjectClassAttribute() || getSelectedValues()[i]
681                 .getAttribute().isMustAttribute() /*
682              * || this.selectedEntry ==
683              * null
684              */
)
685                 && count >= getSelectedValues()[i].getAttribute().getValueSize() )
686             {
687                 throw new Exception JavaDoc();
688             }
689         }
690         // check if a required objectClass is selected
691
if ( getSelectedValues().length > 0 && !selectedObjectClasses.isEmpty() )
692         {
693             IEntry entry = getSelectedValues()[0].getAttribute().getEntry();
694             // get remaining attributes
695
String JavaDoc[] ocValues = entry.getSubschema().getObjectClassNames();
696             Set JavaDoc remainingObjectClassesSet = new HashSet JavaDoc( Arrays.asList( ocValues ) );
697             remainingObjectClassesSet.removeAll( selectedObjectClasses );
698             Set JavaDoc remainingAttributeSet = new HashSet JavaDoc();
699             for ( Iterator JavaDoc it = remainingObjectClassesSet.iterator(); it.hasNext(); )
700             {
701                 String JavaDoc oc = ( String JavaDoc ) it.next();
702                 ObjectClassDescription ocd = entry.getConnection().getSchema().getObjectClassDescription( oc );
703                 if ( ocd != null )
704                 {
705                     remainingAttributeSet
706                         .addAll( Arrays.asList( ocd.getMustAttributeTypeDescriptionNamesTransitive() ) );
707                     remainingAttributeSet.addAll( Arrays.asList( ocd.getMayAttributeTypeDescriptionNamesTransitive() ) );
708                 }
709             }
710             // check against attributes
711
IAttribute[] attributes = entry.getAttributes();
712             for ( int i = 0; i < attributes.length; i++ )
713             {
714                 IAttribute attribute = attributes[i];
715                 if ( attribute.isMayAttribute() || attribute.isMustAttribute() )
716                 {
717                     if ( !remainingAttributeSet.contains( attribute.getType() ) )
718                     {
719                         throw new Exception JavaDoc();
720                     }
721                 }
722             }
723         }
724
725         List JavaDoc valueList = new ArrayList JavaDoc();
726
727         // add selected values
728
Set JavaDoc attributeSet = new HashSet JavaDoc( Arrays.asList( getAttributes() ) );
729         for ( int i = 0; i < getSelectedValues().length; i++ )
730         {
731             if ( !attributeSet.contains( getSelectedValues()[i].getAttribute() ) )
732             {
733                 valueList.add( getSelectedValues()[i] );
734             }
735         }
736
737         return ( IValue[] ) valueList.toArray( new IValue[valueList.size()] );
738     }
739
740
741     /**
742      * Deletes Attributes and Values
743      *
744      * @param attributes
745      * the Attributes to delete
746      * @param values
747      * the Values to delete
748      */

749     protected void deleteAttributesAndValues( IAttribute[] attributes, IValue[] values )
750     {
751         new DeleteAttributesValueJob( attributes, values ).execute();
752     }
753 }
754
Popular Tags