001    /*
002     * JBoss, Home of Professional Open Source.
003     * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004     * as indicated by the @author tags. See the copyright.txt file in the
005     * distribution for a full listing of individual contributors. 
006     *
007     * This is free software; you can redistribute it and/or modify it
008     * under the terms of the GNU Lesser General Public License as
009     * published by the Free Software Foundation; either version 2.1 of
010     * the License, or (at your option) any later version.
011     *
012     * This software is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * Lesser General Public License for more details.
016     *
017     * You should have received a copy of the GNU Lesser General Public
018     * License along with this software; if not, write to the Free
019     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021     */
022    package org.jboss.example.dna.sequencers;
023    
024    import java.util.List;
025    import java.util.Map;
026    import java.util.Properties;
027    import java.util.TreeMap;
028    import net.jcip.annotations.Immutable;
029    
030    /**
031     * @author Serge Pagop
032     * @author Randall Hauch
033     */
034    @Immutable
035    public class JavaInfo extends ContentInfo {
036    
037        private final Map<String, List<Properties>> javaElements;
038        private final String type;
039    
040        protected JavaInfo( String path,
041                            String name,
042                            String type,
043                            Map<String, List<Properties>> javaElements ) {
044            super(path, name, null);
045            this.type = type;
046            this.javaElements = javaElements != null ? new TreeMap<String, List<Properties>>(javaElements) : new TreeMap<String, List<Properties>>();
047        }
048    
049        public String getType() {
050            return this.type;
051        }
052    
053        /**
054         * @return javaElements
055         */
056        public Map<String, List<Properties>> getJavaElements() {
057            return javaElements;
058        }
059    
060        @Override
061        public String toString() {
062            StringBuilder sb = new StringBuilder();
063            sb.append("   Name: " + getName() + "\n");
064            sb.append("   Path: " + getPath() + "\n");
065            sb.append("   Type: " + getType() + "\n");
066            for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
067                sb.append("   " + entry.getKey() + ": " + entry.getValue() + "\n");
068            }
069            for (Map.Entry<String, List<Properties>> javaElement : getJavaElements().entrySet()) {
070                sb.append("\n   ------ " + javaElement.getKey() + " ------\n");
071                for (Properties props : javaElement.getValue()) {
072                    for (Map.Entry<Object, Object> entry : props.entrySet()) {
073                        if (!entry.getKey().equals("jcr:primaryType")) {
074                            sb.append("   " + entry.getKey() + " => " + entry.getValue() + "\n");
075                        }
076                    }
077                }
078            }
079            return sb.toString();
080        }
081    
082    }