001//
002// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2 
003// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
004// Any modifications to this file will be lost upon recompilation of the source schema. 
005// Generated on: 2016.09.01 at 05:41:23 AM CEST 
006//
007
008
009package org.jomc.modlet;
010
011import java.util.ArrayList;
012import java.util.Iterator;
013import java.util.List;
014import javax.annotation.Generated;
015import javax.xml.bind.annotation.XmlAccessType;
016import javax.xml.bind.annotation.XmlAccessorType;
017import javax.xml.bind.annotation.XmlElement;
018import javax.xml.bind.annotation.XmlType;
019
020
021/**
022 * List of modlets.
023 * 
024 * <p>Java class for Modlets complex type.
025 * 
026 * <p>The following schema fragment specifies the expected content contained within this class.
027 * 
028 * <pre>
029 * &lt;complexType name="Modlets">
030 *   &lt;complexContent>
031 *     &lt;extension base="{http://jomc.org/modlet}ModletObject">
032 *       &lt;sequence>
033 *         &lt;element ref="{http://jomc.org/modlet}modlet" maxOccurs="unbounded" minOccurs="0"/>
034 *       &lt;/sequence>
035 *     &lt;/extension>
036 *   &lt;/complexContent>
037 * &lt;/complexType>
038 * </pre>
039 * 
040 * 
041 */
042@XmlAccessorType(XmlAccessType.FIELD)
043@XmlType(name = "Modlets", namespace = "http://jomc.org/modlet", propOrder = {
044    "modlet"
045})
046@Generated(value = "com.sun.tools.xjc.Driver", date = "2016-09-01T05:41:23+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
047public class Modlets
048    extends ModletObject
049    implements Cloneable
050{
051
052    @XmlElement(namespace = "http://jomc.org/modlet")
053    @Generated(value = "com.sun.tools.xjc.Driver", date = "2016-09-01T05:41:23+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
054    protected List<Modlet> modlet;
055
056    /**
057     * Creates a new {@code Modlets} instance.
058     * 
059     */
060    public Modlets() {
061        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
062        super();
063    }
064
065    /**
066     * Creates a new {@code Modlets} instance by deeply copying a given {@code Modlets} instance.
067     * 
068     * 
069     * @param o
070     *     The instance to copy.
071     * @throws NullPointerException
072     *     if {@code o} is {@code null}.
073     */
074    public Modlets(final Modlets o) {
075        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
076        super(o);
077        if (o == null) {
078            throw new NullPointerException("Cannot create a copy of 'Modlets' from 'null'.");
079        }
080        // 'Modlet' collection.
081        if (o.modlet!= null) {
082            copyModlet(o.getModlet(), this.getModlet());
083        }
084    }
085
086    /**
087     * Gets the value of the modlet property.
088     * 
089     * <p>
090     * This accessor method returns a reference to the live list,
091     * not a snapshot. Therefore any modification you make to the
092     * returned list will be present inside the JAXB object.
093     * This is why there is not a <CODE>set</CODE> method for the modlet property.
094     * 
095     * <p>
096     * For example, to add a new item, do as follows:
097     * <pre>
098     *    getModlet().add(newItem);
099     * </pre>
100     * 
101     * 
102     * <p>
103     * Objects of the following type(s) are allowed in the list
104     * {@link Modlet }
105     * 
106     * 
107     */
108    @Generated(value = "com.sun.tools.xjc.Driver", date = "2016-09-01T05:41:23+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
109    public List<Modlet> getModlet() {
110        if (modlet == null) {
111            modlet = new ArrayList<Modlet>();
112        }
113        return this.modlet;
114    }
115
116    /**
117     * Copies all values of property {@code Modlet} deeply.
118     * 
119     * @param source
120     *     The source to copy from.
121     * @param target
122     *     The target to copy {@code source} to.
123     * @throws NullPointerException
124     *     if {@code target} is {@code null}.
125     */
126    @SuppressWarnings("unchecked")
127    @Generated(value = "com.sun.tools.xjc.Driver", date = "2016-09-01T05:41:23+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
128    private static void copyModlet(final List<Modlet> source, final List<Modlet> target) {
129        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
130        if ((source!= null)&&(!source.isEmpty())) {
131            for (final Iterator<?> it = source.iterator(); it.hasNext(); ) {
132                final Object next = it.next();
133                if (next instanceof Modlet) {
134                    // CClassInfo: org.jomc.modlet.Modlet
135                    target.add(((Modlet) next).clone());
136                    continue;
137                }
138                // Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
139                throw new AssertionError((("Unexpected instance '"+ next)+"' for property 'Modlet' of class 'org.jomc.modlet.Modlets'."));
140            }
141        }
142    }
143
144    /**
145     * Creates and returns a deep copy of this object.
146     * 
147     * 
148     * @return
149     *     A deep copy of this object.
150     */
151    @Override
152    @Generated(value = "com.sun.tools.xjc.Driver", date = "2016-09-01T05:41:23+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
153    public Modlets clone() {
154        {
155            // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
156            final Modlets clone = ((Modlets) super.clone());
157            // 'Modlet' collection.
158            if (this.modlet!= null) {
159                clone.modlet = null;
160                copyModlet(this.getModlet(), clone.getModlet());
161            }
162            return clone;
163        }
164    }
165    
166    /**
167     * Gets a modlet for a given name from the list of modlets.
168     *
169     * @param name The name of the modlet to return.
170     *
171     * @return The first matching modlet or {@code null}, if no such modlet is found.
172     *
173     * @throws NullPointerException if {@code name} is {@code null}.
174     *
175     * @see #getModlet()
176     * @see Modlet#getName()
177     */
178    public Modlet getModlet( final String name )
179    {
180        if ( name == null )
181        {
182            throw new NullPointerException( "name" );
183        }
184
185        for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
186        {
187            final Modlet m = this.getModlet().get( i );
188
189            if ( name.equals( m.getName() ) )
190            {
191                return m;
192            }
193        }
194
195        return null;
196    }
197
198    /**
199     * Merges modlets of a model from this list of modlets to a single modlet.
200     *
201     * @param name The name of the modlet to return.
202     * @param model The identifier of the model of the modlet to return.
203     *
204     * @return A modlet holding all modlet objects of the model identified by {@code model} from the list.
205     *
206     * @throws NullPointerException if {@code name} or {@code model} is {@code null}.
207     *
208     * @see #getModlet()
209     * @see Modlet#getModel()
210     */
211    public Modlet getMergedModlet( final String name, final String model )
212    {
213        if ( name == null )
214        {
215            throw new NullPointerException( "name" );
216        }
217        if ( model == null )
218        {
219            throw new NullPointerException( "model" );
220        }
221
222        final Modlet mergedModlet = new Modlet();
223        mergedModlet.setName( name );
224        mergedModlet.setModel( model );
225
226        for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
227        {
228            final Modlet m = this.getModlet().get( i );
229
230            if ( model.equals( m.getModel() ) )
231            {
232                if ( m.getSchemas() != null )
233                {
234                    if ( mergedModlet.getSchemas() == null )
235                    {
236                        mergedModlet.setSchemas( new Schemas() );
237                    }
238
239                    for ( int j = 0, s1 = m.getSchemas().getSchema().size(); j < s1; j++ )
240                    {
241                        final Schema s = m.getSchemas().getSchema().get( j );
242
243                        if ( mergedModlet.getSchemas().getSchemaBySystemId( s.getSystemId() ) == null )
244                        {
245                            mergedModlet.getSchemas().getSchema().add( s );
246                        }
247                    }
248                }
249
250                if ( m.getServices() != null )
251                {
252                    if ( mergedModlet.getServices() == null )
253                    {
254                        mergedModlet.setServices( new Services() );
255                    }
256
257                    for ( int j = 0, s1 = m.getServices().getService().size(); j < s1; j++ )
258                    {
259                        final Service s = m.getServices().getService().get( j );
260                        boolean merged = false;
261
262                        for ( Service mergedService : mergedModlet.getServices().getServices( s.getIdentifier() ) )
263                        {
264                            if ( mergedService.getClazz().equals( s.getClazz() ) )
265                            {
266                                if ( mergedService.getOrdinal() < s.getOrdinal() )
267                                {
268                                    mergedService.setOrdinal( s.getOrdinal() );
269                                }
270
271                                merged = true;
272                            }
273                        }
274
275                        if ( !merged )
276                        {
277                            mergedModlet.getServices().getService().add( s );
278                        }
279                    }
280                }
281            }
282        }
283
284        return mergedModlet;
285    }
286
287    /**
288     * Gets schemas for a model from this list of modlets.
289     *
290     * @param model The identifier of the model to return schemas of.
291     *
292     * @return A list of schemas for {@code model} or {@code null}, if no such schemas are found.
293     *
294     * @throws NullPointerException if {@code model} is {@code null}.
295     *
296     * @see #getModlet()
297     * @see Modlet#getModel()
298     */
299    public Schemas getSchemas( final String model )
300    {
301        if ( model == null )
302        {
303            throw new NullPointerException( "model" );
304        }
305
306        final Schemas schemas = new Schemas();
307        boolean modelFound = false;
308
309        for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
310        {
311            final Modlet m = this.getModlet().get( i );
312
313            if ( m.getSchemas() != null && !m.getSchemas().getSchema().isEmpty()
314                     && ( ModletObject.MODEL_PUBLIC_ID.equals( m.getModel() ) || model.equals( m.getModel() ) ) )
315            {
316                modelFound |= model.equals( m.getModel() );
317
318                for ( int j = 0, s1 = m.getSchemas().getSchema().size(); j < s1; j++ )
319                {
320                    schemas.getSchema().add( m.getSchemas().getSchema().get( j ) );
321                }
322            }
323        }
324
325        return modelFound && !schemas.getSchema().isEmpty() ? schemas : null;
326    }
327
328    /**
329     * Gets schemas for a public identifier from this list of modlets.
330     *
331     * @param publicId The public identifier of the schemas to return.
332     *
333     * @return A list of schemas matching {@code publicId} or {@code null}, if no such schemas are found.
334     *
335     * @throws NullPointerException if {@code publicId} is {@code null}.
336     *
337     * @see #getModlet()
338     * @see Modlet#getSchemas()
339     * @see Schemas#getSchemasByPublicId(java.net.URI)
340     * @since 1.2
341     * @deprecated As of JOMC 1.8, removed without replacement. This method will be removed in JOMC 2.0.
342     */
343    @Deprecated
344    public Schemas getSchemas( final java.net.URI publicId )
345    {
346        if ( publicId == null )
347        {
348            throw new NullPointerException( "publicId" );
349        }
350
351        final Schemas schemas = new Schemas();
352
353        for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
354        {
355            final Modlet m = this.getModlet().get( i );
356
357            if ( m.getSchemas() != null )
358            {
359                schemas.getSchema().addAll( m.getSchemas().getSchemasByPublicId( publicId ) );
360            }
361        }
362
363        return schemas.getSchema().isEmpty() ? null : schemas;
364    }
365
366    /**
367     * Gets services for a model from this list of modlets.
368     *
369     * @param model The identifier of the model to return services of.
370     *
371     * @return A list of services for {@code model} or {@code null}, if no such services are found.
372     *
373     * @throws NullPointerException if {@code model} is {@code null}.
374     *
375     * @see #getModlet()
376     * @see Modlet#getModel()
377     */
378    public Services getServices( final String model )
379    {
380        if ( model == null )
381        {
382            throw new NullPointerException( "model" );
383        }
384
385        final Services services = new Services();
386        boolean modelFound = false;
387
388        for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
389        {
390            final Modlet m = this.getModlet().get( i );
391
392            if ( m.getServices() != null && !m.getServices().getService().isEmpty()
393                     && ( ModletObject.MODEL_PUBLIC_ID.equals( m.getModel() ) || model.equals( m.getModel() ) ) )
394            {
395                modelFound |= model.equals( m.getModel() );
396
397                for ( int j = 0, s1 = m.getServices().getService().size(); j < s1; j++ )
398                {
399                    services.getService().add( m.getServices().getService().get( j ) );
400                }
401            }
402        }
403
404        return modelFound && !services.getService().isEmpty() ? services : null;
405    }
406      
407}