001    /*
002     * Copyright 2001,2004 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.apache.commons.jjar;
018    
019    import java.util.HashMap;
020    
021    /**
022     *  little class to handle the
023     *  package/version duple.
024     *  
025     *  the intent was to extend to carry more 
026     *  information, but the repository seems to
027     *  be doing ok for that.
028     *
029     *  It might be nice to continue here though
030     *  and make the repository surface area smaller
031     * 
032     *  @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
033     *  @version $Id: JJARPackage.java 155454 2005-02-26 13:23:34Z dirkv $
034     */
035    public class JJARPackage 
036    {
037        private String name;
038        private Version version;
039        private HashMap properties;
040        
041        private static String DESC = "desc";
042        private static String JAR = "jar";
043        private static String HREF = "href";
044       
045        /**
046         *  usual CTOR
047         */
048        public JJARPackage( String name, String version )
049        {
050            this.name = name;
051            this.version = new Version(version);
052        }
053    
054        /**
055         *  ctor for <package>:<version> unispec
056         */
057        public JJARPackage( String onepiece )
058        {
059            int i = onepiece.indexOf(":");
060            
061            if (i != -1 )
062            {
063                this.name = onepiece.substring(0, i );
064                this.version = new Version( onepiece.substring( i + 1 ) );
065            }
066        }
067    
068        public String getName() 
069        {
070            return name;
071        }
072        
073        public Version getVersion()
074        {
075            return version;
076        }
077        
078        public String getVersionString()
079        {
080            return version.toString();
081        }
082    
083        public boolean equals( JJARPackage jpack )
084        {
085            return equals( jpack.getName(), jpack.getVersionString() );
086        }
087      
088        public boolean equals( String pkg, String ver )
089        {
090            if ( pkg != null && this.name.equals( pkg ) )
091            {
092                // do something better here ?
093    
094                if ( ver != null && version.equals( ver ) )
095                {
096                    return true;
097                }
098            }
099                    
100            return false;
101        }
102    }  
103    
104    
105