View Javadoc

1   package org.apache.maven.repository.metadata;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.ArtifactScopeEnum;
24  
25  /**
26   * metadata [dirty] Tree
27   *
28   * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
29   *
30   */
31  public class MetadataTreeNode
32  {
33      ArtifactMetadata md; // this node
34  
35      MetadataTreeNode parent; // papa
36  
37      /** default # of children. Used for tree creation optimization only */
38      int nChildren = 8;
39  
40      MetadataTreeNode[] children; // of cause
41  
42      public int getNChildren()
43      {
44          return nChildren;
45      }
46  
47      public void setNChildren( int children )
48      {
49          nChildren = children;
50      }
51  
52      //------------------------------------------------------------------------
53      public MetadataTreeNode()
54      {
55      }
56      //------------------------------------------------------------------------
57      public MetadataTreeNode( ArtifactMetadata md, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope )
58      {
59          if ( md != null )
60          {
61              md.setArtifactScope( ArtifactScopeEnum.checkScope( scope ) );
62              md.setResolved( resolved );
63          }
64  
65          this.md = md;
66          this.parent = parent;
67      }
68      //------------------------------------------------------------------------
69      public MetadataTreeNode( Artifact af, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope )
70      {
71          this( new ArtifactMetadata( af ), parent, resolved, scope );
72      }
73  
74      // ------------------------------------------------------------------------
75      public void addChild( int index, MetadataTreeNode kid )
76      {
77          if ( kid == null )
78          {
79              return;
80          }
81  
82          if ( children == null )
83          {
84              children = new MetadataTreeNode[nChildren];
85          }
86  
87          children[index % nChildren] = kid;
88      }
89  
90      //------------------------------------------------------------------
91      @Override
92      public String toString()
93      {
94          return md == null ? "no metadata" : md.toString();
95      }
96  
97      //------------------------------------------------------------------
98      public String graphHash()
99          throws MetadataResolutionException
100     {
101         if ( md == null )
102         {
103             throw new MetadataResolutionException( "treenode without metadata, parent: "
104                 + ( parent == null ? "null" : parent.toString() ) );
105         }
106 
107         return md.groupId + ":" + md.artifactId;
108     }
109 
110     //------------------------------------------------------------------------
111     public boolean hasChildren()
112     {
113         return children != null;
114     }
115     //------------------------------------------------------------------------
116     public ArtifactMetadata getMd()
117     {
118         return md;
119     }
120 
121     public void setMd( ArtifactMetadata md )
122     {
123         this.md = md;
124     }
125 
126     public MetadataTreeNode getParent()
127     {
128         return parent;
129     }
130 
131     public void setParent( MetadataTreeNode parent )
132     {
133         this.parent = parent;
134     }
135 
136     public MetadataTreeNode[] getChildren()
137     {
138         return children;
139     }
140 
141     public void setChildren( MetadataTreeNode[] children )
142     {
143         this.children = children;
144     }
145     //------------------------------------------------------------------------
146     //------------------------------------------------------------------------
147 
148 }