001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.core;
028    
029    
030    import java.util.Collections;
031    import java.util.List;
032    import java.util.concurrent.CopyOnWriteArrayList;
033    
034    
035    /**
036     * This classes defines a list of naming contexts for a network group.
037     */
038    public class NetworkGroupNamingContexts
039    {
040      // List of naming contexts.
041      private List<WorkflowTopologyNode> namingContexts;
042      // If list of naming contexts is returned, ensure it is immutable
043      private List<WorkflowTopologyNode> _namingContexts;
044    
045      // List of public naming contexts.
046      private List<WorkflowTopologyNode> publicNamingContexts;
047      // If list of public naming contexts is returned, ensure it is immutable
048      private List<WorkflowTopologyNode> _publicNamingContexts;
049    
050      // List of private naming contexts.
051      private List<WorkflowTopologyNode> privateNamingContexts;
052      // If list of private naming contexts is returned, ensure it is immutable
053      private List<WorkflowTopologyNode> _privateNamingContexts;
054    
055      /**
056       * Create a list of naming contexts for a network group.
057       */
058      public NetworkGroupNamingContexts()
059      {
060        namingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
061        _namingContexts = Collections.unmodifiableList(namingContexts);
062    
063        privateNamingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
064        _privateNamingContexts =
065                                Collections.unmodifiableList(privateNamingContexts);
066    
067        publicNamingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
068        _publicNamingContexts = Collections.unmodifiableList(publicNamingContexts);
069      }
070    
071    
072      /**
073       * Reset the list of naming contexts.
074       */
075      public void resetLists()
076      {
077        namingContexts.clear();
078        privateNamingContexts.clear();
079        publicNamingContexts.clear();
080      }
081    
082    
083      /**
084       * Add a workflow in the list of naming context.
085       *
086       * @param workflow  the workflow to add in the list of naming contexts
087       */
088      public void addNamingContext (
089          WorkflowTopologyNode workflow
090          )
091      {
092        // add the workflow to the list of naming context
093        namingContexts.add (workflow);
094    
095        // add the workflow to the private/public list of naming contexts
096        if (workflow.isPrivate())
097        {
098          privateNamingContexts.add (workflow);
099        }
100        else
101        {
102          publicNamingContexts.add (workflow);
103        }
104      }
105    
106    
107      /**
108       * Get the list of naming contexts.
109       *
110       * <br>Note: the returned iterable instance is immutable and attempts to
111       * remove elements will throw an UnsupportedOperationException exception.
112       *
113       * @return the list of all the naming contexts
114       */
115      public Iterable<WorkflowTopologyNode> getNamingContexts()
116      {
117        return _namingContexts;
118      }
119    
120    
121      /**
122       * Get the list of private naming contexts.
123       *
124       * <br>Note: the returned iterable instance is immutable and attempts to
125       * remove elements will throw an UnsupportedOperationException exception.
126       *
127       * @return the list of private naming contexts
128       */
129      public Iterable<WorkflowTopologyNode> getPrivateNamingContexts()
130      {
131        return _privateNamingContexts;
132      }
133    
134    
135      /**
136       * Get the list of public naming contexts.
137       *
138       * <br>Note: the returned iterable instance is immutable and attempts to
139       * remove elements will throw an UnsupportedOperationException exception.
140       *
141       * @return the list of public naming contexts
142       */
143      public Iterable<WorkflowTopologyNode> getPublicNamingContexts()
144      {
145        return _publicNamingContexts;
146      }
147    
148    
149      /**
150       * Dumps info from the current networkk group for debug purpose.
151       *
152       * @param  leftMargin  white spaces used to indent traces
153       * @return a string buffer that contains trace information
154       */
155      public StringBuilder toString (String leftMargin)
156      {
157        StringBuilder sb = new StringBuilder();
158        String newMargin = leftMargin + "   ";
159    
160        sb.append (leftMargin + "List of naming contexts:\n");
161        for (WorkflowTopologyNode w: namingContexts)
162        {
163          sb.append (w.toString (newMargin));
164        }
165    
166        sb.append (leftMargin + "List of PRIVATE naming contexts:\n");
167        for (WorkflowTopologyNode w: privateNamingContexts)
168        {
169          sb.append (w.toString (newMargin));
170        }
171    
172        sb.append (leftMargin + "List of PUBLIC naming contexts:\n");
173        for (WorkflowTopologyNode w: publicNamingContexts)
174        {
175          sb.append (w.toString (newMargin));
176        }
177    
178        return sb;
179      }
180    
181    }