001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.core.util.matrices;
025    
026    import java.util.ArrayList;
027    import java.util.List;
028    
029    import org.ujmp.core.Matrix;
030    import org.ujmp.core.MatrixFactory;
031    import org.ujmp.core.enums.ValueType;
032    import org.ujmp.core.stringmatrix.stub.AbstractDenseStringMatrix2D;
033    import org.ujmp.core.util.AbstractPlugin;
034    
035    public class UJMPPluginsMatrix extends AbstractDenseStringMatrix2D {
036            private static final long serialVersionUID = 9076856922668700140L;
037    
038            private final List<String> classes = new ArrayList<String>();
039    
040            private Matrix matrix = null;
041    
042            public UJMPPluginsMatrix() {
043                    addClass("ujmp-core");
044                    addClass("ujmp-gui");
045                    addClass("ujmp-colt");
046                    addClass("ujmp-commonsmath");
047                    addClass("ujmp-ehcache");
048                    addClass("ujmp-ejml");
049                    addClass("ujmp-hadoop");
050                    addClass("ujmp-itext");
051                    addClass("ujmp-jackcess");
052                    addClass("ujmp-jama");
053                    addClass("ujmp-jampack");
054                    addClass("ujmp-jblas");
055                    addClass("ujmp-jbpcafill");
056                    addClass("ujmp-jlinalg");
057                    addClass("ujmp-jdbc");
058                    addClass("ujmp-jexcelapi");
059                    addClass("ujmp-jfreechart");
060                    addClass("ujmp-jmatharray");
061                    addClass("ujmp-jmathplot");
062                    addClass("ujmp-jmatio");
063                    addClass("ujmp-jmatrices");
064                    addClass("ujmp-jsci");
065                    addClass("ujmp-jscience");
066                    addClass("ujmp-jung");
067                    addClass("ujmp-lsimpute");
068                    addClass("ujmp-lucene");
069                    addClass("ujmp-mail");
070                    addClass("ujmp-mantissa");
071                    addClass("ujmp-mtj");
072                    addClass("ujmp-ojalgo");
073                    addClass("ujmp-orbital");
074                    addClass("ujmp-owlpack");
075                    addClass("ujmp-parallelcolt");
076                    addClass("ujmp-pdfbox");
077                    addClass("ujmp-sst");
078                    addClass("ujmp-vecmath");
079                    refresh();
080                    setLabel("UJMP Plugins");
081                    setColumnLabel(0, "Name");
082                    setColumnLabel(1, "Available");
083                    setColumnLabel(2, "Description");
084                    setColumnLabel(3, "Dependencies");
085                    setColumnLabel(4, "Status");
086            }
087    
088            public void refresh() {
089                    matrix = MatrixFactory.dense(ValueType.STRING, classes.size(), 5);
090    
091                    int r = 0;
092    
093                    for (String s : classes) {
094    
095                            matrix.setAsString(s, r, 0);
096    
097                            Class<?> cl = null;
098                            if (s.startsWith("ujmp")) {
099                                    try {
100                                            cl = Class.forName("org.ujmp." + s.substring(5) + ".Plugin");
101                                    } catch (ClassNotFoundException e) {
102                                    }
103                            } else {
104                                    try {
105                                            cl = Class.forName("org.jdmp." + s.substring(5) + ".Plugin");
106                                    } catch (ClassNotFoundException e) {
107                                    }
108                            }
109    
110                            AbstractPlugin o = null;
111                            if (cl != null) {
112                                    try {
113                                            o = (AbstractPlugin) cl.newInstance();
114                                    } catch (Exception e) {
115                                    }
116                            }
117    
118                            if (o != null) {
119                                    try {
120                                            matrix.setAsString("yes", r, 1);
121                                            matrix.setAsString(o.getDescription(), r, 2);
122                                            matrix.setAsString("" + o.getDependencies(), r, 3);
123                                            matrix.setAsString(o.getStatus(), r, 4);
124                                    } catch (Throwable t) {
125                                            matrix.setAsString("no", r, 1);
126                                            matrix.setAsString("n/a", r, 2);
127                                            matrix.setAsString("n/a", r, 3);
128                                            matrix.setAsString(t.getMessage(), r, 4);
129                                    }
130                            } else {
131                                    matrix.setAsString("no", r, 1);
132                                    matrix.setAsString("n/a", r, 2);
133                                    matrix.setAsString("n/a", r, 3);
134                                    matrix.setAsString("n/a", r, 4);
135                            }
136    
137                            r++;
138    
139                    }
140            }
141    
142            protected void addClass(String c) {
143                    classes.add(c);
144            }
145    
146            public String getString(long row, long column) {
147                    return matrix.getAsString(row, column);
148            }
149    
150            public void setString(String value, long row, long column) {
151            }
152    
153            public long[] getSize() {
154                    return matrix.getSize();
155            }
156    
157    }