code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/* * JarJarTest.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor.sandbox; /** * @author rb * */ public class JarJarTest { /** * @param args */ public static void main(String[] args) { // Main main = new Main(); //main.process(rulesFile, inJar, outJar) } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/sandbox/JarJarTest.java
Java
bsd
1,833
/* * ClassAnalysis.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor.analysis; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import org.gjt.jclasslib.io.ClassFileReader; import org.gjt.jclasslib.structures.CPInfo; import org.gjt.jclasslib.structures.ClassFile; import org.gjt.jclasslib.structures.InvalidByteCodeException; import org.gjt.jclasslib.structures.constants.ConstantClassInfo; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; /** * Analyzes a class and stores the result. * * @author rb * */ public class ClassClasspathElement extends AbstractClasspathElement { /** */ final ClassFile classFile; /** */ final ClassReader classReader; /** */ final String className; /** */ final Collection<String> nonSystemDepenencies = new ArrayList<String>(); /** */ final Collection<String> annotations = new ArrayList<String>(); /** * @param location * @param name * @throws IOException * @throws InvalidByteCodeException */ public ClassClasspathElement(AbstractClassPathLocation location, String name) throws IOException, InvalidByteCodeException { super(location, name); InputStream inputStream; // Use ASM inputStream = location.getInputStream(name); this.classReader = new ClassReader(inputStream); inputStream.close(); // Use jClassLib inputStream = location.getInputStream(name); this.classFile = ClassFileReader.readFromInputStream(inputStream); inputStream.close(); // Get base info this.className = this.classReader.getClassName().replaceAll("/", "."); // Get complex info detectDependencies(); detectAnnotations(); } /** * */ private void detectAnnotations() { this.classReader.accept(new ClassVisitor() { public void visitSource(String arg0, String arg1) { // TODO Auto-generated method stub } public void visitOuterClass(String arg0, String arg1, String arg2) { // TODO Auto-generated method stub } public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4) { // TODO Auto-generated method stub return null; } public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) { // TODO Auto-generated method stub } public FieldVisitor visitField(int arg0, String arg1, String arg2, String arg3, Object arg4) { // TODO Auto-generated method stub return null; } public void visitEnd() { // TODO Auto-generated method stub } public void visitAttribute(Attribute arg0) { // TODO Auto-generated method stub } public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { if (arg0 == null) return null; ClassClasspathElement.this.annotations.add(arg0.substring(1).replaceAll(";", "").replaceAll("/", ".")); return null; } public void visit(int arg0, int arg1, String arg2, String arg3, String arg4, String[] arg5) { // TODO Auto-generated method stub } }, 0); } /** * Load all dependencies */ private void detectDependencies() { final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); final CPInfo[] constantPool = this.classFile.getConstantPool(); for (CPInfo cpInfo : constantPool) { if (cpInfo instanceof ConstantClassInfo) { final ConstantClassInfo i = (ConstantClassInfo) cpInfo; String dependencyName = null; boolean isIrrelevant = false; // Check found dependency try { dependencyName = i.getName().replaceAll("/", "."); if (dependencyName.startsWith("[")) continue; // If this line returns the class was found and is probably irrelevant // FIXME: Also classes of this application are found! systemClassLoader.loadClass(dependencyName); isIrrelevant = true; } catch (InvalidByteCodeException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { // } catch (NoClassDefFoundError e) { // } // Add dependency if (!isIrrelevant && dependencyName != null && !dependencyName.equals(this.className)) { this.nonSystemDepenencies.add(dependencyName); } } } } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("ClassElement {\n"); sb.append(" name = " + this.className + "\n"); for (String s : this.nonSystemDepenencies) { sb.append(" dependency = " + s + "\n"); } for (String s : this.annotations) { sb.append(" annotation = " + s + "\n"); } sb.append("}"); return sb.toString(); } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/analysis/ClassClasspathElement.java
Java
bsd
7,642
/* * AbstractClasspathElement.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor.analysis; import java.io.IOException; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import org.gjt.jclasslib.structures.InvalidByteCodeException; /** * @author rb * */ public abstract class AbstractClasspathElement { final AbstractClassPathLocation location; final String name; /** * @param location * @param name */ public AbstractClasspathElement(AbstractClassPathLocation location, String name) { this.location = location; this.name = name; } /** * @param location * @param name * @return . */ public static AbstractClasspathElement newClassPathElement( AbstractClassPathLocation location, String name) { if (name.endsWith(".class")) { try { return new ClassClasspathElement(location, name); } catch (IOException e) { e.printStackTrace(); } catch (InvalidByteCodeException e) { e.printStackTrace(); } } return new CommonClasspathElement(location, name); } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/analysis/AbstractClasspathElement.java
Java
bsd
2,858
/* * CommonClasspathElement.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor.analysis; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; /** * @author rb * */ public class CommonClasspathElement extends AbstractClasspathElement { /** * @param location * @param name */ public CommonClasspathElement(AbstractClassPathLocation location, String name) { super(location, name); } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("FileElement {\n"); sb.append(" name = " + this.name + "\n"); sb.append("}"); return sb.toString(); } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/analysis/CommonClasspathElement.java
Java
bsd
2,302
/* * ConsoleDoctor.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor; import java.io.File; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import net.xeoh.plugins.base.impl.classpath.locator.ClassPathLocator; import net.xeoh.plugins.plugindoctor.analysis.AbstractClasspathElement; import net.xeoh.plugins.plugindoctor.output.JARWriter; /** * @author rb * */ public class ConsoleDoctor { /** * * @param args */ public static void main(String[] args) { final ConsoleDoctor consoleDoctor = new ConsoleDoctor(); final Collection<URI> projectPath = new ArrayList<URI>(); projectPath.add(new File("bin/").toURI()); projectPath.add(new File("../Augmented Text Services/dependencies/analysis/jfreechart-1.0.13.jar").toURI()); consoleDoctor.extractInterfaces(projectPath, "/tmp"); } /** * Scans the path for all available plugins and extracts the plugin interfaces * and their dependencies. * * @param projectClasspaths * @param target */ public void extractInterfaces(Collection<URI> projectClasspaths, String target) { final ClassPathLocator cpl = new ClassPathLocator(null, null); final Collection<AbstractClassPathLocation> allLocations = new ArrayList<AbstractClassPathLocation>(); // Locate all classpath elements for (URI uri : projectClasspaths) { allLocations.addAll(cpl.findBelow(uri)); } // Get all elements for (AbstractClassPathLocation l : allLocations) { final Collection<String> cn = l.listAllEntries(); for (String c : cn) { final AbstractClasspathElement classPathElement = AbstractClasspathElement.newClassPathElement(l, c); System.out.println(classPathElement); } } new JARWriter(new File(target + "/test.jar")); } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/ConsoleDoctor.java
Java
bsd
3,558
/* * JARWriter.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.plugindoctor.output; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; /** * @author rb * */ public class JARWriter { /** */ private JarOutputStream jarOutputStream; /** * @param output */ public JARWriter(File output) { try { this.jarOutputStream = new JarOutputStream(new FileOutputStream(output)); ZipEntry zipEntry = new ZipEntry("myxxx/test.txt"); zipEntry.setComment("my Comment"); this.jarOutputStream.putNextEntry(zipEntry); this.jarOutputStream.write("Helli World".getBytes()); this.jarOutputStream.closeEntry(); this.jarOutputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
100json-jspf
modules/tools/plugindoctor/src/net/xeoh/plugins/plugindoctor/output/JARWriter.java
Java
bsd
2,601
/* * ConverterImpl.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.converters.impl.plain; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.io.Serializable; import net.jcores.jre.cores.CoreFile; import net.jcores.jre.interfaces.functions.F1; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.DiagnosisMonitor; import net.xeoh.plugins.diagnosis.local.DiagnosisStatus; import net.xeoh.plugins.diagnosis.local.options.status.OptionInfo; import net.xeoh.plugins.diagnosisreader.converters.Converter; import net.xeoh.plugins.diagnosisreader.converters.ConverterInfo; /** * @author Ralf Biedert */ @PluginImplementation public class PlainConverterImpl implements Converter { /** */ @InjectPlugin public Diagnosis diagnosis; /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#getInfo() */ @Override public ConverterInfo getInfo() { return new ConverterInfo() { @Override public String getName() { return "Plain Text Converter"; } }; } /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#convert(java.io.File) */ @Override public void convert(File file) { final CoreFile f = $(file.getAbsolutePath() + ".txt").file().delete(); this.diagnosis.replay(file.getAbsolutePath(), new DiagnosisMonitor<Serializable>() { @Override public void onStatusChange(DiagnosisStatus<Serializable> status) { final StringBuilder sb = new StringBuilder(); sb.append(status.getDate()); sb.append(" "); sb.append($(status.getChannelAsString()).split("\\.").get(-1)); sb.append(" "); sb.append(status.getValue()); sb.append(" { "); sb.append($(status.getInfos()).map(new F1<OptionInfo, String>() { @Override public String f(OptionInfo arg0) { return arg0.getKey() + ":" + $(arg0.getValue()).get("null"); } }).string().join(", ")); sb.append(" }\n"); // Write text to file f.append(sb.toString()); } }); } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/converters/impl/plain/PlainConverterImpl.java
Java
bsd
4,114
/* * ConverterImpl.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.converters.impl.xml; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.io.Serializable; import net.jcores.jre.interfaces.functions.F1; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.DiagnosisMonitor; import net.xeoh.plugins.diagnosis.local.DiagnosisStatus; import net.xeoh.plugins.diagnosis.local.options.status.OptionInfo; import net.xeoh.plugins.diagnosisreader.converters.Converter; import net.xeoh.plugins.diagnosisreader.converters.ConverterInfo; /** * @author Ralf Biedert */ @PluginImplementation public class XMLConverterImpl implements Converter { /** */ @InjectPlugin public Diagnosis diagnosis; /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#getInfo() */ @Override public ConverterInfo getInfo() { return new ConverterInfo() { @Override public String getName() { return "XML Converter"; } }; } /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#convert(java.io.File) */ @Override public void convert(File file) { final String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; final String startTag = "<LogEntry>\n".intern(); final String endTag = "</LogEntry>\n".intern(); final StringBuilder sb = new StringBuilder(100000); sb.append(xmlHeader); this.diagnosis.replay(file.getAbsolutePath(), new DiagnosisMonitor<Serializable>() { @Override public void onStatusChange(DiagnosisStatus<Serializable> status) { final long date = status.getDate(); final String sender = $(status.getChannelAsString()).split("\\.").get(-1); final String value = status.getValue().toString(); final String opts = $(status.getInfos()).map(new F1<OptionInfo, String>() { @Override public String f(OptionInfo arg0) { return arg0.getKey() + ":" + $(arg0.getValue()).get("null"); } }).string().join(","); sb.append(startTag); sb.append("\t<time>" + date + "</time>\n"); sb.append("\t<sender>" + sender + "</sender>\n"); sb.append("\t<value>" + value + "</value>\n"); sb.append("\t<opts>" + opts + "</opts>\n"); sb.append(endTag); } }); // Write text to file $(file.getAbsolutePath() + ".xml").file().delete().append(sb); } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/converters/impl/xml/XMLConverterImpl.java
Java
bsd
4,419
/* * ConverterImpl.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.converters.impl.csv; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import net.jcores.jre.interfaces.functions.F1; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.DiagnosisMonitor; import net.xeoh.plugins.diagnosis.local.DiagnosisStatus; import net.xeoh.plugins.diagnosis.local.options.status.OptionInfo; import net.xeoh.plugins.diagnosisreader.converters.Converter; import net.xeoh.plugins.diagnosisreader.converters.ConverterInfo; /** * @author Ralf Biedert */ @PluginImplementation public class CSVConverterImpl implements Converter { /** */ @InjectPlugin public Diagnosis diagnosis; /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#getInfo() */ @Override public ConverterInfo getInfo() { return new ConverterInfo() { @Override public String getName() { return "CSV Converter"; } }; } /* * (non-Javadoc) * * @see net.xeoh.plugins.diagnosisreader.converters.Converter#convert(java.io.File) */ @Override public void convert(File file) { final DateFormat dateFormatter = new SimpleDateFormat("dd.MM.yy' 'HH:mm:ss.S"); final String columnHeader = "Date&Time;Sender;Message;Optional Parameters\n"; final StringBuilder sb = new StringBuilder(100000); sb.append(columnHeader); this.diagnosis.replay(file.getAbsolutePath(), new DiagnosisMonitor<Serializable>() { @Override public void onStatusChange(DiagnosisStatus<Serializable> status) { final String date = dateFormatter.format(new Date(status.getDate())); final String sender = $(status.getChannelAsString()).split("\\.").get(-1); final String value = status.getValue().toString(); final String opts = $(status.getInfos()).map(new F1<OptionInfo, String>() { @Override public String f(OptionInfo arg0) { return arg0.getKey() + ":" + $(arg0.getValue()).get("null"); } }).string().join(","); sb.append(date + ";" + sender + ";" + value + ";" + opts + "\n"); } }); // Write text to file $(file.getAbsolutePath() + ".csv").file().delete().append(sb); } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/converters/impl/csv/CSVConverterImpl.java
Java
bsd
4,283
/* * ConverterInfo.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.converters; /** * @author Ralf Biedert */ public interface ConverterInfo { /** * Name of this converter. * * @return . */ public String getName(); }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/converters/ConverterInfo.java
Java
bsd
1,787
/* * Reader.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.converters; import java.io.File; import net.xeoh.plugins.base.Plugin; /** * @author Ralf Biedert */ public interface Converter extends Plugin { /** * Converts the given file. * * @param file */ public void convert(File file); /** * Returns infos about this converter * * @return The current converter info. */ public ConverterInfo getInfo(); }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/converters/Converter.java
Java
bsd
2,018
/* * DropPanel.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.ui; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JPanel; public class DropPanel extends JPanel { /** */ private static final long serialVersionUID = 4384668615658760387L; /** */ private BufferedImage image; public DropPanel() { try { this.image = ImageIO.read(DropPanel.class.getResourceAsStream("dropfileshere.png")); } catch (IOException e) {} } /* * (non-Javadoc) * * @see javax.swing.JComponent#paint(java.awt.Graphics) */ @Override public void paint(Graphics g) { g.drawImage(this.image, 0, 0, null); } /* * (non-Javadoc) * * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(this.image.getWidth(), this.image.getHeight()); } /* * (non-Javadoc) * * @see javax.swing.JComponent#getMinimumSize() */ @Override public Dimension getMinimumSize() { return this.getPreferredSize(); } /* * (non-Javadoc) * * @see javax.swing.JComponent#getMaximumSize() */ @Override public Dimension getMaximumSize() { return this.getPreferredSize(); } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/ui/DropPanel.java
Java
bsd
2,974
/* * MainWindow.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader.ui; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.util.Collection; import net.jcores.jre.cores.CoreFile; import net.jcores.jre.cores.CoreObject; import net.jcores.jre.interfaces.functions.F0; import net.jcores.jre.interfaces.functions.F1; import net.jcores.jre.options.DropType; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.util.PluginManagerUtil; import net.xeoh.plugins.diagnosisreader.converters.Converter; /** * @author Ralf Biedert */ public class MainWindow extends MainWindowTemplate { /** */ private static final long serialVersionUID = 3556149463262771404L; /** The plugin manager we use */ private PluginManager pluginManager; /** * @param pluginManager */ public MainWindow(PluginManager pluginManager) { this.pluginManager = pluginManager; // Make the drop panel accept files $(this.dropPanel).onDrop(new F1<CoreObject<Object>, Void>() { @Override public Void f(final CoreObject<Object> arg0) { $.sys.oneTime(new F0() { @Override public void f() { process(arg0.as(CoreFile.class)); } }, 1); return null; } }, DropType.FILES); } /** * Registers a converter. * * @param c The converter to register. */ public void registerHandler(Converter c) { this.converter.addItem(c.getInfo().getName()); } /** * Processes the given files * * @param files */ void process(CoreFile files) { final String selected = (String) this.converter.getSelectedItem(); final PluginManagerUtil managerUtil = new PluginManagerUtil(this.pluginManager); final Collection<Converter> plugins = managerUtil.getPlugins(Converter.class); // Now convert all files for (final Converter c : plugins) { if(c.getInfo().getName().equals(selected)) { files.map(new F1<File, Void>() { @Override public Void f(File arg0) { c.convert(arg0); return null; } }); } } } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/ui/MainWindow.java
Java
bsd
3,925
/* * Created by JFormDesigner on Wed Mar 30 12:26:50 CEST 2011 */ package net.xeoh.plugins.diagnosisreader.ui; import java.awt.Container; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.WindowConstants; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * @author Ralf Biedert */ public class MainWindowTemplate extends JFrame { /** */ private static final long serialVersionUID = -1517673471088767556L; /** */ public MainWindowTemplate() { initComponents(); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license this.dropPanel = new DropPanel(); this.converter = new JComboBox(); CellConstraints cc = new CellConstraints(); //======== this ======== setTitle("Diagnosis Converter"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = getContentPane(); contentPane.setLayout(new FormLayout( "pref, $rgap, center:pref:grow, $lcgap, pref", "pref:grow, $lgap, default")); contentPane.add(this.dropPanel, cc.xywh(1, 1, 5, 2)); contentPane.add(this.converter, cc.xy(3, 3)); pack(); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // Generated using JFormDesigner non-commercial license protected DropPanel dropPanel; protected JComboBox converter; // JFormDesigner - End of variables declaration //GEN-END:variables }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/ui/MainWindowTemplate.java
Java
bsd
1,806
/* * DiagnosisReader.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosisreader; import java.io.File; import java.util.Collection; import javax.swing.UIManager; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.impl.PluginManagerFactory; import net.xeoh.plugins.base.util.PluginManagerUtil; import net.xeoh.plugins.base.util.uri.ClassURI; import net.xeoh.plugins.diagnosisreader.converters.Converter; import net.xeoh.plugins.diagnosisreader.converters.impl.csv.CSVConverterImpl; import net.xeoh.plugins.diagnosisreader.converters.impl.plain.PlainConverterImpl; import net.xeoh.plugins.diagnosisreader.converters.impl.xml.XMLConverterImpl; import net.xeoh.plugins.diagnosisreader.ui.MainWindow; /** * @author Ralf Biedert */ public class DiagnosisReader { public static void main(String[] args) { // Set the system look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (final Exception e) {} // We only need the default plugins and a few of our owns final PluginManager pluginManager = PluginManagerFactory.createPluginManager(); final PluginManagerUtil pluginManagerUtil = new PluginManagerUtil(pluginManager); pluginManager.addPluginsFrom(ClassURI.PLUGIN(PlainConverterImpl.class)); pluginManager.addPluginsFrom(ClassURI.PLUGIN(CSVConverterImpl.class)); pluginManager.addPluginsFrom(ClassURI.PLUGIN(XMLConverterImpl.class)); pluginManager.addPluginsFrom(new File("plugins/").toURI()); final MainWindow mainWindow = new MainWindow(pluginManager); mainWindow.setVisible(true); final Collection<Converter> converters = pluginManagerUtil.getPlugins(Converter.class); for (Converter converter : converters) { mainWindow.registerHandler(converter); } } }
100json-jspf
modules/tools/diagnosisreader/src/net/xeoh/plugins/diagnosisreader/DiagnosisReader.java
Java
bsd
3,401
/* * Option.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base; import java.io.Serializable; import net.xeoh.plugins.base.util.OptionUtils; /** * Used as optional arguments to classes. <br/><br/> * * All options have to be serializable, because they might be transferred over * the network. Options are a great way of keeping interfaces small yet powerful. * See the <a href="http://code.google.com/p/jspf/wiki/UsageGuide">usage guide</a> * for more infos on options. * * @author Ralf Biedert * @see OptionUtils */ public interface Option extends Serializable { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/Option.java
Java
bsd
2,115
/** * Contains the core plugin manager classes. * * @since 1.0 */ package net.xeoh.plugins.base;
100json-jspf
modules/core/src/net/xeoh/plugins/base/package-info.java
Java
bsd
104
/* * OptionDummy.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.getinformation; import java.util.List; import net.xeoh.plugins.base.PluginInformation; import net.xeoh.plugins.base.options.GetInformationOption; /** * Asks the {@link PluginInformation} plugin to return the author information. * * @author Ralf Biedert */ public class InformationAuthors implements GetInformationOption { /** */ private static final long serialVersionUID = -1699032953607764618L; /** * Returns a list of all authors that contributed to the plugin. * * @since 1.0 * @return The list with all authors. */ public List<String> getAuthors() { return null; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/getinformation/InformationAuthors.java
Java
bsd
2,241
/** * Options to <code>getPlugin()</code>. * * @since 1.0 */ package net.xeoh.plugins.base.options.getplugin;
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/getplugin/package-info.java
Java
bsd
117
/* * PluginSelector.java * * Copyright (c) 2008, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.getplugin; import net.xeoh.plugins.base.Plugin; /** * You can use this interface to select an appropriate instance of a given * plugin when querying the plugin manager. * * @author Ralf Biedert * * @param <T> Type of the plugin. */ public interface PluginSelector<T extends Plugin> { /** * Return true if you want the specified plugin returned, false otherwise. * * @param plugin The plugin for which you are being called. * @return Return <code>true</code> if you want to select the passed plugin. */ public boolean selectPlugin(T plugin); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/getplugin/PluginSelector.java
Java
bsd
2,230
/* * OptionDummy.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.getplugin; import net.xeoh.plugins.base.annotations.Capabilities; import net.xeoh.plugins.base.options.GetPluginOption; /** * Specifies the method should only consider plugins satisfying all the * given {@link Capabilities}. This is useful in case there are a number of plugins * implementing the same interface. With this option, only plugins with the * specified capabilities are considered. For example, to get a plugin implementing * the <code>Language</code> and capable of handling English, write:<br/><br/> * * <code> * pluginManager.getPlugin(Language.class, new OptionCapabilities("language:english")); * </code><br/><br/> * * If multiple capabilities are specified only plugins matching all of them are being * considered. Multiple capabilities MUST be specified within a single option, not as * multiple options, i.e., write:<br/><br/> * * <code> * new OptionCapabilities("filetype:xml", "filetype:csv", "filetype:raw"); * </code><br/><br/> * * @author Ralf Biedert */ public class OptionCapabilities implements GetPluginOption { /** */ private static final long serialVersionUID = -7856506348748868122L; /** */ private String[] caps; /** * Returns plugins that matches all given capabilites. * * @param matchingCapabilites The capabilities to consider. */ public OptionCapabilities(String... matchingCapabilites) { this.caps = matchingCapabilites; } /** * Returns the requested capabilities. * * @return Array of caps. */ public String[] getCapabilities() { return this.caps; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/getplugin/OptionCapabilities.java
Java
bsd
3,227
/* * OptionPluginSelector.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.getplugin; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.options.GetPluginOption; import net.xeoh.plugins.base.util.PluginManagerUtil; /** * Passes a plugin selector as an option. The selector will be called for each considered plugin. * The first plugin on which the collector returns <code>true</code> will be returned. For example, * to select a remote service based on its protocol, write:<br/><br/> * * <code> * getPlugin(RemoteAPI.class, new OptionPluginSelector<RemoteAPI>(new PluginSelector<RemoteAPI>() {<br/> * &nbsp;&nbsp;&nbsp;&nbsp;public boolean selectPlugin(final RemoteAPI p) {<br/> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (p.getPublishMethod() == PublishMethod.JSON) return true;<br/> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/> * }<br/> * }));<br/> * </code><br/><br/> * * The plugin selector is especially useful to iterate over all plugins, {@link PluginManagerUtil} * already does that for you. * * @author Ralf Biedert * @see PluginManager * @param <P> Type of the plugin. */ public final class OptionPluginSelector<P extends Plugin> implements GetPluginOption { /** */ private static final long serialVersionUID = 6540623006341980932L; /** */ private PluginSelector<P> value; /** * Creates a new selectop option with the given selelector. * * @param ps The plugin selector to add. */ public OptionPluginSelector(PluginSelector<P> ps) { this.value = ps; } /** * Returns the passed selector. * * @return The selector enclosed. */ public PluginSelector<P> getSelector() { return this.value; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/getplugin/OptionPluginSelector.java
Java
bsd
3,382
/** * Top level package for core options. * * @since 1.0 */ package net.xeoh.plugins.base.options;
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/package-info.java
Java
bsd
107
/* * OptionSearchAround.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.addpluginsfrom; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.options.AddPluginsFromOption; /** * When JSPF searches for plugins, use the given class as the initial exploration * point for a classpath search. Usually this is not needed, but in very special cases * (like when using an application server), it can help JSPF to find your plugins.<br/><br/> * * <code> * pluginManager.addPluginsFrom(uri, new OptionSearchAround(getClass())); * </code> * * @author Ralf Biedert * @see PluginManager */ public class OptionSearchAround implements AddPluginsFromOption { /** */ private static final long serialVersionUID = -8362751446846683259L; /** */ private Class<?> clazz; public OptionSearchAround(Class<?> clazz) { this.clazz = clazz; } /** * @return the clazz */ public Class<?> getClazz() { return this.clazz; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/addpluginsfrom/OptionSearchAround.java
Java
bsd
2,543
/** * Options to <code>addPluginsFrom()</code>. * * @since 1.0 */ package net.xeoh.plugins.base.options.addpluginsfrom;
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/addpluginsfrom/package-info.java
Java
bsd
127
/* * OptionDummy.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options.addpluginsfrom; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.options.AddPluginsFromOption; /** * Asks the PluginManager to print a report after this plugin addition. See the console * output for more information. This option is a useful tool for debugging plugin problems. * For example, to print a report after all plugins from a given source have been loaded, * write:<br/><br/> * * <code> * pluginManager.addPluginsFrom(uri, new OptionReportAfter()); * </code> * * @author Ralf Biedert * @see PluginManager */ public class OptionReportAfter implements AddPluginsFromOption { /** */ private static final long serialVersionUID = -8362751446846683259L; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/addpluginsfrom/OptionReportAfter.java
Java
bsd
2,310
/* * GetPluginOption.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options; import net.xeoh.plugins.base.Option; import net.xeoh.plugins.base.PluginManager; /** * The base type for all <code>getPlugin()</code> options. * * @author Ralf Biedert * @see PluginManager */ public interface GetPluginOption extends Option { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/GetPluginOption.java
Java
bsd
1,865
/* * GetInformationOption.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options; import net.xeoh.plugins.base.Option; import net.xeoh.plugins.base.PluginManager; /** * The base type for all <code>getInformation()</code> options. * * @author Ralf Biedert * @see PluginManager */ public interface GetInformationOption extends Option { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/GetInformationOption.java
Java
bsd
1,880
/* * GetPluginOption.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.options; import net.xeoh.plugins.base.Option; import net.xeoh.plugins.base.PluginManager; /** * The base type for all <code>addPluginsFrom()</code> options. * * @author Ralf Biedert * @see PluginManager */ public interface AddPluginsFromOption extends Option { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/options/AddPluginsFromOption.java
Java
bsd
1,876
/* * PluginInformation.java * * Copyright (c) 2008, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base; import java.util.Collection; import net.xeoh.plugins.base.annotations.Capabilities; import net.xeoh.plugins.base.annotations.meta.Author; import net.xeoh.plugins.base.annotations.meta.Version; import net.xeoh.plugins.base.options.GetInformationOption; /** * Returns various information about plugins, static as well as dynamic. * * @author Ralf Biedert */ public interface PluginInformation extends Plugin { /** * The set of information item that can be requested. <b>S1</b> means a list * of strings with exactly one element is returnd, <b>S+</b> means a number of * strings will be returned. In case no information was available an empty * collection is returned. * * @author Ralf Biedert */ public static enum Information { /** * The author of this plugins (S1). * * @see Author */ AUTHORS, /** * Returns the self proclaimed capabilites of this plugin (S+). * * @see Capabilities */ CAPABILITIES, /** * Version of this plugin (S+). A version number of 10304 will be * returned as 1.03.04 at index 0. Additional versioning information may be * provided. * * @see Version */ VERSION, /** * Date when the plugin was initialized (S1). The unix time will be returned.<br/><br/> * * TODO: Not implemented yet. */ INIT_DATE, /** * Returns a single string containing the URI to the classpath item this * element came from (S1). */ CLASSPATH_ORIGIN, } /** * Returns an {@link Information} item about a plugin. For example, to query a plugin's * classpath origin you would write:<br/><br/> * * <code> * getInformation(Information.CLASSPATH_ORIGIN, plugin); * </code> * * @param item The information item to request. * @param plugin The plugin for which the information is requested. * * @return A collection of strings containing the requested information. The the specific {@link Information} * item for more details. If nothing sensible was found, an empty collection is returned. */ public Collection<String> getInformation(Information item, Plugin plugin); /** * Returns an {@link Information} item about a plugin. For example, to query a plugin's * classpath origin you would write:<br/><br/> * * <code> * getInformation(plugin, InformationOrigin.class); * </code> * * @param plugin The plugin for which the information is requested. * @param query The information item to request. * * @return The appropriate query result. */ public <T extends GetInformationOption> T getInformation(Plugin plugin, Class<T> query); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/PluginInformation.java
Java
bsd
4,632
/* * Spawner.java * * Copyright (c) 2008, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.spawning; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; import java.util.TimerTask; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.annotations.Thread; import net.xeoh.plugins.base.annotations.Timer; import net.xeoh.plugins.base.annotations.events.Init; import net.xeoh.plugins.base.annotations.events.PluginLoaded; import net.xeoh.plugins.base.annotations.events.Shutdown; import net.xeoh.plugins.base.diagnosis.channels.tracing.SpawnerTracer; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.Dependency; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation.PluginLoadedInformation; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation.PluginStatus; import net.xeoh.plugins.base.impl.spawning.handler.InjectHandler; import net.xeoh.plugins.base.util.PluginManagerUtil; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.DiagnosisChannel; import net.xeoh.plugins.diagnosis.local.options.StatusOption; import net.xeoh.plugins.diagnosis.local.options.status.OptionInfo; /** * Spawn a given class. * * @author Ralf Biedert */ public class Spawner { /** Used for diagnosic messages */ DiagnosisChannel<String> diagnosis; /** Main plugin manager */ private final PluginManagerImpl pluginManager; /** * Creates a new spawner with the given PluginManager. * * @param pmi */ public Spawner(final PluginManagerImpl pmi) { this.pluginManager = pmi; } /** * Destroys a given plugin, halt all timers and threads, calls shutdown methods. * * @param plugin * @param metaInformation */ public void destroyPlugin(final Plugin plugin, final PluginMetaInformation metaInformation) { log("destroy/start", new OptionInfo("plugin", plugin.getClass().getCanonicalName())); // Halt all timer tasks for (final TimerTask timerTask : metaInformation.timerTasks) { timerTask.cancel(); } // Halt all timers for (final java.util.Timer timer : metaInformation.timers) { timer.cancel(); } // Halt all threads for (final java.lang.Thread thread : metaInformation.threads) { // TODO: Maybe not the best way to terminate. try { thread.interrupt(); } catch (final Exception e) { e.printStackTrace(); } } // Call shutdown hooks callShutdownMethods(plugin); log("destroy/end", new OptionInfo("plugin", plugin.getClass().getCanonicalName())); } /** * Destroys a given plugin, halt all timers and threads, calls shutdown methods. * * @param plugin * @param metaInformation */ public void processThisPluginLoadedAnnotation(final Plugin plugin, final PluginMetaInformation metaInformation) { // Get all our annotations. for (PluginLoadedInformation pli : metaInformation.pluginLoadedInformation) { final Collection<? extends Plugin> plugins = new PluginManagerUtil(this.pluginManager).getPlugins(pli.baseType); // For each plugin we have a request, call this plugin. for (Plugin p : plugins) { try { pli.method.invoke(plugin, p); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } pli.calledWith.addAll(plugins); } } /** * Processes the {@link PluginLoaded} annotation for other plugins for this plugin. * * @param newPlugin Newly creatd pluign */ public void processOtherPluginLoadedAnnotation(Plugin newPlugin) { for (Plugin plugin : this.pluginManager.getPluginRegistry().getAllPlugins()) { final PluginMetaInformation pmi = this.pluginManager.getPluginRegistry().getMetaInformationFor(plugin); for (PluginLoadedInformation pli : pmi.pluginLoadedInformation) { final Collection<? extends Plugin> plins = new PluginManagerUtil(this.pluginManager).getPlugins(pli.baseType); // Check if the new plugin is returned upon request if (plins.contains(newPlugin)) { try { pli.method.invoke(plugin, newPlugin); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } pli.calledWith.add(newPlugin); } } } } /** * Spawn a plugin and process its internal annotations. * * @param c Class to spawn from. * @return . */ @SuppressWarnings({ "rawtypes", "unchecked" }) public SpawnResult spawnPlugin(final Class c) { log("spawn/start", new OptionInfo("plugin", c.getCanonicalName())); // Used for time measurements. final long startTime = System.nanoTime(); final java.util.Timer timer = new java.util.Timer(); final TimerTask lateMessage = new TimerTask() { @Override public void run() { log("spawn/timeout/toolong", new OptionInfo("plugin", c.getCanonicalName())); } }; // Finally load and register plugin try { // Schedule late message. (TODO: Make this configurable) timer.schedule(lateMessage, 250); // Instanciate the plugin final Constructor constructor = c.getDeclaredConstructor(); constructor.setAccessible(true); final Plugin spawnedPlugin = (Plugin) constructor.newInstance(); // In here spawning of the plugin worked final SpawnResult spawnResult = new SpawnResult(spawnedPlugin); spawnResult.metaInformation.pluginStatus = PluginStatus.SPAWNED; spawnResult.metaInformation.spawnTime = System.currentTimeMillis(); // Finally load and register plugin try { new InjectHandler(this.pluginManager).init(spawnedPlugin); // Obtain all methods final Method[] methods = getMethods(c); // 2. Call all init methods final boolean initStatus = callInitMethods(spawnedPlugin, methods); if (initStatus == false) { spawnResult.metaInformation.pluginStatus = PluginStatus.FAILED; return spawnResult; } // Initialization complete spawnResult.metaInformation.pluginStatus = PluginStatus.INITIALIZED; // 3. Spawn all threads spawnThreads(spawnResult, methods); // 4. Spawn timer spawnTimer(spawnResult, methods); // 5. Obtain PluginLoaded methods obtainPluginLoadedMethods(spawnResult, methods); // Currently running spawnResult.metaInformation.pluginStatus = PluginStatus.ACTIVE; log("spawn/end", new OptionInfo("plugin", c.getCanonicalName())); return spawnResult; } catch (final Throwable e) { log("spawn/exception/init", new OptionInfo("plugin", c.getCanonicalName())); e.printStackTrace(); Throwable cause = e.getCause(); while (cause != null) { cause.printStackTrace(); cause = cause.getCause(); } } return null; } catch (final Throwable e) { log("spawn/exception/construct", new OptionInfo("plugin", c.getCanonicalName())); e.printStackTrace(); Throwable cause = e.getCause(); while (cause != null) { cause.printStackTrace(); cause = cause.getCause(); } } finally { // Halt the late message timer.cancel(); final long stopTime = System.nanoTime(); final long delta = (stopTime - startTime) / 1000; log("spawn/duration", new OptionInfo("plugin", c.getCanonicalName()), new OptionInfo("time", ""+ delta)); } log("spawn/end/abnormal", new OptionInfo("plugin", c.getCanonicalName())); return null; } /** * * @param methods * @returns True if initialization was successful. * @throws IllegalAccessException * * */ private boolean callInitMethods(final Plugin spawnedPlugin, final Method[] methods) throws IllegalAccessException { log("callinit/start", new OptionInfo("plugin", spawnedPlugin.getClass().getCanonicalName())); // final Class<? extends Plugin> spawnClass = spawnedPlugin.getClass(); for (final Method method : methods) { log("callinit/method", new OptionInfo("method", method.getName())); // Init methods will be marked by the corresponding annotation. final Init annotation = method.getAnnotation(Init.class); if (annotation != null) { log("callinit/method/initannotation", new OptionInfo("method", method.getName())); try { final Object invoke = method.invoke(spawnedPlugin, new Object[0]); if (invoke != null && invoke instanceof Boolean) { // Check if any init method returns false. if (((Boolean) invoke).booleanValue() == false) return false; } } catch (final IllegalArgumentException e) { log("callinit/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); log("callinit/end/abnormal", new OptionInfo("plugin", spawnedPlugin.getClass().getCanonicalName())); e.printStackTrace(); return false; } catch (final InvocationTargetException e) { log("callinit/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); log("callinit/end/abnormal", new OptionInfo("plugin", spawnedPlugin.getClass().getCanonicalName())); e.printStackTrace(); return false; } catch (final Exception e) { log("callinit/exception/exception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); log("callinit/end/abnormal", new OptionInfo("plugin", spawnedPlugin.getClass().getCanonicalName())); e.printStackTrace(); return false; } } } log("callinit/end", new OptionInfo("plugin", spawnedPlugin.getClass().getCanonicalName())); return true; } /** * @param plugin */ private void callShutdownMethods(final Plugin plugin) { log("callshutdown/start", new OptionInfo("plugin", plugin.getClass().getCanonicalName())); final Class<? extends Plugin> spawnClass = plugin.getClass(); final Method[] methods = spawnClass.getMethods(); for (final Method method : methods) { log("callshutdown/method", new OptionInfo("method", method.getName())); // Init methods will be marked by the corresponding annotation. final Shutdown annotation = method.getAnnotation(Shutdown.class); if (annotation != null) { log("callshutdown/method/shutdownannotation", new OptionInfo("method", method.getName())); try { method.invoke(plugin, new Object[0]); } catch (final IllegalArgumentException e) { log("callshutdown/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final InvocationTargetException e) { log("callinit/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final Exception e) { log("callshutdown/exception/exception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } } } log("callshutdown/end", new OptionInfo("plugin", plugin.getClass().getCanonicalName())); return; } /** * @param c * @return */ private Method[] getMethods(final Class<? extends Plugin> c) { final Method[] methods = c.getMethods(); return methods; } /** * @param spawnResult * @param methods */ private void spawnThreads(final SpawnResult spawnResult, final Method[] methods) { log("spawnthreads/start", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName())); for (final Method method : methods) { // Init methods will be marked by the corresponding annotation. New: // also turn on extended accessibility, so elements don't have to be public // anymore. method.setAccessible(true); final net.xeoh.plugins.base.annotations.Thread annotation = method.getAnnotation(Thread.class); if (annotation != null) { final java.lang.Thread t = new java.lang.Thread(new Runnable() { public void run() { try { // TODO: Pass kind of ThreadController as argument 1 (or any // fitting argument) method.invoke(spawnResult.plugin, new Object[0]); } catch (final IllegalArgumentException e) { log("spawnthreads/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final IllegalAccessException e) { log("spawnthreads/exception/illegalaccess", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final InvocationTargetException e) { log("spawnthreads/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } } }); final String name = spawnResult.plugin.getClass().getName() + "." + method.getName() + "()"; log("spawnthreads/threadstart", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()), new OptionInfo("threadname", name)); t.setName(name); t.setDaemon(annotation.isDaemonic()); t.start(); // Add timer task to list spawnResult.metaInformation.threads.add(t); } } log("spawnthreads/end", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName())); } /** * @param spawnResult * @param methods */ @SuppressWarnings("unchecked") private void obtainPluginLoadedMethods(SpawnResult spawnResult, Method[] methods) { for (final Method method : methods) { // New: also turn on extended accessibility, so elements don't have to be // public anymore. method.setAccessible(true); final PluginLoaded annotation = method.getAnnotation(PluginLoaded.class); if (annotation != null) { final PluginLoadedInformation pli = new PluginLoadedInformation(); final Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { log("pluginloadedmethods/wrongnumberofparams", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()), new OptionInfo("method", method.getName())); continue; } pli.method = method; pli.baseType = (Class<? extends Plugin>) parameterTypes[0]; // And add result spawnResult.metaInformation.pluginLoadedInformation.add(pli); } } } /** * @param spawnResult * @param methods */ private void spawnTimer(final SpawnResult spawnResult, final Method[] methods) { log("spawntimers/start", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName())); for (final Method method : methods) { // Init methods will be marked by the corresponding annotation. New: also // turn on extended accessibility, so elements don't have to be public // anymore. method.setAccessible(true); final net.xeoh.plugins.base.annotations.Timer annotation = method.getAnnotation(Timer.class); if (annotation != null) { final java.util.Timer t = new java.util.Timer(); final TimerTask tt = new TimerTask() { @Override public void run() { try { final Object invoke = method.invoke(spawnResult.plugin, new Object[0]); if (invoke != null && invoke instanceof Boolean) { if (((Boolean) invoke).booleanValue()) { t.cancel(); } } } catch (final IllegalArgumentException e) { log("spawntimers/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final IllegalAccessException e) { log("spawntimers/exception/illegalaccessexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } catch (final InvocationTargetException e) { log("spawntimers/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage())); e.printStackTrace(); } } }; if (annotation.timerType() == Timer.TimerType.RATE_BASED) { t.scheduleAtFixedRate(tt, annotation.startupDelay(), annotation.period()); } if (annotation.timerType() == Timer.TimerType.DELAY_BASED) { t.schedule(tt, annotation.startupDelay(), annotation.period()); } // Add timer task to list spawnResult.metaInformation.timerTasks.add(tt); spawnResult.metaInformation.timers.add(t); } } log("spawntimers/end", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName())); } /** * Returns the list of all dependencies the plugin has. * * @param pluginClass * @return . */ public Collection<Dependency> getDependencies(Class<? extends Plugin> pluginClass) { return new InjectHandler(this.pluginManager).getDependencies(pluginClass); } /** * Logs the given message. * * @param message * @param options */ void log(String message, StatusOption... options) { // Try to get the diagnosis if (this.diagnosis == null) { // Check if the diagnosis is already there final Diagnosis diag = this.pluginManager.getDiagnosis(); if(diag==null) return; // If yes, get the main channel this.diagnosis = diag.channel(SpawnerTracer.class); } this.diagnosis.status(message, options); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/spawning/Spawner.java
Java
bsd
23,971
package net.xeoh.plugins.base.impl.spawning; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation; /** * Spawn result, encapsulates the results of our attempt to spawn * a given plugin. * * @author Ralf Biedert */ public class SpawnResult { /** The actual pluggable spawned */ public final Plugin plugin; /** Information on this plugin */ public final PluginMetaInformation metaInformation; /** * Creates a new spawn results. * * @param plugin */ public SpawnResult(Plugin plugin) { this.plugin = plugin; this.metaInformation = new PluginMetaInformation(); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/spawning/SpawnResult.java
Java
bsd
685
/* * AbstractHandler.java * * Copyright (c) 2010, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.spawning.handler; import java.util.logging.Logger; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginManager; /** * Handles a certain type of annotations / properties. * * @author Ralf Biedert */ public abstract class AbstractHandler { /** */ final PluginManager pluginManager; /** */ final Logger logger = Logger.getLogger(this.getClass().getName()); /** * @param pluginManager */ public AbstractHandler(PluginManager pluginManager) { this.pluginManager = pluginManager; } /** * Called when the plugin is initialized * * @param plugin * @throws Exception */ public abstract void init(Plugin plugin) throws Exception; /** * Called when the plugin is initialized * * @param plugin * @throws Exception */ public abstract void deinit(Plugin plugin) throws Exception; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/spawning/handler/AbstractHandler.java
Java
bsd
2,518
/* * InjectHandler.java * * Copyright (c) 2010, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.spawning.handler; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.Dependency; import net.xeoh.plugins.base.options.getplugin.OptionCapabilities; /** * Handles injections into plugins. * * @author Ralf Biedert */ public class InjectHandler extends AbstractHandler { /** * @param pluginManager */ public InjectHandler(PluginManager pluginManager) { super(pluginManager); } /* * (non-Javadoc) * * @see * net.xeoh.plugins.base.impl.spawning.handler.AbstractHandler#init(net.xeoh.plugins * .base.Plugin) */ @SuppressWarnings("unchecked") @Override public void init(Plugin plugin) throws Exception { // All fields we have a look at final Field[] fields = plugin.getClass().getFields(); final Method[] methods = plugin.getClass().getMethods(); // Process every field for (final Field field : fields) { // Try to get inject annotation. New: also turn on extended accessibility, so // elements don't have to be public anymore. field.setAccessible(true); final InjectPlugin ipannotation = field.getAnnotation(InjectPlugin.class); // If there is one .. if (ipannotation != null) { // Obtain capabilities final String[] capabilities = ipannotation.requiredCapabilities(); // Handle the plugin-parameter part // In the default case do an auto-detection ... final Class<? extends Plugin> typeOfField = (Class<? extends Plugin>) field.getType(); this.logger.fine("Injecting plugin by autodetection (" + typeOfField.getName() + ") into " + plugin.getClass().getName()); field.set(plugin, getEntityForType(typeOfField, capabilities)); } } // And setter methods as well (aka Scala hack) for (Method method : methods) { // Try to get inject annotation. New: also turn on extended accessibility, so // elements don't have to be public anymore. method.setAccessible(true); final InjectPlugin ipannotation = method.getAnnotation(InjectPlugin.class); if (ipannotation != null) { // Obtain capabilities final String[] capabilities = ipannotation.requiredCapabilities(); // Handle the plugin-parameter part // In the default case do an auto-detection ... final Class<? extends Plugin> typeOfMethod = (Class<? extends Plugin>) method.getParameterTypes()[0]; this.logger.fine("Injecting plugin by autodetection (" + typeOfMethod.getName() + ") into " + plugin.getClass().getName()); try { method.invoke(plugin, getEntityForType(typeOfMethod, capabilities)); } catch (IllegalArgumentException e) { this.logger.warning("Unable to inject plugin " + typeOfMethod + " into method " + method); e.printStackTrace(); } catch (InvocationTargetException e) { this.logger.warning("Unable to inject plugin " + typeOfMethod + " into method " + method); e.printStackTrace(); } } } } /* * (non-Javadoc) * * @see * net.xeoh.plugins.base.impl.spawning.handler.AbstractHandler#deinit(net.xeoh.plugins * .base.Plugin) */ @Override public void deinit(Plugin plugin) throws Exception { // TODO Auto-generated method stub } /** * Returns the true plugin interface type for something that accepts * an @InjectPlugin annotation. This is either the interface directly, * or some Util that accepts a interface as the first parameter. * * @param type * @return */ Class<?> getTrueDependencyInterfaceType(Class<?> type) { // If it is an interface, return that if(type.isInterface()) return type; // In all other cases, return the type of the first parameter of the given class try { final Constructor<?>[] declaredConstructors = type.getDeclaredConstructors(); for (Constructor<?> constructor : declaredConstructors) { final Class<?>[] parameterTypes = constructor.getParameterTypes(); if(parameterTypes.length != 1) continue; if(parameterTypes[0].isAssignableFrom(type)) return parameterTypes[0]; } } catch (SecurityException e) { e.printStackTrace(); } return null; } /** * Tries to get an entity for the requested type. * * @param type * @return */ @SuppressWarnings("unchecked") Plugin getEntityForType(Class<?> type, String...capabilities) { // We need that anyways. Plugin plugin = this.pluginManager.getPlugin((Class<Plugin>) getTrueDependencyInterfaceType(type), new OptionCapabilities(capabilities)); // First check if the requested type is an anctual interface or not. If it is, we simply treat // it as a plugin, if it is not (i.e., a ordinary class), we treat it as a util wrapper. if(type.isInterface()) { return plugin; } // In that case, we have to inspect the first parameter of the constructor that accepts itself as a // paramter. try { final Constructor<?>[] constructors = type.getDeclaredConstructors(); for (Constructor<?> constructor : constructors) { final Class<?>[] parameterTypes = constructor.getParameterTypes(); if(parameterTypes.length != 1) continue; if(parameterTypes[0].isAssignableFrom(type)) return (Plugin) constructor.newInstance(plugin); } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; } /** * Returns the list of all dependencies the plugin has. * * @param pluginClass * @return . */ @SuppressWarnings("unchecked") public Collection<Dependency> getDependencies(Class<? extends Plugin> pluginClass) { final Collection<Dependency> rval = new ArrayList<Dependency>(); // All fields we have a look at final Field[] fields = pluginClass.getFields(); final Method[] methods = pluginClass.getMethods(); // Process every field for (final Field field : fields) { field.setAccessible(true); final InjectPlugin ipannotation = field.getAnnotation(InjectPlugin.class); if (ipannotation == null) continue; if (ipannotation.isOptional()) continue; final Dependency d = new Dependency(); d.capabilites = ipannotation.requiredCapabilities(); d.pluginClass = (Class<? extends Plugin>) getTrueDependencyInterfaceType(field.getType()); d.isOptional = ipannotation.isOptional(); rval.add(d); } // And setter methods as well (aka Scala hack) for (Method method : methods) { method.setAccessible(true); final InjectPlugin ipannotation = method.getAnnotation(InjectPlugin.class); if (ipannotation == null) continue; if (ipannotation.isOptional()) continue; final Dependency d = new Dependency(); d.capabilites = ipannotation.requiredCapabilities(); d.pluginClass = (Class<? extends Plugin>) getTrueDependencyInterfaceType(method.getParameterTypes()[0]); d.isOptional = ipannotation.isOptional(); rval.add(d); } return rval; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/spawning/handler/InjectHandler.java
Java
bsd
10,224
/** * The {@link net.xeoh.plugins.base.impl.PluginManagerFactory} is the framework's entry point and the only class of * relevance within this package, start exploring here. * * @since 1.0 */ package net.xeoh.plugins.base.impl;
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/package-info.java
Java
bsd
237
/* * PluginConfigurationImpl.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl; import static net.jcores.jre.CoreKeeper.$; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.logging.Logger; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginInformation; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.Capabilities; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.base.annotations.meta.Author; import net.xeoh.plugins.base.annotations.meta.Stateless; import net.xeoh.plugins.base.annotations.meta.Version; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation; import net.xeoh.plugins.base.impl.registry.PluginRegistry; import net.xeoh.plugins.base.options.GetInformationOption; /** * TODO: Make plugin threadsafe * * @author Ralf Biedert * */ @Author(name = "Ralf Biedert") @Version(version = 1 * Version.UNIT_MAJOR) @Stateless @PluginImplementation public class PluginInformationImpl implements PluginInformation { /** */ final Logger logger = Logger.getLogger(this.getClass().getName()); /** */ @InjectPlugin public PluginManager pluginManager; /** Dum dum dum dum .... don't touch this ... */ private PluginInformationImpl() { } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginInformation#getInformation(net.xeoh.plugins.base. * PluginInformation.Information, net.xeoh.plugins.base.Plugin) */ public Collection<String> getInformation(final Information item, final Plugin plugin) { // Needed to query some special information final PluginManagerImpl pmi = (PluginManagerImpl) this.pluginManager; // Prepare return values ... final Collection<String> rval = new ArrayList<String>(); switch (item) { case CAPABILITIES: // Caps are only supported for plugins currently final String[] caps = getCaps(plugin); for (final String string : caps) { rval.add(string); } break; case AUTHORS: final Author author = plugin.getClass().getAnnotation(Author.class); if (author == null) break; rval.add(author.name()); break; case VERSION: final Version version = plugin.getClass().getAnnotation(Version.class); if (version == null) break; rval.add(Integer.toString(version.version())); if(plugin == this.pluginManager) { final String build = $(PluginManagerImpl.class.getResourceAsStream("jspf.version")).text().split("\n").hashmap().get("build"); rval.add("jspf.build:" + build); } break; case CLASSPATH_ORIGIN: final PluginRegistry pluginRegistry = pmi.getPluginRegistry(); final PluginMetaInformation metaInformation = pluginRegistry.getMetaInformationFor(plugin); if (metaInformation != null && metaInformation.classMeta != null && metaInformation.classMeta.pluginOrigin != null) rval.add(metaInformation.classMeta.pluginOrigin.toString()); break; default: this.logger.info("Requested InformationItem is not known!"); break; } return rval; } /** * @param plugin * @return */ private String[] getCaps(final Plugin plugin) { final Class<? extends Plugin> spawnClass = plugin.getClass(); final Method[] methods = spawnClass.getMethods(); // Search for proper method for (final Method method : methods) { // Init methods will be marked by the corresponding annotation. final Capabilities caps = method.getAnnotation(Capabilities.class); if (caps != null) { Object result = null; try { result = method.invoke(plugin, new Object[0]); } catch (final IllegalArgumentException e) { // } catch (final IllegalAccessException e) { // } catch (final InvocationTargetException e) { // } if (result != null && result instanceof String[]) return (String[]) result; } } return new String[0]; } /* (non-Javadoc) * @see net.xeoh.plugins.base.PluginInformation#getInformation(net.xeoh.plugins.base.Plugin, java.lang.Class) */ @Override public <T extends GetInformationOption> T getInformation(Plugin plugin, Class<T> query) { return null; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/PluginInformationImpl.java
Java
bsd
6,428
/* * PluginManager.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl; import static net.jcores.jre.CoreKeeper.$; import java.net.URI; import java.util.Arrays; import java.util.Collection; import java.util.Properties; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginConfiguration; import net.xeoh.plugins.base.PluginInformation; import net.xeoh.plugins.base.PluginInformation.Information; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.meta.Author; import net.xeoh.plugins.base.annotations.meta.RecognizesOption; import net.xeoh.plugins.base.annotations.meta.Version; import net.xeoh.plugins.base.diagnosis.channels.tracing.PluginManagerTracer; import net.xeoh.plugins.base.impl.classpath.ClassPathManager; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation.PluginStatus; import net.xeoh.plugins.base.impl.registry.PluginRegistry; import net.xeoh.plugins.base.impl.spawning.SpawnResult; import net.xeoh.plugins.base.impl.spawning.Spawner; import net.xeoh.plugins.base.options.AddPluginsFromOption; import net.xeoh.plugins.base.options.GetPluginOption; import net.xeoh.plugins.base.options.addpluginsfrom.OptionReportAfter; import net.xeoh.plugins.base.options.getplugin.OptionCapabilities; import net.xeoh.plugins.base.options.getplugin.OptionPluginSelector; import net.xeoh.plugins.base.options.getplugin.PluginSelector; import net.xeoh.plugins.base.util.OptionUtils; import net.xeoh.plugins.base.util.PluginConfigurationUtil; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.impl.DiagnosisImpl; import net.xeoh.plugins.diagnosis.local.options.status.OptionInfo; import net.xeoh.plugins.informationbroker.impl.InformationBrokerImpl; /** * Implementation of the PluginManager interface. Do not use this class. Do not cast the PluginManager to this implementation. * Do not access any of the public methods.<br> * * @author Ralf Biedert */ @PluginImplementation @Version(version = 1 * Version.UNIT_MAJOR + 0 * Version.UNIT_MINOR + 2 * Version.UNIT_RELEASE) @Author(name = "Ralf Biedert") public class PluginManagerImpl implements PluginManager { /** User properties for plugin configuration */ private final PluginConfiguration configuration; /** The main container for plugins and plugin information */ private final PluginRegistry pluginRegistry = new PluginRegistry(); /** Classloader used by plugin manager to locate and load plugin classes */ private final ClassPathManager classPathManager; /** Manages the creation of plugins */ private final Spawner spawner; /** Indicates if a shutdown has already been one */ private boolean shutdownPerformed = false; /** User properties for plugin configuration */ PluginInformation information; /** Diagnostic facilities */ Diagnosis diagnosis; /** * Construct new properties. * * @param initialProperties */ protected PluginManagerImpl(final Properties initialProperties) { // Create helper classes and config (needed early) this.spawner = new Spawner(this); this.classPathManager = new ClassPathManager(this); this.configuration = new PluginConfigurationImpl(initialProperties); // Hook fundamental plugins hookPlugin(new SpawnResult(this)); hookPlugin(new SpawnResult(this.configuration)); // Load the rest loadAdditionalPlugins(); applyConfig(); } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginManager#addPluginsFrom(java.net.URI, * net.xeoh.plugins.base.options.AddPluginsFromOption[]) */ public PluginManager addPluginsFrom(final URI url, final AddPluginsFromOption... options) { this.diagnosis.channel(PluginManagerTracer.class).status("add/start", new OptionInfo("url", url)); if(url == null) return this; // Add from the given location if (!this.classPathManager.addFromLocation(url, options)) { this.diagnosis.channel(PluginManagerTracer.class).status("add/nohandler", new OptionInfo("url", url)); } // Check if we should print a report? if ($(options).get(OptionReportAfter.class, null) != null) this.pluginRegistry.report(); this.diagnosis.channel(PluginManagerTracer.class).status("add/end", new OptionInfo("url", url)); return this; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginManager#getPlugin(java.lang.Class, * net.xeoh.plugins.base.option.GetPluginOption[]) */ @SuppressWarnings({ "unchecked" }) @RecognizesOption(option = OptionPluginSelector.class) public <P extends Plugin> P getPlugin(final Class<P> requestedPlugin, GetPluginOption... options) { // Report our request. if (this.diagnosis != null) { String name = requestedPlugin == null ? "null" : requestedPlugin.getCanonicalName(); this.diagnosis.channel(PluginManagerTracer.class).status("get/start", new OptionInfo("plugin", name)); } // We don't handle null values. if (requestedPlugin == null) { this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null)); return null; } // Sanity check. if (!requestedPlugin.isInterface()) { this.diagnosis.channel(PluginManagerTracer.class).status("get/onlyinterface", new OptionInfo("plugin", requestedPlugin.getCanonicalName())); this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null)); System.err.println("YOU MUST NOT call getPlugin() with a concrete class; only interfaces are"); System.err.println("supported for lookup. This means do not call getPlugin(MyPluginImpl.class),"); System.err.println("but rather getPlugin(MyPlugin.class)!"); return null; } // Used to process the options final OptionUtils<GetPluginOption> ou = new OptionUtils<GetPluginOption>(options); // We use this one to select the plugin PluginSelector<P> pluginSelector = null; // Check our options. In case we have a plugin selector, only use the selector if (ou.contains(OptionPluginSelector.class)) { pluginSelector = ou.get(OptionPluginSelector.class).getSelector(); } else { // Capabilites we require final String capabilites[] = ou.get(OptionCapabilities.class, new OptionCapabilities()).getCapabilities(); // Get caps as list final Collection<String> caps = Arrays.asList(capabilites); // Create our own selector pluginSelector = new PluginSelector<P>() { public boolean selectPlugin(final Plugin plugin) { // In case we have caps do special handling and don't return the next // best plugin if (caps.size() > 0) { Collection<String> pcaps = PluginManagerImpl.this.information.getInformation(Information.CAPABILITIES, plugin); // Check the plugin has them all if (pcaps.containsAll(caps)) return true; return false; } return true; } }; } // Check for each plugin if it matches for (final Plugin plugin : this.pluginRegistry.getAllPlugins()) { if (this.diagnosis != null) this.diagnosis.channel(PluginManagerTracer.class).status("get/considering", new OptionInfo("plugin", plugin.toString())); // Check the meta information for this plugin. We only want active classes final PluginMetaInformation metaInformation = this.pluginRegistry.getMetaInformationFor(plugin); // Plugins not active are not considered if (metaInformation.pluginStatus != PluginStatus.ACTIVE) continue; // Check if the plugin can be assigned to the requested class if (requestedPlugin.isAssignableFrom(plugin.getClass())) { if (pluginSelector.selectPlugin((P) plugin)) { if (this.diagnosis != null) this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", plugin.toString())); return (P) plugin; } } } if (this.diagnosis != null) this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null)); return null; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginManager#shutdown() */ public void shutdown() { this.diagnosis.channel(PluginManagerTracer.class).status("shutdown/start"); // Only execute this method a single time. if (this.shutdownPerformed) { this.diagnosis.channel(PluginManagerTracer.class).status("shutdown/end/alreadyperformed"); return; } // Destroy plugins in a random order for (final Plugin p : this.pluginRegistry.getAllPlugins()) { this.diagnosis.channel(PluginManagerTracer.class).status("shutdown/destroy", new OptionInfo("plugin", p.getClass().getCanonicalName())); this.spawner.destroyPlugin(p, this.pluginRegistry.getMetaInformationFor(p)); } // Curtains down, lights out. this.pluginRegistry.clear(); this.shutdownPerformed = true; this.diagnosis.channel(PluginManagerTracer.class).status("shutdown/end"); } /** * Apply things from the config. */ @SuppressWarnings("boxing") private void applyConfig() { final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.configuration); final String cachePath = this.configuration.getConfiguration(PluginManager.class, "cache.file"); this.classPathManager.getCache().setEnabled(pcu.getBoolean(PluginManager.class, "cache.enabled", false)); this.classPathManager.getCache().setCachePath(cachePath); // Check if we should enable weak mode final String mode = pcu.getString(PluginManager.class, "cache.mode", "strong"); if (mode.equals("weak")) { this.classPathManager.getCache().setWeakMode(true); } } /** * Load some additional plugins. */ private void loadAdditionalPlugins() { // Remaining core plugins hookPlugin(this.spawner.spawnPlugin(InformationBrokerImpl.class)); // We need the information plugin in getPlugin, so we can't get it normally. this.information = (PluginInformation) this.spawner.spawnPlugin(PluginInformationImpl.class).plugin; this.diagnosis = (Diagnosis) this.spawner.spawnPlugin(DiagnosisImpl.class).plugin; // Inject additional information (MUST NOT USE @InjectPlugin at this point, as // they are not set // 'active' yet) and perform manual init ((PluginInformationImpl) this.information).pluginManager = this; ((DiagnosisImpl) this.diagnosis).configuration = this.configuration; ((DiagnosisImpl) this.diagnosis).init(); hookPlugin(new SpawnResult(this.information)); hookPlugin(new SpawnResult(this.diagnosis)); // Set all plugins as active we have so far ... final Collection<Plugin> allPlugins = this.pluginRegistry.getAllPlugins(); for (Plugin plugin : allPlugins) { this.pluginRegistry.getMetaInformationFor(plugin).pluginStatus = PluginStatus.ACTIVE; } } /** * Adds a plugins to the list of known plugins and performs late initialization and * processing. * * @param p The SpawnResult to hook. */ public void hookPlugin(SpawnResult p) { // 1. Process plugin @PluginLoaded annotation for this plugins. TODO: Why was // this process split? Can't we just do everything in one method before or // after the plugins was registered? this.spawner.processThisPluginLoadedAnnotation(p.plugin, p.metaInformation); // Finally register it. this.pluginRegistry.registerPlugin(p.plugin, p.metaInformation); // Process plugin loaded information this.spawner.processOtherPluginLoadedAnnotation(p.plugin); } /** * Returns the ClassPathManger handling our plugin sources. * * @return The PluginManager. */ public ClassPathManager getClassPathManager() { return this.classPathManager; } /** * Returns the PluginRegistry, keeping track of loaded plugins. * * @return The PluginRegistry. */ public PluginRegistry getPluginRegistry() { return this.pluginRegistry; } /** * Returns the PluginConfiguration handling application setup. * * @return Returns the plugin configuration. */ public PluginConfiguration getPluginConfiguration() { return this.configuration; } /** * Returns the Diagnosis. * * @return The diagnosis. */ public Diagnosis getDiagnosis() { return this.diagnosis; } /** * Returns the main spawner to instantiate plugins. * * @return The Spawner. */ public Spawner getSpawner() { return this.spawner; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/PluginManagerImpl.java
Java
bsd
15,233
/* * MBeansDiagnosisProvider.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.jmx; import java.lang.management.ManagementFactory; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; import javax.management.DynamicMBean; import javax.management.InstanceAlreadyExistsException; import javax.management.IntrospectionException; import javax.management.InvalidAttributeValueException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanConstructorInfo; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanNotificationInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.ReflectionException; /** * @author rb * */ public class MBeansDiagnosisProvider implements DynamicMBean { /** * @throws InstanceAlreadyExistsException * @throws MBeanRegistrationException * @throws NotCompliantMBeanException * @throws MalformedObjectNameException * @throws ReflectionException * @throws MBeanException * @throws NullPointerException */ public MBeansDiagnosisProvider() throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, ReflectionException, MBeanException, NullPointerException { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); System.out.println(server.getMBeanCount()); for (Object object : server.queryMBeans(new ObjectName("*:*"), null)) System.out.println(((ObjectInstance) object).getObjectName()); ObjectName name = new ObjectName("com.javatutor.insel.jmx:type=MBeansDiagnosisProvider"); server.registerMBean(this, name); } /** * @param args * @throws InstanceAlreadyExistsException * @throws MBeanRegistrationException * @throws NotCompliantMBeanException * @throws MalformedObjectNameException * @throws ReflectionException * @throws MBeanException * @throws NullPointerException * @throws InterruptedException */ @SuppressWarnings("unused") public static void main(String[] args) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, ReflectionException, MBeanException, NullPointerException, InterruptedException { new MBeansDiagnosisProvider(); Thread.sleep(1000 * 1000); } public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { // TODO Auto-generated method stub System.out.println("getAttr " + attribute); return null; } public AttributeList getAttributes(String[] attributes) { System.out.println("getAttrs"); // TODO Auto-generated method stub return null; } public MBeanInfo getMBeanInfo() { System.out.println("getM"); MBeanAttributeInfo mai = null; try { mai = new MBeanAttributeInfo("mname", "Desccasas", MBeansDiagnosisProvider.class.getMethod("test"), null); } catch (IntrospectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } MBeanNotificationInfo mni = new MBeanNotificationInfo(new String[] {"asd"}, "nmnm!", "asdklajsdasl"); return new MBeanInfo("clzName", "Desc", new MBeanAttributeInfo[] { mai }, new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[] {mni}); } public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException { // TODO Auto-generated method stub return null; } public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { // TODO Auto-generated method stub System.out.println("setAttr"); } public AttributeList setAttributes(AttributeList attributes) { System.out.println("setAttrrs"); return null; } /** * @return . */ public int test() { System.out.println("Test"); return 123; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/jmx/MBeansDiagnosisProvider.java
Java
bsd
6,995
/* * PluginMetaInformation.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.registry; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; import net.xeoh.plugins.base.Plugin; /** * Meta information of the given plugin. * * @author Ralf Biedert */ public class PluginMetaInformation { /** Handles PluginLoaded annotations */ public static class PluginLoadedInformation { /** Annotated method */ public Method method; /** Base type to call with */ public Class<? extends Plugin> baseType; /** Items already put into the method */ public List<Plugin> calledWith = new ArrayList<Plugin>(); } /** * @author rb */ public static enum PluginStatus { /** No further information is available */ UNDEFINED, /** Plugin has been spawned, i.e., constructed. */ SPAWNED, /** Plugin has been initialized and all threads and timers have been spawned */ INITIALIZED, /** * Plugin is currently running (default state when * everything is okay) */ ACTIVE, /** Plugin was shut down. */ TERMINATED, /** Plugin failed to initialize due to own report. */ FAILED } /** Status of the plugin */ public PluginStatus pluginStatus = PluginStatus.UNDEFINED; /** Meta information of the parent class */ public PluginClassMetaInformation classMeta = null; /** List of declared threads, managed by the Spawner */ public final List<Thread> threads = new ArrayList<Thread>(); /** List of declared timer tasks, managed by the Spawner */ public final List<TimerTask> timerTasks = new ArrayList<TimerTask>(); /** List of declared timer tasks, managed by the Spawner */ public final List<Timer> timers = new ArrayList<Timer>(); /** Handles plugin loaded information */ public final List<PluginLoadedInformation> pluginLoadedInformation = new ArrayList<PluginLoadedInformation>(); /** Time this pluggable has been spawned. */ public long spawnTime; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/registry/PluginMetaInformation.java
Java
bsd
3,712
/* * PluginRegistry.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.registry; import static net.jcores.jre.CoreKeeper.$; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import net.jcores.jre.interfaces.functions.F1; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.Dependency; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.PluginClassStatus; /** * The registry keeps track of all instantiated plugins. * * @author Ralf Biedert */ public class PluginRegistry { /** Stores meta information related to a plugin */ private final Map<Plugin, PluginMetaInformation> pluginMetaInformation; /** Stores meta information related to a plugin class */ private final Map<Class<? extends Plugin>, PluginClassMetaInformation> pluginClassMetaInformation; /** * Creates a new registry */ public PluginRegistry() { this.pluginMetaInformation = new ConcurrentHashMap<Plugin, PluginMetaInformation>(); this.pluginClassMetaInformation = new ConcurrentHashMap<Class<? extends Plugin>, PluginClassMetaInformation>(); } /** * Returns all plugins, regardless of their status * * @return . */ public Collection<Plugin> getAllPlugins() { return this.pluginMetaInformation.keySet(); } /** * Returns the metainfromation of a plugin * * @param plugin * @return . */ public PluginMetaInformation getMetaInformationFor(Plugin plugin) { return this.pluginMetaInformation.get(plugin); } /** * Returns the metainfromation of a pluginclass * * @param clazz * @return . */ public PluginClassMetaInformation getMetaInformationFor(Class<? extends Plugin> clazz) { return this.pluginClassMetaInformation.get(clazz); } /** * Remove all plugin references */ public void clear() { this.pluginClassMetaInformation.clear(); this.pluginMetaInformation.clear(); } /** * Registers a plugin with the given meta information * * @param plugin * @param metaInformation */ public void registerPlugin(Plugin plugin, PluginMetaInformation metaInformation) { this.pluginMetaInformation.put(plugin, metaInformation); } /** * @param c * @param metaInformation */ public void registerPluginClass(Class<? extends Plugin> c, PluginClassMetaInformation metaInformation) { this.pluginClassMetaInformation.put(c, metaInformation); } /** * Returns all classes with a given status. * * @param status * @return . */ public Collection<Class<? extends Plugin>> getPluginClassesWithStatus(PluginClassStatus status) { final List<Class<? extends Plugin>> rval = new ArrayList<Class<? extends Plugin>>(); final Set<Class<? extends Plugin>> keySet = this.pluginClassMetaInformation.keySet(); for (Class<? extends Plugin> class1 : keySet) { final PluginClassMetaInformation metaInformation = this.pluginClassMetaInformation.get(class1); if (metaInformation.pluginClassStatus == status) rval.add(class1); } return rval; } /** * Prints a report of this registry. */ public void report() { System.out.println(); System.out.println(">>> Class Report <<<"); final Set<Class<? extends Plugin>> keySet = this.pluginClassMetaInformation.keySet(); for (Class<? extends Plugin> class1 : keySet) { final PluginClassMetaInformation meta = this.pluginClassMetaInformation.get(class1); System.out.print(" " + class1.getCanonicalName() + " (status:'" + meta.pluginClassStatus); System.out.print("'; dependencies:'" + $(meta.dependencies).map(new F1<PluginClassMetaInformation.Dependency, String>() { public String f(Dependency x) { return x.pluginClass.getSimpleName(); } }).string().join(",")); System.out.print("'; origin:'" + meta.pluginOrigin + "';)"); System.out.println(); } System.out.println(); System.out.println(">>> Object Report <<<"); final Set<Plugin> keySet2 = this.pluginMetaInformation.keySet(); for (Plugin plugin : keySet2) { final PluginMetaInformation meta = this.pluginMetaInformation.get(plugin); System.out.println(" " + plugin + " (status:'" + meta.pluginStatus + "')"); } System.out.println(); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/registry/PluginRegistry.java
Java
bsd
6,305
/* * PluginClassMetaInformation.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.registry; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import net.xeoh.plugins.base.Plugin; /** * Meta information of the given plugin class. * * @author Ralf Biedert */ public class PluginClassMetaInformation { /** * @author rb */ public static enum PluginClassStatus { /** No further information are available. Should not be observed * under normal circumstances. */ UNDEFINED, /** Plugin has been accepted as a valid plugin */ ACCEPTED, /** Disabled due to various reasons (check logging output). */ DISABLED, /** Plugin contains unresolved dependencies */ CONTAINS_UNRESOLVED_DEPENDENCIES, /** Plugin is ready for spawning, should happen soon. */ SPAWNABLE, /** Plugin has been lazy-spawned. ??? */ LAZY_SPAWNED, /** Plugin has been spawned. Should be accessible now * by getPlugin(). */ SPAWNED, /** If the class failed to spawn */ FAILED, } /** * Another plugin this plugin depends on. * * @author rb * */ public static class Dependency { /** */ public Class<? extends Plugin> pluginClass; /** */ public String[] capabilites = new String[0]; /** */ public boolean isOptional = false; } /** Status of this plugin class */ public PluginClassStatus pluginClassStatus = PluginClassStatus.UNDEFINED; /** Where this plugin came from */ public URI pluginOrigin; /** The dependencies of this class */ public Collection<Dependency> dependencies = new ArrayList<Dependency>(); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/registry/PluginClassMetaInformation.java
Java
bsd
3,324
/* * ClassPathManager.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.impl.classpath.cache.JARCache.JARInformation; import net.xeoh.plugins.base.impl.classpath.loader.AbstractLoader; import net.xeoh.plugins.base.impl.classpath.loader.FileLoader; import net.xeoh.plugins.base.impl.classpath.loader.HTTPLoader; import net.xeoh.plugins.base.impl.classpath.loader.InternalClasspathLoader; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import net.xeoh.plugins.base.impl.classpath.locator.ClassPathLocator; import net.xeoh.plugins.base.impl.classpath.locator.locations.JARClasspathLocation; import net.xeoh.plugins.base.options.AddPluginsFromOption; import org.codehaus.classworlds.ClassRealm; import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.DuplicateRealmException; import org.codehaus.classworlds.NoSuchRealmException; /** * Manages all our classpaths shared by different plugins. * * @author Ralf Biedert */ public class ClassPathManager { /** Console and file logging */ private final Logger logger = Logger.getLogger(this.getClass().getName()); /** Blocks access to the file cache */ private final Lock cacheLock = new ReentrantLock(); /** Manages content cache of jar files */ private final JARCache jarCache = new JARCache(); /** Locates possible classpaths */ private final ClassPathLocator locator; /** Loads plugins from various urls */ private final Collection<AbstractLoader> pluginLoader = new ArrayList<AbstractLoader>(); /** Manages classpaths from URLs */ ClassWorld classWorld; /** * Indicates if we're initialized properly (application mode) or if we had sandbox * problems (applet mode). */ boolean initializedProperly = false; /** * @param pluginManager */ @SuppressWarnings("synthetic-access") public ClassPathManager(PluginManagerImpl pluginManager) { this.locator = new ClassPathLocator(pluginManager, this.jarCache); // Register loader this.pluginLoader.add(new InternalClasspathLoader(pluginManager)); this.pluginLoader.add(new FileLoader(pluginManager)); this.pluginLoader.add(new HTTPLoader(pluginManager)); // Initialization is a bit ugly, but we might be in a sandbox AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { try { // Try to create a new ClassWorld object ClassPathManager.this.classWorld = new ClassWorld(); // Create a core realm (for internal and classpath://* plugins) try { ClassPathManager.this.classWorld.newRealm("core", getClass().getClassLoader()); } catch (DuplicateRealmException e) { e.printStackTrace(); } // Signal that we are okay. ClassPathManager.this.initializedProperly = true; } catch (SecurityException e) { ClassPathManager.this.logger.warning("Proper initialization failed due to security restrictions. Only classpath://xxx URIs will work. Sorry."); } return null; } }); } /** * Locates plugins at a given source, loads them and adds them to the registry. * * @param location * @param options * @return . */ public boolean addFromLocation(URI location, AddPluginsFromOption[] options) { if(location == null) return false; this.cacheLock.lock(); try { // Load local cache this.jarCache.loadCache(); // Handle URI for (AbstractLoader loader : this.pluginLoader) { if (!loader.handlesURI(location)) continue; loader.loadFrom(location, options); return true; } } finally { this.jarCache.saveCache(); this.cacheLock.unlock(); } return false; } /** * Loads a class given its name and classpath location. * * @param location Specifies where this plugins should be obtained from, or * <code>null</code> if we should use our own classloader. * @param name The name of the class to load. * * @return The requested class. * * @throws ClassNotFoundException */ public Class<?> loadClass(AbstractClassPathLocation location, String name) throws ClassNotFoundException { // In case no location is supplied ... if (location == null) { return getClass().getClassLoader().loadClass(name); } try { if (this.initializedProperly) { final ClassLoader classLoader = this.classWorld.getRealm(location.getRealm()).getClassLoader(); return classLoader.loadClass(name); } } catch (ClassNotFoundException e) { return getClass().getClassLoader().loadClass(name); } catch (NoSuchRealmException e) { e.printStackTrace(); } // And again, this time we run this code if we have not been inititalized properly return getClass().getClassLoader().loadClass(name); } /** * Finds all subclasses for the given superclass. * * @param location The location to search for. * @param superclass The superclass to obtain subclasses for. * * @return A list of plugin names extending <code>superclass</code>. */ public Collection<String> findSubclassesFor(AbstractClassPathLocation location, Class<?> superclass) { final Collection<String> rval = new ArrayList<String>(); if (!this.initializedProperly) return rval; // Check if we can get the requested information out of the cache JARInformation cacheEntry = null; // If it is a JAR entry, check if we have cache information if (location instanceof JARClasspathLocation) { cacheEntry = ((JARClasspathLocation) location).getCacheEntry(); if (cacheEntry != null) { final Collection<String> collection = cacheEntry.subclasses.get(superclass.getCanonicalName()); if (collection != null) return collection; } } // No? Okay, search the hard way ... try { final ClassLoader classLoader = this.classWorld.getRealm(location.getRealm()).getClassLoader(); final Collection<String> listClassNames = location.listToplevelClassNames(); for (String name : listClassNames) { try { final Class<?> c = Class.forName(name, false, classLoader); // No interfaces please if (c.isInterface()) continue; if (superclass.isAssignableFrom(c) && !superclass.getCanonicalName().equals(c.getCanonicalName())) { rval.add(name); } } catch (ClassNotFoundException e) { this.logger.fine("ClassNotFoundException. Unable to inspect class " + name + " although it appears to be one."); // Print all causes, helpful for debugging Throwable cause = e.getCause(); while (cause != null) { this.logger.fine("Reason " + cause.getMessage()); cause = cause.getCause(); } } catch (final NoClassDefFoundError e) { this.logger.finer("Ignored class " + name + " due to unresolved dependencies"); // Print all causes, helpful for debugging Throwable cause = e.getCause(); while (cause != null) { this.logger.fine("Reason " + cause.getMessage()); cause = cause.getCause(); } } catch (SecurityException e) { this.logger.fine("SecurityException while trying to find subclasses. Cause of trouble: " + name + ". This does not neccessarily mean problems however."); // Print all causes, helpful for debugging Throwable cause = e.getCause(); while (cause != null) { this.logger.fine("Reason " + cause.getMessage()); cause = cause.getCause(); } } catch (Exception e) { this.logger.finer("Ignored class " + name + " due to some other error"); Throwable cause = e.getCause(); while (cause != null) { this.logger.fine("Reason " + cause.getMessage()); cause = cause.getCause(); } } } } catch (NoSuchRealmException e1) { e1.printStackTrace(); } // Update the cache information if (cacheEntry != null) { cacheEntry.subclasses.put(superclass.getCanonicalName(), rval); } return rval; } /** * Adds a classpath location to this manager. * * @param location */ public void registerLocation(AbstractClassPathLocation location) { if (!this.initializedProperly) return; try { final ClassRealm newRealm = this.classWorld.newRealm(location.getRealm(), getClass().getClassLoader()); final URI[] classpathLocations = location.getClasspathLocations(); for (URI uri : classpathLocations) { newRealm.addConstituent(uri.toURL()); } } catch (DuplicateRealmException e) { // Happens for #classpath realms ... } catch (MalformedURLException e) { e.printStackTrace(); } } /** * Returns a resource as an input stream for a given location. * * @param location The location to use. * @param name The requested resource. * @return The input stream for the requested resource or <code>null</code> if none * was found. */ public InputStream getResourceAsStream(AbstractClassPathLocation location, String name) { // In case no location is supplied ... if (location == null) { return getClass().getClassLoader().getResourceAsStream(name); } try { final ClassLoader classLoader = this.classWorld.getRealm(location.getRealm()).getClassLoader(); return classLoader.getResourceAsStream(name); } catch (NoSuchRealmException e) { e.printStackTrace(); } return null; } /** * Returns our locator. * * @return The locator. */ public ClassPathLocator getLocator() { return this.locator; } /** * Returns the JAR cache. * * @return The cache. */ public JARCache getCache() { return this.jarCache; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/ClassPathManager.java
Java
bsd
13,253
/* * InternalClasspathLoader.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.loader; import java.net.URI; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.classpath.ClassPathManager; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import net.xeoh.plugins.base.impl.classpath.locator.ClassPathLocator; import net.xeoh.plugins.base.options.AddPluginsFromOption; /** * A loader to handle classpath://* URIs. * * @author Ralf Biedert */ public class InternalClasspathLoader extends AbstractLoader { /** * @param pluginManager */ public InternalClasspathLoader(PluginManagerImpl pluginManager) { super(pluginManager); } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#handlesURI(java.net.URI) */ @Override public boolean handlesURI(URI uri) { if (uri != null && "classpath".equals(uri.getScheme())) return true; return false; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#loadFrom(java.net.URI) */ @Override public void loadFrom(URI url, AddPluginsFromOption[] options) { // Special handler to load files from the local classpath if (url.toString().contains("*")) { if (url.toString().equals("classpath://*")) { loadAllClasspathPluginClasses(null, options); } else { String pattern = url.toString(); pattern = pattern.replace("**", ".+"); pattern = pattern.replace("*", "[^\\.]*"); pattern = pattern.replace("classpath://", ""); loadAllClasspathPluginClasses(pattern, options); } return; } // Special handler to load files from the local classpath, specified by name. // Please note that this is a very bad solution and should only be used in special // cases, // as when invoking from applets that don't have permission to access the // classpath (is this so) if (url.toString().startsWith("classpath://")) { // Obtain the fq-classname to load final String toLoad = url.toString().substring("classpath://".length()); // Try to load all plugins, might cause memory problems due to Issue #20. try { loadClassFromClasspathByName(toLoad); } catch (OutOfMemoryError error) { this.logger.severe("Due to a bug (Issue #20), JSPF ran low on memory. Please increase your memory by (e.g., -Xmx1024m) or specify a 'classpath.filter.default.pattern' options. We hope to fix this bux in some future release. We are sorry for the inconvenience this might cause and we can understand if you hate us now :-(."); error.printStackTrace(); } return; } } /** * Load all plugins from the classpath that match a given pattern. * * @param pattern * @param options */ private void loadAllClasspathPluginClasses(String pattern, AddPluginsFromOption[] options) { // Start the classpath search this.logger.finer("Starting classpath search with pattern " + pattern); // Get all classpath locations of the current classpath final ClassPathManager manager = this.pluginManager.getClassPathManager(); final ClassPathLocator locator = manager.getLocator(); final Collection<AbstractClassPathLocation> locations = locator.findInCurrentClassPath(options); // Process all locations for (AbstractClassPathLocation location : locations) { manager.registerLocation(location); final Collection<String> candidates = manager.findSubclassesFor(location, Plugin.class); this.logger.finer("Found " + candidates.size() + " candidates."); // Check all candidates for (String string : candidates) { // Either try to add them all, or only those who match a given pattern if (pattern == null) tryToLoadClassAsPlugin(location, string); else { final Pattern p = Pattern.compile(pattern); final Matcher m = p.matcher(string); this.logger.finest(string + " " + m.matches()); if (m.matches()) { tryToLoadClassAsPlugin(location, string); } } } } return; } private void loadClassFromClasspathByName(final String toLoad) { this.logger.fine("Loading " + toLoad + " directly"); tryToLoadClassAsPlugin(null, toLoad); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/loader/InternalClasspathLoader.java
Java
bsd
6,509
/* * AbstractLoader.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.loader; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Properties; import java.util.Set; import java.util.logging.Logger; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.configuration.ConfigurationFile; import net.xeoh.plugins.base.annotations.configuration.IsDisabled; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.classpath.ClassPathManager; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.Dependency; import net.xeoh.plugins.base.impl.registry.PluginClassMetaInformation.PluginClassStatus; import net.xeoh.plugins.base.impl.registry.PluginMetaInformation.PluginStatus; import net.xeoh.plugins.base.impl.registry.PluginRegistry; import net.xeoh.plugins.base.impl.spawning.SpawnResult; import net.xeoh.plugins.base.impl.spawning.Spawner; import net.xeoh.plugins.base.options.AddPluginsFromOption; import net.xeoh.plugins.base.options.getplugin.OptionCapabilities; import net.xeoh.plugins.base.util.PluginConfigurationUtil; /** * The abstract base class of all loaders, provides methods for spawning classes. * * @author Ralf Biedert */ public abstract class AbstractLoader { /** */ protected final Logger logger = Logger.getLogger(this.getClass().getName()); /** Grants access to various shared variables. */ protected final PluginManagerImpl pluginManager; /** * @param pluginManager */ public AbstractLoader(PluginManagerImpl pluginManager) { this.pluginManager = pluginManager; } /** * @param uri * @return . */ public abstract boolean handlesURI(URI uri); /** * Load plugins from a given source * * @param uri * @param options */ public abstract void loadFrom(URI uri, AddPluginsFromOption[] options); /** * Tries to load a class from a given source. If it is a plugin, it will be * registered. * * @param location * @param name */ @SuppressWarnings({ "unchecked", "boxing" }) protected void tryToLoadClassAsPlugin(AbstractClassPathLocation location, final String name) { this.logger.finest("Trying to load " + name + " as a plugin."); // Obtain some shared objects // final JARCache jarCache = this.pluginManager.getJARCache(); final ClassPathManager classPathManager = this.pluginManager.getClassPathManager(); final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry(); final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration()); final Spawner spawner = this.pluginManager.getSpawner(); // Obtain information // final JARInformation jarInformation = jarCache.getJARInformation(name); // final String file = jarCache.classTofile(name); try { // Get class of the candidate final Class<?> possiblePlugin = classPathManager.loadClass(location, name); // Don't load plugins already spawned. if (name.startsWith("net.xeoh.plugins.base") || name.startsWith("net.xeoh.plugins.diagnosis.") || name.startsWith("net.xeoh.plugins.informationbroker.")) return; // Get the plugin's annotation final PluginImplementation annotation = possiblePlugin.getAnnotation(PluginImplementation.class); // Nothing to load here if no annotation is present if (annotation == null) { return; } // Don't load classes already loaded from this location final PluginClassMetaInformation preexistingMeta = pluginRegistry.getMetaInformationFor((Class<? extends Plugin>) possiblePlugin); if (preexistingMeta != null) { this.logger.info("Skipping plugin " + possiblePlugin + " because we already have it "); return; } // Register class at registry final PluginClassMetaInformation metaInformation = new PluginClassMetaInformation(); metaInformation.pluginClassStatus = PluginClassStatus.ACCEPTED; if (location != null) { metaInformation.pluginOrigin = location.getToplevelLocation(); } else { metaInformation.pluginOrigin = new URI("classpath://UNDEFINED"); } pluginRegistry.registerPluginClass((Class<? extends Plugin>) possiblePlugin, metaInformation); // Update the class information of the corresponding cache entry this.logger.finer("Updating cache information"); // Avoid loading if annotation request it. if (pcu.getBoolean(possiblePlugin, "plugin.disabled", false) || possiblePlugin.getAnnotation(IsDisabled.class) != null) { metaInformation.pluginClassStatus = PluginClassStatus.DISABLED; this.logger.fine("Ignoring " + name + " due to request."); return; } // Up from here we know we will (eventually) use the plugin. So load its // configuration. final String properties = (possiblePlugin.getAnnotation(ConfigurationFile.class) != null) ? possiblePlugin.getAnnotation(ConfigurationFile.class).file() : null; if (properties != null && properties.length() > 0) { final String resourcePath = name.replaceAll("\\.", "/").replaceAll(possiblePlugin.getSimpleName(), "") + properties; this.logger.fine("Adding configuration from " + resourcePath + " for plugin " + name); final Properties p = new Properties(); // Try to load resource by special classloader try { p.load(classPathManager.getResourceAsStream(location, resourcePath)); final Set<Object> keys = p.keySet(); // Add every string that is not already in the configuration. for (final Object object : keys) { if (pcu.getString(null, (String) object) != null) { this.pluginManager.getPluginConfiguration().setConfiguration(null, (String) object, p.getProperty((String) object)); } } } catch (final IOException e) { this.logger.warning("Unable to load properties " + resourcePath + " although requested"); } catch (final NullPointerException e) { this.logger.warning("Unable to load properties " + resourcePath + " although requested. Probably not in package."); } } // Obtain dependencies metaInformation.dependencies = spawner.getDependencies((Class<? extends Plugin>) possiblePlugin); // If the class has unfulfilled dependencies, add it to our list. if (metaInformation.dependencies.size() == 0) { metaInformation.pluginClassStatus = PluginClassStatus.SPAWNABLE; } else { metaInformation.pluginClassStatus = PluginClassStatus.CONTAINS_UNRESOLVED_DEPENDENCIES; } } catch (final ClassNotFoundException e) { e.printStackTrace(); this.logger.warning("ClassNotFoundException. Unable to inspect class " + name + " although it appears to be one."); } catch (final NoClassDefFoundError e) { e.printStackTrace(); this.logger.finer("Ignored class " + name + " due to unresolved dependencies"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } // We always try to load pending classes ... processPending(); } /** * Try to load a pending class. */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected void processPending() { // Obtain shared objects final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry(); final Spawner spawner = this.pluginManager.getSpawner(); // All classes we want to spawn final Collection<Class<? extends Plugin>> toSpawn = new ArrayList<Class<? extends Plugin>>(); toSpawn.addAll(pluginRegistry.getPluginClassesWithStatus(PluginClassStatus.CONTAINS_UNRESOLVED_DEPENDENCIES)); toSpawn.addAll(pluginRegistry.getPluginClassesWithStatus(PluginClassStatus.SPAWNABLE)); // Check if there is work to do. if (toSpawn.size() == 0) return; boolean loopAgain; do { // Classes we want to spawn final Collection<Class<? extends Plugin>> spawned = new ArrayList<Class<? extends Plugin>>(); // Reset hasLoaded flag loopAgain = false; // Check all known classes ... for (final Class c : toSpawn) { this.logger.fine("Trying to load pending " + c); final PluginClassMetaInformation metaInformation = pluginRegistry.getMetaInformationFor(c); // If the class is spawnable, spawn it ... if (metaInformation.pluginClassStatus == PluginClassStatus.SPAWNABLE) { this.logger.fine("Class found as SPAWNABLE. Trying to spawn it now " + c); // // The magic line: spawn it. // final SpawnResult p = spawner.spawnPlugin(c); // In case we were successful ... if (p != null && p.metaInformation.pluginStatus != PluginStatus.FAILED) { // Link the parent class meta information p.metaInformation.classMeta = metaInformation; // Check if the class is active or only lazy spawned if (p.metaInformation.pluginStatus == PluginStatus.ACTIVE) { // Mark the class a spawned metaInformation.pluginClassStatus = PluginClassStatus.SPAWNED; spawned.add(c); this.pluginManager.hookPlugin(p); } // Lazy spawn ... if (p.metaInformation.pluginStatus == PluginStatus.SPAWNED) { metaInformation.pluginClassStatus = PluginClassStatus.LAZY_SPAWNED; throw new IllegalStateException("Lazy spawning not supported yet!"); } // And loop once more. loopAgain = true; break; } // This case is bad ... this.logger.warning("Failed to spawn class " + c); metaInformation.pluginClassStatus = PluginClassStatus.FAILED; } // Check if we can switch the class to SPAWNABLE if (metaInformation.pluginClassStatus == PluginClassStatus.CONTAINS_UNRESOLVED_DEPENDENCIES) { this.logger.fine("Trying to solve dependencies for class " + c); boolean resolvedAll = true; // Check all dependencies for (Dependency d : metaInformation.dependencies) { if (d.isOptional) { this.logger.finest("Skipping dependency as optional " + d.pluginClass); continue; } if (this.pluginManager.getPlugin(d.pluginClass, new OptionCapabilities(d.capabilites)) == null) { resolvedAll = false; } } // Nice. So this class will be spawned in one of the next rounds ... if (resolvedAll) { metaInformation.pluginClassStatus = PluginClassStatus.SPAWNABLE; loopAgain = true; break; } } } // Remove all spawned from the list (not really necessary, is it?) toSpawn.removeAll(spawned); } while (loopAgain && toSpawn.size() > 0); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/loader/AbstractLoader.java
Java
bsd
14,300
/* * InternalClasspathLoader.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.loader; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; import java.util.Collection; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.classpath.ClassPathManager; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; import net.xeoh.plugins.base.impl.classpath.locator.ClassPathLocator; import net.xeoh.plugins.base.impl.classpath.locator.locations.JARClasspathLocation; import net.xeoh.plugins.base.options.AddPluginsFromOption; /** * @author rb * */ public class FileLoader extends AbstractLoader { /** * @param pluginManager */ public FileLoader(PluginManagerImpl pluginManager) { super(pluginManager); } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#handlesURI(java.net.URI) */ @Override public boolean handlesURI(URI uri) { if (uri != null && "file".equals(uri.getScheme())) return true; return false; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#loadFrom(java.net.URI) */ @Override public void loadFrom(URI url, AddPluginsFromOption[] options) { // If not caught by the previous handler, handle files normally. if (url.getScheme().equals("file")) { // Get the actual file from the given path (TODO: Why don't we do new // File(url)?) String file = url.getPath(); // FIXME: Where does this trailing slash come from ?! if (file.startsWith("/") && file.substring(0, 4).contains(":")) { file = file.substring(1); } // Try to decode the path properly try { file = URLDecoder.decode(file, "utf8"); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } // Now load from the given file ... this.logger.fine("More specifically, trying to add from " + file); final File root = new File(file); // ... if it exists ... if (!root.exists()) { this.logger.warning("Supplied path does not exist. Unable to add plugins from there."); return; } // Here we go locateAllPluginsAt(root); return; } } /** * Given a top level directory, we locate all classpath locations and load all plugins * we find. * * @param root The top level to start from. */ void locateAllPluginsAt(File root) { final ClassPathManager manager = this.pluginManager.getClassPathManager(); final ClassPathLocator locator = manager.getLocator(); final Collection<AbstractClassPathLocation> locations = locator.findBelow(root.toURI()); for (AbstractClassPathLocation location : locations) { manager.registerLocation(location); Collection<String> subclasses = null; // Check if it has a list of plugins if (location instanceof JARClasspathLocation) { final JARClasspathLocation jarLocation = (JARClasspathLocation) location; subclasses = jarLocation.getPredefinedPluginList(); } // Add all found files ... if we have no predefined list if (subclasses == null) subclasses = manager.findSubclassesFor(location, Plugin.class); // Try to load them for (String string : subclasses) { tryToLoadClassAsPlugin(location, string); } } } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/loader/FileLoader.java
Java
bsd
5,387
/* * InternalClasspathLoader.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.loader; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URI; import java.net.URL; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.options.AddPluginsFromOption; /** * @author rb * */ public class HTTPLoader extends FileLoader { /** * @param pluginManager */ public HTTPLoader(PluginManagerImpl pluginManager) { super(pluginManager); } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#handlesURI(java.net.URI) */ @Override public boolean handlesURI(URI uri) { if (uri != null && "http".equals(uri.getScheme())) return true; return false; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.loader.AbstractLoader#loadFrom(java.net.URI) */ @Override public void loadFrom(URI url, AddPluginsFromOption[] options) { // Handle http files if ("http".equals(url.getScheme())) { try { // download the file (TODO: download could be improved a bit ...) java.io.File tmpFile = java.io.File.createTempFile("jspfplugindownload", ".jar"); final FileOutputStream fos = new FileOutputStream(tmpFile); final URL url2 = url.toURL(); final InputStream openStream = url2.openStream(); int read = 0; byte buf[] = new byte[1024]; while ((read = openStream.read(buf)) > 0) { fos.write(buf, 0, read); } fos.close(); openStream.close(); // BIG FAT TODO: Do signature check!!! locateAllPluginsAt(tmpFile); return; } catch (Exception e) { e.printStackTrace(); this.logger.warning("Error downloading plugins from " + url); } } } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/loader/HTTPLoader.java
Java
bsd
3,558
/* * JARClasspathLocation.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.locator.locations; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.JarURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; import net.jcores.jre.cores.CoreString; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; /** * A multi-plugin in a meta-plugin containing several sub-plugins sharing the same class * loader and have an external dependency folder. * * @author Ralf Biedert */ public class MultiPluginClasspathLocation extends AbstractClassPathLocation { /** Maps our returned entries to contained JARs (so we know where too look if we want to resolve them) */ final Map<String, String> entryMapping = new HashMap<String, String>(); /** All the JARs we handle */ final Collection<String> allJARs; /** * @param cache * @param realm * @param location */ public MultiPluginClasspathLocation(JARCache cache, String realm, URI location) { super(cache, realm, location); this.allJARs = $(location).file().dir().filter(".*jar$").string().list(); } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getType() */ @Override public LocationType getType() { return LocationType.MULTI_PLUGIN; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getClasspathLocations() */ @Override public URI[] getClasspathLocations() { return $(this.allJARs).as(CoreString.class).file().uri().array(URI.class); } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getInputStream(java.lang.String) */ @Override public InputStream getInputStream(String file) { final String uri = this.entryMapping.get(file); if (uri == null) return null; try { final JarURLConnection connection = (JarURLConnection) new URI("jar:" + new File(uri).toURI() + "!/").toURL().openConnection(); final JarFile jarFile = connection.getJarFile(); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); // We only search for class file entries if (entry.isDirectory()) continue; String name = entry.getName(); if (name.equals(file)) return jarFile.getInputStream(entry); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listAllEntries() */ @Override public Collection<String> listAllEntries() { ArrayList<String> rval = new ArrayList<String>(); for (String entry : this.allJARs) { final Collection<String> all = JARClasspathLocation.listAllEntriesFor(URI.create(entry)); for (String string : all) { this.entryMapping.put(string, entry); } rval.addAll(all); } return rval; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listToplevelClassNames() */ @Override public Collection<String> listToplevelClassNames() { ArrayList<String> rval = new ArrayList<String>(); for (String entry : this.allJARs) { final Collection<String> all = JARClasspathLocation.listToplevelClassNamesForURI(new File(entry).toURI()); for (String string : all) { this.entryMapping.put(string, entry); } rval.addAll(all); } return rval; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/locator/locations/MultiPluginClasspathLocation.java
Java
bsd
5,974
/* * JARClasspathLocation.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.locator.locations; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.regex.Pattern; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; /** * @author rb * */ public class FileClasspathLocation extends AbstractClassPathLocation { /** * @param cache * @param realm * @param location */ public FileClasspathLocation(JARCache cache, String realm, URI location) { super(cache, realm, location); } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getInputStream(java.lang.String) */ @Override public InputStream getInputStream(String entry) { final File toplevel = new File(this.location); try { return new FileInputStream(new File(toplevel.getAbsolutePath() + "/" + entry)); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getType() */ @Override public LocationType getType() { return LocationType.DIRECTORY; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listAllEntries() */ @Override public Collection<String> listAllEntries() { final Collection<String> rval = new ArrayList<String>(); final File toplevel = new File(this.location); try { List<File> fileListing = getFileListing(toplevel, new ArrayList<String>()); for (File file : fileListing) { // Only accept true files if (file.isDirectory()) continue; final String path = Pattern.quote(toplevel.getAbsolutePath()); String name = ""; name = file.getAbsolutePath().replaceAll(path, ""); name = name.substring(1); name = name.replace("\\", "/"); rval.add(name); } } catch (FileNotFoundException e) { e.printStackTrace(); } return rval; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listToplevelClassNames() */ @Override public Collection<String> listToplevelClassNames() { final Collection<String> rval = new ArrayList<String>(); final File toplevel = new File(this.location); try { List<File> fileListing = getFileListing(toplevel, new ArrayList<String>()); for (File file : fileListing) { // Only accept class files if (!file.getAbsolutePath().endsWith(".class")) continue; //if (file.getAbsolutePath().contains("$")) continue; // Why are we ignoring files with a $ again? final String path = Pattern.quote(toplevel.getAbsolutePath()); String name = ""; name = file.getAbsolutePath().replaceAll(path, ""); name = name.substring(1); name = name.replace("\\", "/"); name = name.replace("/", "."); // Remove trailing .class if (name.endsWith("class")) { name = name.substring(0, name.length() - 6); } rval.add(name); } } catch (FileNotFoundException e) { e.printStackTrace(); } return rval; } /** * List all files * * @param aStartingDir * @return * @throws FileNotFoundException */ private List<File> getFileListing(File aStartingDir, List<String> visited) throws FileNotFoundException { // Sanity check if (aStartingDir == null || aStartingDir.listFiles() == null) return new ArrayList<File>(); this.logger.fine("Obtaining file listing for: " + aStartingDir); final String[] ignoreList = new String[] { "/dev/", "/sys/", "/proc/" }; final List<File> result = new ArrayList<File>(); for (File file : aStartingDir.listFiles()) { boolean skip = false; // Very ugly Android related hack, remove this if we have a better solution to detect a recursion. for (String ignore : ignoreList) { if (file.getAbsolutePath().contains(ignore)) { this.logger.warning("Android hack actve. Ignoring directory containing " + ignore); skip = true; } } // Now skip if (skip) continue; result.add(file); // TODO: Is it possible that this doen't work as expected? Check if there is a better // recursion test ... { String canonical = null; // Why can this fail? try { canonical = file.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } // Anyway, safteycheck: Only process this path if it hasn't already been seen if (canonical != null) { if (visited.contains(canonical)) continue; visited.add(canonical); } } // Okay, in here the sub element must have been new, inspect it. if (file.isDirectory()) { List<File> deeperList = getFileListing(file, visited); result.addAll(deeperList); } } return result; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/locator/locations/FileClasspathLocation.java
Java
bsd
7,615
/* * JARClasspathLocation.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.locator.locations; import java.io.IOException; import java.io.InputStream; import java.net.JarURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.impl.classpath.cache.JARCache.JARInformation; import net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation; /** * Tries to load plugins from a JAR class path location. * * @author Ralf Biedert */ public class JARClasspathLocation extends AbstractClassPathLocation { /** * @param cache * @param realm * @param location */ public JARClasspathLocation(JARCache cache, String realm, URI location) { super(cache, realm, location); } /** * @return the location */ public JARInformation getCacheEntry() { // If we have a JAR if (getType() == LocationType.JAR && this.cache != null) this.cacheEntry = this.cache.getJARInformationFor(this.location); return this.cacheEntry; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getType() */ @Override public LocationType getType() { return LocationType.JAR; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#getInputStream(java.lang.String) */ @Override public InputStream getInputStream(String file) { try { final JarURLConnection connection = (JarURLConnection) new URI("jar:" + this.location + "!/").toURL().openConnection(); final JarFile jarFile = connection.getJarFile(); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); // We only search for class file entries if (entry.isDirectory()) continue; String name = entry.getName(); if (name.equals(file)) return jarFile.getInputStream(entry); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } /** * Returns a list of predefined plugins inside this jar. * * @return . */ public Collection<String> getPredefinedPluginList() { return null; } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listAllEntries() */ @Override public Collection<String> listAllEntries() { return listAllEntriesFor(this.location); } /* (non-Javadoc) * @see net.xeoh.plugins.base.impl.classpath.locator.AbstractClassPathLocation#listToplevelClassNames() */ @Override public Collection<String> listToplevelClassNames() { final Collection<String> rval = listToplevelClassNamesForURI(this.location); if (this.cacheEntry != null) this.cacheEntry.classesValid = true; return rval; } /** * Lists all entries for the given JAR. * * @param uri * @return . */ public static Collection<String> listAllEntriesFor(URI uri) { final Collection<String> rval = new ArrayList<String>(); try { final JarURLConnection connection = (JarURLConnection) new URI("jar:" + uri + "!/").toURL().openConnection(); final JarFile jarFile = connection.getJarFile(); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); // We only search for class file entries if (entry.isDirectory()) continue; String name = entry.getName(); rval.add(name); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return rval; } /** * Lists all top level class entries for the given URL. * * @param uri * @return . */ public static Collection<String> listToplevelClassNamesForURI(URI uri) { final Collection<String> rval = new ArrayList<String>(); // Ensure we have a proper cache entry ... //getCacheEntry(); // Disabled: Not really necessary, is it? And not storing/retrieving these items // makes the cache file smaller and saves several ms (~200) loading and storing it //if (this.cacheEntry.classesValid) { return this.cacheEntry.classes; } try { final JarURLConnection connection = (JarURLConnection) new URI("jar:" + uri + "!/").toURL().openConnection(); final JarFile jarFile = connection.getJarFile(); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); // We only search for class file entries if (entry.isDirectory()) continue; if (!entry.getName().endsWith(".class")) continue; String name = entry.getName(); name = name.replaceAll("/", "."); // Remove trailing .class if (name.endsWith("class")) { name = name.substring(0, name.length() - 6); } // Disabled: Not really necessary, is it? And not storing/retrieving these items // makes the cache file smaller and saves several ms (~200) loading and storing it // Only store something if we have a cache entry //if (this.cacheEntry != null) this.cacheEntry.classes.add(name); rval.add(name); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return rval; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/locator/locations/JARClasspathLocation.java
Java
bsd
8,153
/* * ClasspathLocator.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.locator; import static net.jcores.jre.CoreKeeper.$; import java.io.File; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collection; import java.util.List; import net.jcores.jre.interfaces.functions.F1; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.diagnosis.channels.tracing.SpawnerTracer; import net.xeoh.plugins.base.impl.PluginManagerImpl; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.options.AddPluginsFromOption; import net.xeoh.plugins.base.options.addpluginsfrom.OptionSearchAround; import net.xeoh.plugins.base.util.PluginConfigurationUtil; import net.xeoh.plugins.diagnosis.local.Diagnosis; import net.xeoh.plugins.diagnosis.local.util.DiagnosisChannelUtil; /** * Used to find classpaths, JARs and their contents. * * @author Ralf Biedert */ public class ClassPathLocator { /** Cache to lookup elements */ private final JARCache cache; /** Mainly used to access the config. */ private PluginManagerImpl pluginManager; /** * @param pluginManager * @param cache */ public ClassPathLocator(PluginManagerImpl pluginManager, JARCache cache) { this.pluginManager = pluginManager; this.cache = cache; } /** * Given a top level entry, finds a list of class path locations below the given * entry. The top level entry can either be a folder, or it can be a JAR directly. * * @param toplevel The top level URI to start from. * @return A list of class path locations. */ public Collection<AbstractClassPathLocation> findBelow(URI toplevel) { final Collection<AbstractClassPathLocation> rval = new ArrayList<AbstractClassPathLocation>(); final File startPoint = new File(toplevel); // First, check if the entry represents a multi-plugin (in that case we don't add // anything else) if ($(startPoint).filter(".*\\.plugin?$").get(0) != null) { rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, toplevel.toString(), toplevel)); return rval; } // Check if this is a directory or a file if (startPoint.isDirectory()) { final File[] listFiles = startPoint.listFiles(); boolean hasJARs = false; for (File file : listFiles) { if (file.getAbsolutePath().endsWith(".jar")) { rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, file.toURI().toString(), file.toURI())); hasJARs = true; } if ($(file).filter(".*\\.plugin?$").get(0) != null) { rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, file.toURI().toString(), file.toURI())); hasJARs = true; } } // If we have JARs, we already added them if (hasJARs) return rval; // If we have no JARs, this is probably a classpath, in this case warn that // the method is not recommended if (toplevel.toString().contains("/bin/") || toplevel.toString().contains("class")) { System.err.println("Adding plugins in 'raw' classpaths, such as 'bin/' or 'classes/' is not recommended. Please use classpath://* instead (the video is a bit outdated in this respect)."); } rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, toplevel.toString(), toplevel)); return rval; } // If this is directly a JAR, add this if (startPoint.isFile() && startPoint.getAbsolutePath().endsWith(".jar")) { rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, toplevel.toString(), toplevel)); return rval; } return rval; } /** * Gets all contributing classpaths for a given class by traversing all parent-classloader. * * @since 1.1 * @param clazz The class to get all classloaders for. * @return A list of all contributing classloaders. */ protected List<String> allClasspathsFor(Class<?> clazz) { final DiagnosisChannelUtil<String> channel = new DiagnosisChannelUtil<String>(this.pluginManager.getPlugin(Diagnosis.class).channel(SpawnerTracer.class)); final List<String> rval = $.list(); channel.status("allclasspathsfor/start", "class", clazz.toString()); // In case JSPF has been loaded from an URL class loader as well (Issue #29) URLClassLoader ourloader = $(clazz.getClassLoader()).cast(URLClassLoader.class).get(0); while (ourloader != null) { // Removed check for system classloader, might need its elements as well channel.status("allclasspathsfor/urlloader"); rval.addAll($(ourloader.getURLs()).file().forEach(new F1<File, String>() { @Override public String f(File arg0) { channel.status("allclasspathsfor/urlloader/path", "path", arg0); return arg0.getAbsolutePath(); } }).list()); ourloader = $(ourloader.getParent()).cast(URLClassLoader.class).get(0); } channel.status("allclasspathsfor/end"); return $(rval).unique().list(); } /** * Finds all locations inside the current classpath. * @param options * * @return A list of all locations in the current classpath. */ @SuppressWarnings("boxing") public Collection<AbstractClassPathLocation> findInCurrentClassPath(AddPluginsFromOption[] options) { final DiagnosisChannelUtil<String> channel = new DiagnosisChannelUtil<String>(this.pluginManager.getPlugin(Diagnosis.class).channel(SpawnerTracer.class)); channel.status("findinclasspath/start"); final Collection<AbstractClassPathLocation> rval = new ArrayList<AbstractClassPathLocation>(); // Get our current classpath (TODO: Better get this using // ClassLoader.getSystemClassLoader()?) final boolean filter = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration()).getBoolean(PluginManager.class, "classpath.filter.default.enabled", true); final String blacklist[] = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration()).getString(PluginManager.class, "classpath.filter.default.pattern", "/jre/lib/;/jdk/lib/;/lib/rt.jar").split(";"); final String pathSep = System.getProperty("path.separator"); final String classpath = System.getProperty("java.class.path"); final List<URL> toFilter = new ArrayList<URL>(); // Get the starting point final Class<?> startPoint = $(options).get(OptionSearchAround.class, new OptionSearchAround(getClass())).getClazz(); // Get all classpaths List<String> classpaths = $(classpath.split(pathSep)).list(); classpaths.addAll(allClasspathsFor(startPoint)); classpaths = $(classpaths).unique().list(); // Check if we should filter, if yes, get topmost classloader so we know // what to filter out if (filter) { channel.status("findinclasspath/filter"); ClassLoader loader = ClassLoader.getSystemClassLoader(); while (loader != null && loader.getParent() != null) loader = loader.getParent(); // Get 'blacklist' and add it to our filterlist if (loader != null && loader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) loader).getURLs(); for (URL url : urls) { channel.status("findinclasspath/filter/add", "item", url); toFilter.add(url); } } } // Process all possible locations for (String string : classpaths) { if(string == null) continue; try { final URL url = new File(string).toURI().toURL(); channel.status("findinclasspath/add", "raw", string, "url", url); // Check if the url was already contained if (toFilter.contains(url) || blacklisted(blacklist, url)) { channel.status("findinclasspath/add/blacklisted", "raw", string, "url", url); continue; } // And eventually add the location rval.add(AbstractClassPathLocation.newClasspathLocation(this.cache, "#classpath", new File(string).toURI())); } catch (MalformedURLException e) { e.printStackTrace(); } } return rval; } /** * Checks if the given URL is blacklisted * * @param blacklist * @param url * @return */ private boolean blacklisted(String[] blacklist, URL url) { // Default sanity check if (blacklist == null || blacklist.length == 0 || blacklist[0].length() == 0) return false; // Go thorugh blacklist for (String string : blacklist) { if (url.toString().contains(string)) return true; } return false; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/locator/ClassPathLocator.java
Java
bsd
11,036
/* * ClasspathLoaction.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.classpath.locator; import static net.jcores.jre.CoreKeeper.$; import java.io.InputStream; import java.net.URI; import java.util.Collection; import java.util.logging.Logger; import net.xeoh.plugins.base.impl.classpath.cache.JARCache; import net.xeoh.plugins.base.impl.classpath.cache.JARCache.JARInformation; import net.xeoh.plugins.base.impl.classpath.locator.locations.FileClasspathLocation; import net.xeoh.plugins.base.impl.classpath.locator.locations.JARClasspathLocation; import net.xeoh.plugins.base.impl.classpath.locator.locations.MultiPluginClasspathLocation; /** * Location of a classpath (i.e., either a JAR file or a toplevel directory) * * TODO: Constrict two subclasses, JARClassPathLocation and FileClassPathLocation * * @author Ralf Biedert * */ public abstract class AbstractClassPathLocation { /** * * Type of this location * * @author Ralf Biedert * */ public enum LocationType { /** Is a JAR */ JAR, /** Is an ordinary dir */ DIRECTORY, /** A multiplugin*/ MULTI_PLUGIN } /** */ protected final Logger logger = Logger.getLogger(this.getClass().getName()); /** Location of this item */ protected final URI location; /** ID of this entry */ protected final String realm; /** */ protected final JARCache cache; /** Information for this location entry */ protected JARInformation cacheEntry = null; /** * @param cache * @param realm * @param location */ protected AbstractClassPathLocation(JARCache cache, String realm, URI location) { this.cache = cache; this.realm = realm; this.location = location; } /** * Constructs a new ClassPathLocation which handles all classes within. * * @param cache The cache to lookup the entrie's content. * @param realm The real name. * @param location URI location of the given classpath. * @return The constructed location. */ public static AbstractClassPathLocation newClasspathLocation(JARCache cache, String realm, URI location) { if ($(location).filter(".*\\.plugin[/]$").get(0) != null) return new MultiPluginClasspathLocation(cache, realm, location); if (location.toString().endsWith(".jar")) return new JARClasspathLocation(cache, realm, location); return new FileClasspathLocation(cache, realm, location); } /** * Returns the top level classpath location. This is *NOT* equal to the * the classpath-entries this location provides. Especially multi-plugins * may consist of a number of JARs required for proper class resolution. * * @return The top level location */ public URI getToplevelLocation() { return this.location; } /** * Gets all classpath entries required to properly load plugins. Add them * to a class loader. * * @return the location */ public URI[] getClasspathLocations() { return new URI[] { this.location }; } /** * @return the location */ public String getRealm() { return this.realm; } /** * Get the type of this entry * * @return . */ public abstract LocationType getType(); /** * Lists the name of all classes inside this classpath element * * @return . */ public abstract Collection<String> listToplevelClassNames(); /** * Lists all entries in this location, no matter if class or file (excluding directories) * * @return . */ public abstract Collection<String> listAllEntries(); /** * Creates an input stream for the requested item * * @param entry * * @return . */ public abstract InputStream getInputStream(String entry); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/classpath/locator/AbstractClassPathLocation.java
Java
bsd
5,616
/* * PluginConfigurationImpl.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl; import java.util.Properties; import java.util.logging.Logger; import net.xeoh.plugins.base.PluginConfiguration; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.meta.Author; import net.xeoh.plugins.base.annotations.meta.Version; /** * * * @author Ralf Biedert * */ @Author(name = "Ralf Biedert") @PluginImplementation @Version(version = Version.UNIT_MAJOR) public class PluginConfigurationImpl implements PluginConfiguration { /** Actual properties object we use */ final Properties configuration; /** */ final Logger logger = Logger.getLogger(this.getClass().getName()); /** * @param initialProperties */ protected PluginConfigurationImpl(final Properties initialProperties) { this.configuration = initialProperties; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginConfiguration#getConfiguration(java.lang.Class, * java.lang.String) */ public synchronized String getConfiguration(final Class<?> root, final String subkey) { final String key = getKey(root, subkey); final String value = this.configuration.getProperty(key); this.logger.fine("Returning '" + value + "' for " + "'" + key + "'"); return value; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginConfiguration#setConfiguration(java.lang.Class, * java.lang.String, java.lang.String) */ public synchronized void setConfiguration(final Class<?> root, final String subkey, final String value) { final String key = getKey(root, subkey); this.logger.fine("Setting '" + value + "' for " + "'" + key + "'"); this.configuration.setProperty(key, value); } /** * Assemble a key for a given root class and subkey string * * @param root Root (may be null) * @param subkey (subkey to use) * @return The fully assembled key. */ private String getKey(final Class<?> root, final String subkey) { String prefix = ""; if (root != null) { prefix = root.getName() + "."; } this.logger.finer("Assembled key '" + prefix + subkey + "'"); return prefix + subkey; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/PluginConfigurationImpl.java
Java
bsd
3,923
/* * Benchmarker.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl.util; import java.util.HashMap; import java.util.Map; /** * @author rb * */ public class Benchmarker { static Map<Integer, Long> times = new HashMap<Integer, Long>(); /** * @param id * */ @SuppressWarnings("boxing") public static void start(int id) { times.put(id, System.nanoTime()); } /** * @param id * @param label */ @SuppressWarnings("boxing") public static void stop(int id, String label) { long stop = System.nanoTime(); long d = stop - times.get(id); System.out.println(label + ": " + (d / 1000)); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/util/Benchmarker.java
Java
bsd
2,217
/* * PluginManagerFactory.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.impl; import java.util.Properties; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginConfiguration; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.util.JSPFProperties; import net.xeoh.plugins.base.util.PluginManagerUtil; /** * Factory class to create new {@link PluginManager}. This is your entry and starting point for * using JSPF. Create a new manager by calling one of the enclosed methods.<br/><br/> * * There should be no need to access this class (or call any of its methods) more than once * during the lifetime of your application. * * @author Ralf Biedert */ public class PluginManagerFactory { /** This class will not be instantiated. */ private PluginManagerFactory() { // } /** * Creates a new {@link PluginManager}, no user configuration is used. The manager will * be (almost) empty, i.e., containing no {@link Plugin}s except some internal ones.<br/><br/> * * The next thing you should probably do is adding your own plugins by calling * <code>addPluginsFrom()</code>. * * @return A fresh plugin manager. */ public static PluginManager createPluginManager() { return createPluginManager(new Properties()); } /** * Creates a new {@link PluginManager} which will be wrapped in a {@link PluginManagerUtil} object, * no user configuration is used. The manager will be (almost) empty, i.e., containing no {@link Plugin}s * except some internal ones.<br/><br/> * * The next thing you should probably do is adding your own plugins by calling * <code>addPluginsFrom()</code>. * * @since 1.0.3 * @return A freshly wrapped plugin manager. */ public static PluginManagerUtil createPluginManagerX() { return new PluginManagerUtil(createPluginManager()); } /** * Creates a new {@link PluginManager} with a supplied user configuration. The user configuration * can be obtained by using the {@link PluginConfiguration}. <br/><br/> * * The next thing you should probably do is adding your own plugins by calling * <code>addPluginsFrom()</code>.<br/><br/> * * In order to assist debugging, you can set one of {@link JSPFProperties}'s preferences by * calling: <code>setProperty(PluginManager.class, "logging.level", "INFO")</code> (INFO * can be replaced by OFF, WARNING, INFO, FINE, FINER or FINEST respectively. * * @param initialProperties Initial properties to use. * * @return A fresh manager with the supplied configuration. */ public static PluginManager createPluginManager(final Properties initialProperties) { // Setup logging if (initialProperties.containsKey("net.xeoh.plugins.base.PluginManager.logging.level")) { final String level = initialProperties.getProperty("net.xeoh.plugins.base.PluginManager.logging.level"); setLogLevel(Level.parse(level)); } // Lower the JMDNS level (TODO: Why doen't this work?) Logger.getLogger("javax.jmdns").setLevel(Level.OFF); return new PluginManagerImpl(initialProperties); } /** * Creates a new {@link PluginManager}, wrapped in a {@link PluginManagerUtil} object, with a supplied user * configuration. The user configuration can be obtained by using the {@link PluginConfiguration}. <br/><br/> * * The next thing you should probably do is adding your own plugins by calling * <code>addPluginsFrom()</code>.<br/><br/> * * In order to assist debugging, you can set one of {@link JSPFProperties}'s preferences by * calling: <code>setProperty(PluginManager.class, "logging.level", "INFO")</code> (INFO * can be replaced by OFF, WARNING, INFO, FINE, FINER or FINEST respectively. * * @param initialProperties Initial properties to use. * @since 1.0.3 * @return A freshly wrapped manager with the supplied configuration. */ public static PluginManagerUtil createPluginManagerX(final Properties initialProperties) { return new PluginManagerUtil(createPluginManager(initialProperties)); } /** * Sets logging to the specified level. */ private static void setLogLevel(Level level) { Logger.getLogger("").setLevel(level); Handler[] handlers = Logger.getLogger("").getHandlers(); for (Handler handler : handlers) { handler.setLevel(level); } } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/impl/PluginManagerFactory.java
Java
bsd
6,272
/* * Plugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.util.PluginUtil; /** * The base class of all plugins. Plugin creation is fairly simple: <br> * <br> * 1. Create a new top level package for your plugin, e.g., * <code>com.company.plugins.imagedb</code> in case of an image database.<br> * <br> * 2. Create an interface within that package. The interface should (well, must) * extend Plugin. Add all the methods you like, for example <code>listImages()</code><br> * <br> * 3. Create an impl sub-package with the plugin package, in our case this is * <code>com.company.plugins.imagedb.impl</code>. The <i>impl</i>-name is not * required, but should be kept as a convention. In the future there might exist * tools that depend on it, or work better with it. If you have multiple implementations, * create several sub-packages within the impl folder. In our example case, this * could be the implementations <code>impl.simple</code> (for a simple test * implementation), <code>impl.distributed</code> (for our distributed image storage) * and <code>impl.compatiblity</code> (for the old DB API)<br> * <br> * 4. Implement your interfaces, i.e., create a class / classes inside the * respective <code>impl</code> folder.<br> * <br> * 5. Add the &#064;{@link PluginImplementation} annotation to your implemented * class(es).<br> * <br> * 6. You're done. Technically your plugin is ready now to use. It can be compiled * now (Eclipse will probably have done this for you already). You might want to * have a look at the {@link PluginManager} documentation to see how you can load and retrieve * it (see <code>addPluginsFrom()</code> and <code>getPlugin()</code>).<br> * <br> * NOTE: You should <b>ensure that all implementations of your plugins are thread * safe</b>! Expect your functions to be called any time in any state. * * @author Ralf Biedert * @see PluginManager * @see PluginUtil */ public interface Plugin { }
100json-jspf
modules/core/src/net/xeoh/plugins/base/Plugin.java
Java
bsd
3,588
/* * PluginManager.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base; import java.net.URI; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; import net.xeoh.plugins.base.impl.PluginManagerFactory; import net.xeoh.plugins.base.options.AddPluginsFromOption; import net.xeoh.plugins.base.options.GetPluginOption; import net.xeoh.plugins.base.util.JSPFProperties; import net.xeoh.plugins.base.util.PluginManagerUtil; import net.xeoh.plugins.base.util.uri.ClassURI; import net.xeoh.plugins.informationbroker.InformationBroker; /** * This is your entry point to and the heart of JSPF. The plugin manager keeps track of all * registed plugins and gives you methods to add and query them. You cannot instantiate the * PluginManager directly, instead you<br/><br/> * * <center>create this class the first time by a call to {@link PluginManagerFactory}<code>.createPluginManager()</code></center> * * <br/><br/> * Afterwards you probably want to add some of your own plugins. During the lifetime of your * application there should only be one PluginManager. The PluginManager does not have to be * passed to the inside of your plugins, instead, they can request it by the &#064;{@link InjectPlugin} * annotation (i.e, create a field '<code>public PluginManager manager</code>' and add the * annotation).<br/><br/> * * There are also a number of default plugins you can retrieve right away (without calling * <code>addPluginsFrom()</code> explicitly.). These are:<br/><br/> * * <ul> * <li>{@link PluginConfiguration} - enables you to get and set config options</li> * <li>{@link PluginInformation} - provides meta information about plugins</li> * <li>{@link InformationBroker} - supports information exchange between plugins while keeping them decoupled</li> * </ul><br/> * * In addition (and after loading the specific plugin) you can also retrieve a RemoteAPI. * <br/><br/> * * The following configuration sub-keys are usually known for this class (see {@link PluginConfiguration}, keys must be set * <em>before</em> createPluginManager() is being called, i.e., set in the {@link JSPFProperties} object!):<br/><br/> * * <ul> * <li><b>cache.enabled</b> - Specifies if the known plugins should be cached. Specify either {true, false}.</li> * <li><b>cache.mode</b> - If we should use strong caching (slow but more accurate) or weak (much faster). Specify either {stong, weak}. </li> * <li><b>cache.file</b> - Cache file to use. Specify any relative or absolute file path, file will be created / overwritten.</li> * <li><b>classpath.filter.default.enabled</b> - If Java default classpaths (e.g., jre/lib/*) should be filtered. Specify either {true, false}. Might not work on all platforms as expected.</li> * <li><b>classpath.filter.default.pattern</b> - Specify what to filter in addition to default classpaths. Specify a list of ';' separated tokens, e.g., "jdk/lib;jre/lib". Will be matched against URL representations, so all \\ will be converted to / (and ' ' might become %20, ...).</li> * <li><b>logging.level</b> - Either {OFF, FINEST, FINER, FINE, INFO, WARNING, ALL}. Specifies what to log on the console. </li> * </ul><br/> * @see PluginManagerUtil * * @author Ralf Biedert */ public interface PluginManager extends Plugin { /** * Requests the plugin manager to add plugins from a given path. The path can be * either a folder-like item where existing .zip and .jar files are trying to be * added, as well as existing class files. The path can also be a singular .zip or * .jar which is added as well.<br><br> * * The manager will search for classes having the &#064;{@link PluginImplementation} * annotation and evaluate this annotation. Thereafter the plugin will be instantiated.<br><br> * * Currently supported are classpath-folders (containing no .JAR files), plugin folders * (containing .JAR files or multiplugins), single plugins and HTTP locations. Example * calls look like this:<br/><br/> * * <ul> * <li><code>addPluginsFrom(new URI("classpath://*"))</code> (add all plugins within the current classpath).</li> * <li><code>addPluginsFrom(new File("plugins/").toURI())</code> (all plugins from the given folder, scanning for JARs and <a href="http://code.google.com/p/jspf/wiki/FAQ">multi-plugins</a>).</li> * <li><code>addPluginsFrom(new File("plugin.jar").toURI())</code> (the given plugin directly, no scanning is being done).</li> * <li><code>addPluginsFrom(new URI("http://sample.com/plugin.jar"))</code> (downloads and adds the given plugin, use with caution).</li> * <li><code>addPluginsFrom(new ClassURI(ServiceImpl.class).toURI())</code> (adds the specific plugin implementation already present in the classpath; very uncomfortable, very fast).</li> * </ul> * * * @see ClassURI * * @param url The URL to add from. If this is "classpath://*"; the plugin manager will * load all plugins within it's own classpath. * * @param options A set of options supported. Please see the individual options for more * details. * @return This plugin manager. */ public PluginManager addPluginsFrom(URI url, AddPluginsFromOption... options); /** * Returns the next best plugin for the requested interface. The way the plugin is being * selected is undefined, you should assume that a random plugin implementing the requested * interface is chosen. <br><br> * * This method is more powerful than it looks like on first sight, especially in conjunction * with the right {@link GetPluginOption}. * * @param <P> Type of the plugin / return value. * * @param plugin The interface to request. The given class <b>must</b> derive from Plugin. You <b>MUST NOT</b> pass * implementation classes. Only interface classes are accepted (i.e. <code>getPlugin(Service.class)</code> * is fine, while <code>getPlugin(ServiceImpl.class)</code> isn't. * @param options A set of options for the request. * * @return A randomly chosen Object that implements <code>plugin</code>. */ public <P extends Plugin> P getPlugin(Class<P> plugin, GetPluginOption... options); /** * Tells the plugin manager to shut down. This may be useful in cases where you want all * created plugins to be destroyed and shutdown hooks called. Normally this happens during * application termination automatically, but sometimes you create a 2nd instance in the same * machine and want the first one to close properly. * * All invocations after the first one have no effect. */ public void shutdown(); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/PluginManager.java
Java
bsd
8,351
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Methods marked with &#064;Timer will called periodically from a timer. The method * may return a boolean value. If this value is true, the timer will be canceled. For * example, to specify that after the plugin's creation a specific method should be * called from a timer, you would write:<br/><br/> * * <code> * &#064;Timer<br/> * public void ping() { ... } * </code><br/><br/> * * All timers are terminated upon <code>PluginManager.shutdown()</code>. * @author Ralf Biedert * @see Thread */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Timer { /** * Type of the timer. * * @author Ralf Biedert * */ public static enum TimerType { /** * Delay based timer */ DELAY_BASED, /** * Rate based timer */ RATE_BASED } /** * Period of the timer. * * @return . */ long period(); /** * When to start the timer. * * @return . */ long startupDelay() default 0; /** * Specifies the type of this timer. * * @return . */ TimerType timerType() default TimerType.DELAY_BASED; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/Timer.java
Java
bsd
2,978
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.events.Init; import net.xeoh.plugins.base.options.getplugin.OptionCapabilities; /** * Methods marked with Capabilities are queried by PluginInformation. The method MUST be * public and it MUST return a String[] array. If several methods are annotated it is * undefined which one will be called. <br/><br/> * * As soon as the &#064;{@link Init} annotation is processed the capabilities function must be * operational. Use this function for example to tell which file extensions you can handle * or the (limited number of) host you can connect to. While this method can return different * values on every call it is considered "bad taste" if latter calls return anything less * than the previous calls.<br/><br/> * * For example, if you want a plugin to indicate that it can handle a set of languages, * you could write:<br/><br/> * * <code> * &#064;Capabilities<br/> * public String[] capabilities() { return new String[] {"language:english", "language:german"}; } * </code><br/><br/> * * Later on, you can use {@link OptionCapabilities} within the {@link PluginManager}'s <code>getPlugin()</code> method to * retrieve all plugins providing certain capabilities. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Capabilities { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/Capabilities.java
Java
bsd
3,153
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.events; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.annotations.Timer; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; /** * Use this annotation to mark functions which should be called on initialization. You * can be sure that at this phase all required plugins (see &#064;{@link InjectPlugin}), * that have not been marked as optional, are available. So, for * example, if you want a method to be called when the plugin is ready, you could * write:<br/><br/> * * <code> * &#064;Init<br/> * public void startup() { ... } * </code><br/><br/> * * This method usually does not have to return a value (return type <code>void</code>). * It may, however, return as well a boolean. If it then returns <code>false</code>, initialization of * this plugin will be canceled, no &#064;{@link net.xeoh.plugins.base.annotations.Thread} or &#064;{@link Timer} will be started, no other * &#064;{@link Init} methods will be called and the plugin will not be touched any more. <br/><br/> * * Note: Methods annotated with this have to be PUBLIC, otherwise they won't be found. * * @author Ralf Biedert * @see Shutdown */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Init { // Just a marker interface }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/events/Init.java
Java
bsd
3,021
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package net.xeoh.plugins.base.annotations.events; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.annotations.injections.InjectPlugin; /** * * Called when a plugin of the given interface was registered. For example, if you want to * be called when a new Plugin of the type <code>StorageService</code> was added, you could * write:<br/><br/> * * <code> * &#064;PluginLoaded<br/> * public void checkPlugin(StorageService service) { ... } * </code><br/><br/> * * This method is especially useful in the case of plugins added <i>in the future</i>. Sometimes * you rely on a plugin which is not there in the early stage of your application lifetime. If you * depended on it with {@link InjectPlugin}, you either would not see it, or your own plugin would * be suspended until it was loaded. Using the <code>PluginLoaded</code> you can start up anyway * and wait for it in this callback-like mechanism.<br/><br/> * * Note: Methods annotated with this have to be PUBLIC, otherwise they won't be found. * * @author Ralf Biedert */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface PluginLoaded { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/events/PluginLoaded.java
Java
bsd
2,858
/** * Annoations related to plugin events. * * @since 1.0 */ package net.xeoh.plugins.base.annotations.events;
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/events/package-info.java
Java
bsd
118
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.events; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.PluginManager; /** * Methods marked with this interface will be called on the shutdown of the {@link PluginManager}. * Plugins *must not* assume anything about the status of other plugins, even if they depend on them; * everyone dies alone. Just free all resources you allocated yourself, and do it fast. For * example, if you want a method to be called upon the Manager's shutdown, you could * write:<br/><br/> * * <code> * &#064;Shutdown<br/> * public void bye() { ... } * </code><br/><br/> * * * Note: Methods annotated with this have to be PUBLIC, otherwise they won't be found. * * @author Ralf Biedert * @see Init * */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Shutdown { // Just a marker interface }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/events/Shutdown.java
Java
bsd
2,574
/** * Core annotations for plugins. Please note that all of these annotations * only work directly inside the plugin class and NOT in any of its embedded * objects. * * @since 1.0 */ package net.xeoh.plugins.base.annotations;
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/package-info.java
Java
bsd
237
/* * InitPlugin.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Methods marked with &#064;Thread will be called from a newly created thread. For example, * to specify that after the plugin's creation a specific method should be called from a * dedicated thread, you would write:<br/><br/> * * <code> * &#064;Thread<br/> * public void background() { ... } * </code><br/><br/> * * All threads are terminated upon <code>PluginManager.shutdown()</code>. * * * @author Ralf Biedert * @see Timer */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Thread { /** * If the thread should be daemonic. * * @return True if the VM may exit with the thread still running.. */ boolean isDaemonic() default true; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/Thread.java
Java
bsd
2,485
/* * ConfigurationFile.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.configuration; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.prefs.Preferences; /** * Specifies a configuration file relative to the given plugin. Its content will be added * to the global configuration (@see PluginConfiguration). For example, to specify that the * configuration file <code>config.properties</code> in the same package as the plugin should * be added the the configuration, write<br/><br/> * * <code> * &#064;PluginImplementation<br/> * &#064;ConfigurationFile(file="config.properties")<br/> * public class ServiceImpl implements Service { ... } * </code><br/><br/> * * The configuration file is a standard Java preferences file. * * @author Ralf Biedert * @see Preferences */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ConfigurationFile { /** * The configuration File to load, relative to the package root. Note that the file * will only be added to the global configuration if the plugin is not disabled. * * @return Relative path to the configuration file. */ String file() default ""; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/configuration/ConfigurationFile.java
Java
bsd
2,848
/* * IsDisabled.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.configuration; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.annotations.PluginImplementation; /** * Marks the given plugin is diabled and will not be spawned. Nor will its configuration * be added to the global configuration. Use this to quickly disable a plugin for testing * purposes. For example, to specify that a plugin should be disabled, write<br/><br/> * * <code> * &#064;IsDisabled<br/> * &#064;PluginImplementation<br/> * public class ServiceImpl implements Service { ... } * </code><br/><br/> * * Might be removed in the future (as removing {@link PluginImplementation} has the same * effect). * * @author Ralf Biedert */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface IsDisabled { // Marker only }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/configuration/IsDisabled.java
Java
bsd
2,520
/** * Annotations related to plugin loading. * * @since 1.0 */ package net.xeoh.plugins.base.annotations.configuration;
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/configuration/package-info.java
Java
bsd
127
/* * AutoInject.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.injections; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.jcores.jre.annotations.Beta; import net.xeoh.plugins.base.PluginManager; /** * Inject all possible instance implementing into this plugin. The same as if you annotated * each variable and method with {@link InjectPlugin}.<br/><br/> * * <code> * &#064;AutoInject<br/> * &#064;PluginImplementation<br/> * public class MyPlugin ...; * </code><br/><br/> * * Please note: The annotated variable has to be <b>public</b>! * * @author Ralf Biedert * @see PluginManager * */ @Beta @Target(value = { ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface AutoInject { }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/injections/AutoInject.java
Java
bsd
2,381
/* * InjectPluginManager.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.injections; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.Capabilities; /** * Inject some instance implementing the given plugin interface. If the plugin is not available * at spawntime (and the dependency is marked as optional), null will be inserted. If the plugin * was not marked as optional this plugin will not be spawned. For example, * to specify that the PluginManager should be injected into the plugin, you would write:<br/><br/> * * <code> * &#064;InjectPlugin<br/> * public PluginManager pluginManager; * </code><br/><br/> * * Another example. To specify that a language service for Swahili should be injected in case it * is there and null in case it is not, you could write:<br/><br/> * * <code> * &#064;InjectPlugin(requiredCapabilities = {"language:swahili"}, isOptional=true)<br/> * public LanguageService service; * </code><br/><br/> * * This ensures that the returned plugin, if it is there, is of type <code>LanguageService</code> and has the * capability (see {@link Capabilities}) of processing Swahili. If <code>isOptional</code> is <code>false</code> * or omitted then it is even ensured that this plugin will not be spawned unless the given service is available. * <br/><br/> * * Please note: The annotated variable has to be <b>public</b>! * * @author Ralf Biedert * @see PluginManager * */ @Target(value = { ElementType.FIELD, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) public @interface InjectPlugin { /** * All the capabilities the plugins must have in order to be instanciated * * @return Number of classes that the plugin explicitly depends on. */ String[] requiredCapabilities() default {}; /** * If set to true, the PluginManager may instanciate the plugin anyway, even if the * other plugin is not present yet. * * @return . */ boolean isOptional() default false; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/injections/InjectPlugin.java
Java
bsd
3,734
/** * Annotations related to injecting variables. * * @since 1.0 */ package net.xeoh.plugins.base.annotations.injections;
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/injections/package-info.java
Java
bsd
129
/* * Version.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.PluginInformation; /** * Version of the given plugin. For example, to specify that a given * plugin is version 1.3.2, write:<br/><br/> * * <code> * &#064;Version(version = 10302)<br/> * &#064;PluginImplementation<br/> * public class ServiceImpl implements Service { ... } * </code><br/><br/> * * This information can be queried using the {@link PluginInformation} plugin. * * @author Ralf Biedert * @see PluginInformation.Information */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Version { /** Major version */ public final static int UNIT_MAJOR = 10000; /** Minor version */ public final static int UNIT_MINOR = 100; /** Release version */ public final static int UNIT_RELEASE = 1; /** * Version of this plugin. For example, a version of 10000 should be read as 1.00.00 * * @return . */ int version() default 1 * UNIT_MAJOR + 0 * UNIT_MINOR + 0 * UNIT_RELEASE; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/meta/Version.java
Java
bsd
2,778
/** * Annotations related to plugin information. * * @since 1.0 */ package net.xeoh.plugins.base.annotations.meta;
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/meta/package-info.java
Java
bsd
122
/* * Author.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.Option; /** * Specifies the given method does accept and evaluate a given * parameter.<br/><br/> * * Work in progress, annotation will change! Also, it is not being * evaluated at the moment. * * * @author Ralf Biedert */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface RecognizesOption { /** * Options understood * * @return . */ Class<? extends Option> option(); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/meta/RecognizesOption.java
Java
bsd
2,243
/* * Version.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker interface to signal that JSPF may hot swap the component behind the scenes * without causing trouble to existing components.<br/><br/> * * Not functional right now!<br/><br/> * * TODO: Does it make really sense / do we *really* want such a functionality? It * complicates many things and is only relevant to a small number of projects (which * are likely better off with OSGi and the like) * * @author Ralf Biedert */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Stateless { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/meta/Stateless.java
Java
bsd
2,322
/* * Author.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.PluginInformation; /** * Specifies an author of the given plugin. For example, to specify that a given * plugin was written by John Doe, write:<br/><br/> * * <code> * &#064;Author(name = "John Doe")<br/> * &#064;PluginImplementation<br/> * public class ServiceImpl implements Service { ... } * </code><br/><br/> * * This information can be queried using the {@link PluginInformation} plugin. * * @author Ralf Biedert * @see PluginInformation.Information */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Author { /** * Author of this plugin. * * @return . */ String name() default "Unknown Author"; }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/meta/Author.java
Java
bsd
2,482
/* * PluginInstance.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import net.xeoh.plugins.base.Plugin; /** * This annotation can be used to mark plugin instances which should be initialized at * runtime. If you don't annotate your plugin with this annotation, nothing will happen. * For example, to specify that a specific class should be treated as a plugin you would * write:<br/><br/> * * <code> * &#064;PluginImplementation<br/> * public class ServiceImpl implements Service { ... } * </code><br/><br/> * * In this case, <code>Service</code> has to extend {@link Plugin}. * * @author Ralf Biedert */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface PluginImplementation { // }
100json-jspf
modules/core/src/net/xeoh/plugins/base/annotations/PluginImplementation.java
Java
bsd
2,443
package net.xeoh.plugins.base.diagnosis.channels.tracing; /* * ClassPathTracer.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ import java.io.Serializable; import java.util.Map; import net.xeoh.plugins.diagnosis.local.DiagnosisChannelID; /** * Traces general messages related to class path issues. * * @author Ralf Biedert */ public class ClassPathTracer extends DiagnosisChannelID<String> { /* (non-Javadoc) * @see net.xeoh.plugins.diagnosis.local.DiagnosisChannelID#toUserRepresentation(java.io.Serializable, java.util.Map) */ @Override public String toUserRepresentation(String t, Map<String, Serializable> args) { // TODO Auto-generated method stub return super.toUserRepresentation(t, args); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/diagnosis/channels/tracing/ClassPathTracer.java
Java
bsd
2,249
/* * AddPlugins.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.diagnosis.channels.tracing; import java.io.Serializable; import java.util.Map; import net.xeoh.plugins.diagnosis.local.DiagnosisChannelID; /** * Traces general messages for the Spawner. * * @author Ralf Biedert */ public class SpawnerTracer extends DiagnosisChannelID<String> { /* (non-Javadoc) * @see net.xeoh.plugins.diagnosis.local.DiagnosisChannelID#toUserRepresentation(java.io.Serializable, java.util.Map) */ @Override public String toUserRepresentation(String t, Map<String, Serializable> args) { // TODO Auto-generated method stub return super.toUserRepresentation(t, args); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/diagnosis/channels/tracing/SpawnerTracer.java
Java
bsd
2,229
/* * AddPlugins.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.diagnosis.channels.tracing; import java.io.Serializable; import java.util.Map; import net.xeoh.plugins.diagnosis.local.DiagnosisChannelID; /** * Traces general messages for the plugin manager. * * @author Ralf Biedert */ public class PluginManagerTracer extends DiagnosisChannelID<String> { /* (non-Javadoc) * @see net.xeoh.plugins.diagnosis.local.DiagnosisChannelID#toUserRepresentation(java.io.Serializable, java.util.Map) */ @Override public String toUserRepresentation(String t, Map<String, Serializable> args) { // TODO Auto-generated method stub return super.toUserRepresentation(t, args); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/diagnosis/channels/tracing/PluginManagerTracer.java
Java
bsd
2,242
/* * URIUtil.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util.uri; import java.net.URI; /** * Returns an URI for something. * * @author Ralf Biedert */ public abstract class URIUtil { /** * The URI. * * @return The URI. */ public abstract URI toURI(); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/uri/URIUtil.java
Java
bsd
1,824
/** * Utilities for URIs. * * @since 1.0 */ package net.xeoh.plugins.base.util.uri;
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/uri/package-info.java
Java
bsd
92
/* * ClassURI.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util.uri; import java.net.URI; import java.net.URISyntaxException; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginManager; /** * Convenience method to load plugins from the classpath * * @author Ralf Biedert * @see PluginManager */ public class ClassURI extends URIUtil { /** Means we should add all plugins we have in our classpath */ public static final URI CLASSPATH = URI.create("classpath://*"); /** * Specifies a pattern to add from the current classpath. * * @param pattern For example net.xeoh.myplugins.** * * @return The generated pattern. */ public static final URI CLASSPATH(String pattern) { return URI.create("classpath://" + pattern); } /** * Specifies that the given plugin should be added. * * @param clazz The plugin to add * @return The generated URI pattern for the plugin. */ public static final URI PLUGIN(Class<? extends Plugin> clazz) { return new ClassURI(clazz).toURI(); } /** The class we wrapped */ private final Class<? extends Plugin> clazz; /** * Construct a new class URI for the given class. * * @param clazz The class to wrap. */ public ClassURI(Class<? extends Plugin> clazz) { if (clazz.isInterface()) throw new IllegalArgumentException("The paramter must be a concrete plugin class, not a plugin interface."); this.clazz = clazz; } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.util.uri.URIUtil#toURI() */ @Override public URI toURI() { try { return new URI("classpath://" + this.clazz.getCanonicalName()); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/uri/ClassURI.java
Java
bsd
3,436
/* * PluginUtil.java * * Copyright (c) 2010, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import net.xeoh.plugins.base.Plugin; /** * A set of inspection methods for an existing plugin. Should only be required * and used internally. * * @author Ralf Biedert */ public class PluginUtil extends VanillaPluginUtil<Plugin> { /** * The plugin to wrap. * * @param plugin */ public PluginUtil(Plugin plugin) { super(plugin); } /** * Lists all primary interfaces. * * @return A list of primary interfaces.> */ @SuppressWarnings({ "unchecked" }) public Collection<Class<? extends Plugin>> getPrimaryInterfaces() { final Collection<Class<? extends Plugin>> rval = getPluginInterfaces(); List<Class<?>> candidates = new ArrayList<Class<?>>(); // Filter all redundant interfaces int lastSize = 0; do { lastSize = rval.size(); // Create a copy of all our plugins candidates = new ArrayList<Class<?>>(rval); rval.clear(); // For every plugin ... for (Class<?> class2 : candidates) { // ... compare it with every other ... boolean hasSuper = false; for (Class<?> class3 : candidates) { // ... and see if it can be assigned from another one that is not the same, if that // is the case, it's useless, if not, we keep it. if (class2.isAssignableFrom(class3) && class2 != class3) { hasSuper = true; } } if (!hasSuper && !rval.contains(class2)) rval.add((Class<? extends Plugin>) class2); } } while (lastSize != rval.size()); return rval; } /** * Lists all toplevel plugin interfaces * * @return The list of all plugin interfaces. */ @SuppressWarnings({ "unchecked" }) public Collection<Class<? extends Plugin>> getPluginInterfaces() { final Collection<Class<? extends Plugin>> rval = new ArrayList<Class<? extends Plugin>>(); List<Class<?>> candidates = new ArrayList<Class<?>>(); Class<?> current = this.object.getClass(); // Check the plugin class and all its parents what interfaces they contain while (current != null && !Object.class.equals(current)) { final List<Class<?>> c = Arrays.asList(current.getInterfaces()); for (Class<?> class1 : c) { if (candidates.contains(class1)) continue; candidates.add(class1); } current = current.getSuperclass(); } // Filter first round (only plugin interfaces should be left) for (Class<?> class1 : candidates) { if (!Plugin.class.isAssignableFrom(class1)) continue; rval.add((Class<? extends Plugin>) class1); } return rval; } /** * Lists all plugin interfaces. * * @return Lists all primary interfaces. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public Collection<Class<? extends Plugin>> getAllPluginInterfaces() { final Collection<Class<? extends Plugin>> pluginInterfaces = getPluginInterfaces(); final Collection<Class<? extends Plugin>> rval = new ArrayList<Class<? extends Plugin>>(); final ArrayList<Class<? extends Plugin>> x = new ArrayList<Class<? extends Plugin>>(pluginInterfaces); // As long as there are new classes (or ones we havent seen yet) while (x.size() > 0) { Class c = x.get(0); x.remove(0); // And walk up that class. if (!rval.contains(c)) { rval.add(c); } // Get all super interfaces Class[] interfaces = c.getInterfaces(); for (Class class1 : interfaces) { if (x.contains(class1)) continue; x.add(class1); } } return rval; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/PluginUtil.java
Java
bsd
5,727
/** * Some utilities and wrappers for other objects / interfaces. * * @since 1.0 */ package net.xeoh.plugins.base.util;
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/package-info.java
Java
bsd
129
/* * JSPFProperties.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import java.util.Properties; import net.xeoh.plugins.base.PluginConfiguration; import net.xeoh.plugins.base.impl.PluginManagerFactory; /** * Can be used to set properties more easily. Pass this object to the {@link PluginManagerFactory}'s * <code>createPluginManager()</code> method to set initial properties.<br/><br/> * * A good overview on how properties can be used is in the {@link PluginConfiguration}'s documentation. * * @author Ralf Biedert */ public class JSPFProperties extends Properties { /** */ private static final long serialVersionUID = -4275521676384493982L; /** * Sets a property using a class as prefix. For example, if * <code>GeoService</code> is in the package <code>com.company.plugins.geoservice</code> * the following call:<br/><br/> * <code> * setProperty(GeoService.class, "remote.url", "http://geo.ip/q?"); * </code><br/><br/> * would set the configuration key <code>com.company.plugins.geoservice.GeoService.remote.url</code> * to the value <code>http://geo.ip/q?</code>. * * @param root Root class to set an option for. * @param subkey The subkey to set. * @param value The value to set. */ public void setProperty(final Class<?> root, final String subkey, final String value) { setProperty(getKey(root, subkey), value); } /** * Assembles a key, only used internally. * * @param root Root class. * @param subkey Subkey to assemble. * @return The assembled key. */ public static String getKey(final Class<?> root, final String subkey) { String prefix = ""; if (root != null) { prefix = root.getName() + "."; } return prefix + subkey; } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/JSPFProperties.java
Java
bsd
3,380
/* * OptionUtils.java * * Copyright (c) 2009, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import java.util.ArrayList; import java.util.Collection; import net.jcores.jre.utils.VanillaUtil; import net.xeoh.plugins.base.Option; /** * Handles options within plugin methods. Likely to be replaced by * <a href="http://jcores.net">jCores</a>. * * @author Ralf Biedert * * @param <T> Type paramter. */ public class OptionUtils<T extends Option> extends VanillaUtil<T[]> { /** * Creates a new options array. * * @param options */ public OptionUtils(T... options) { super(options); } /** * Check if the selection option is available * * @param option * @return . */ public boolean contains(Class<? extends T> option) { for (T t : this.object) { if (t == null) continue; if (option.isAssignableFrom(t.getClass())) return true; } return false; } /** * Check if the selection option is available * * @param option * @return . */ public boolean containsAny(Class<? extends T>... option) { for (T t : this.object) { if (t == null) continue; for (Class<? extends T> cls : option) { if (cls.isAssignableFrom(t.getClass())) return true; } } return false; } /** * Returns the selection option * * @param <O> * * @param option * @param deflt * @return . */ @SuppressWarnings("unchecked") public <O extends T> O get(Class<? extends O> option, O... deflt) { for (T t : this.object) { if (t == null) continue; if (option.isAssignableFrom(t.getClass())) return (O) t; } // return the default if there is any if (deflt.length > 0) return deflt[0]; return null; } /** * Returns the selection option * * @param <O> * * @param option * @return . */ @SuppressWarnings("unchecked") public <O extends T> Collection<O> getAll(Class<? extends O> option) { final Collection<O> rval = new ArrayList<O>(); for (T t : this.object) { if (t == null) continue; if (option.isAssignableFrom(t.getClass())) { rval.add((O) t); } } return rval; } /** * Returns the selection option * * @param <O> * * @param option * @param handler * */ @SuppressWarnings("unchecked") public <O extends T> void handle(Class<? extends O> option, OptionHandler<O> handler) { for (T t : this.object) { if (t == null) continue; if (option.isAssignableFrom(t.getClass())) { handler.handle((O) t); } } } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/OptionUtils.java
Java
bsd
4,412
package net.xeoh.plugins.base.util; import net.xeoh.plugins.base.Option; /** * Handles options. Only used internally. * * @author Ralf Biedert * * @param <T> Type parameter. */ public interface OptionHandler<T extends Option> { /** * Called with e * * @param option */ public void handle(T option); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/OptionHandler.java
Java
bsd
339
/* * BusImpl.java * * Copyright (c) 2008, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import java.util.logging.Logger; import net.xeoh.plugins.base.PluginConfiguration; /** * Helper functions for PluginConfiguration interface. The util uses the embedded * interface to provide more convenience features. * * @author Ralf Biedert * @see PluginConfiguration */ public class PluginConfigurationUtil extends VanillaPluginUtil<PluginConfiguration> implements PluginConfiguration { /** * Creates a new util for the given interface. * * @param pc The interface to create the utils for. */ public PluginConfigurationUtil(PluginConfiguration pc) { super(pc); } final Logger logger = Logger.getLogger(this.getClass().getName()); /** * Returns the requested key as an integer. * * @param root Root class to request. * @param subkey Subkey to return. * @param defautvalue Default value to return if nothing was found. * @return The requested key, or the default value if the key was not found, or 0 if neither was present. */ @SuppressWarnings("boxing") public int getInt(final Class<?> root, final String subkey, final Integer... defautvalue) { final String configuration = this.object.getConfiguration(root, subkey); if (configuration == null) { if (defautvalue.length >= 1) return defautvalue[0]; this.logger.warning("Returning default 0, but nothing was specified. Your application might behave strangely. Subkey was " + subkey); return 0; } return Integer.parseInt(configuration); } /** * Returns the reqeusted key or a default string. * * @param root Root class to request. * @param subkey Subkey to return. * @param defautvalue Default value to return if nothing was found. * @return The requested key, or the default value if the key was not found, or "" if neither was present. */ public String getString(final Class<?> root, final String subkey, final String... defautvalue) { final String configuration = this.object.getConfiguration(root, subkey); if (configuration == null) { if (defautvalue.length >= 1) return defautvalue[0]; this.logger.warning("Returning default '', but nothing was specified. Your application might behave strangely. Subkey was " + subkey); return ""; } return configuration; } /** * Returns the reqeusted key or a default float. * * @param root Root class to request. * @param subkey Subkey to return. * @param defautvalue Default value to return if nothing was found. * @return The requested key, or the default value if the key was not found, or 0.0 if neither was present. */ @SuppressWarnings("boxing") public float getFloat(final Class<?> root, final String subkey, final Float... defautvalue) { final String configuration = this.object.getConfiguration(root, subkey); if (configuration == null) { if (defautvalue.length >= 1) return defautvalue[0]; this.logger.warning("Returning default '', but nothing was specified. Your application might behave strangely. Subkey was " + subkey); return 0; } return Float.parseFloat(configuration); } /** * Returns the reqeusted key or a default boolean. * * @param root Root class to request. * @param subkey Subkey to return. * @param defautvalue Default value to return if nothing was found. * @return The requested key, or the default value if the key was not found, or <code>false</code> if neither was * present. */ @SuppressWarnings("boxing") public boolean getBoolean(final Class<?> root, final String subkey, final Boolean... defautvalue) { final String configuration = this.object.getConfiguration(root, subkey); if (configuration == null) { if (defautvalue.length >= 1) return defautvalue[0]; this.logger.warning("Returning default '', but nothing was specified. Your application might behave strangely. Subkey was " + subkey); return false; } return Boolean.parseBoolean(configuration); } /** * Returns the reqeusted key or a default double. * * @param root Root class to request. * @param subkey Subkey to return. * @param defautvalue Default value to return if nothing was found. * @return The requested key, or the default value if the key was not found, or 0.0 if neither was present. */ @SuppressWarnings("boxing") public double getDouble(final Class<?> root, final String subkey, final Double... defautvalue) { final String configuration = this.object.getConfiguration(root, subkey); if (configuration == null) { if (defautvalue.length >= 1) return defautvalue[0]; this.logger.warning("Returning default '', but nothing was specified. Your application might behave strangely. Subkey was " + subkey); return 0; } return Double.parseDouble(configuration); } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginConfiguration#getConfiguration(java.lang.Class, java.lang.String) */ @Override public String getConfiguration(Class<?> root, String subkey) { return this.object.getConfiguration(root, subkey); } /* * (non-Javadoc) * * @see net.xeoh.plugins.base.PluginConfiguration#setConfiguration(java.lang.Class, java.lang.String, * java.lang.String) */ @Override public void setConfiguration(Class<?> root, String subkey, String value) { this.object.setConfiguration(root, subkey, value); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/PluginConfigurationUtil.java
Java
bsd
7,668
/* * BusImpl.java * * Copyright (c) 2008, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import static net.jcores.jre.CoreKeeper.$; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import net.xeoh.plugins.base.Plugin; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.options.AddPluginsFromOption; import net.xeoh.plugins.base.options.GetPluginOption; import net.xeoh.plugins.base.options.getplugin.OptionCapabilities; import net.xeoh.plugins.base.options.getplugin.OptionPluginSelector; import net.xeoh.plugins.base.options.getplugin.PluginSelector; /** * Helper functions for {@link PluginManager} interface. The util uses the embedded * interface to provide more convenience features. * * @author Ralf Biedert * @see PluginManager * @since 1.0 */ public class PluginManagerUtil extends VanillaPluginUtil<PluginManager> implements PluginManager { /** * Creates a new util for the given interface. * * @param pm The interface to create the utils for. */ public PluginManagerUtil(PluginManager pm) { super(pm); } /** * Returns all plugins implementing the given interface, not just the first, * 'random' match. Use this method if you want to list the registed plugins (or * select from them on your own). For example, to get all plugins implementing the * <code>Chat</code> interface, write:<br/><br/> * * <code> * getPlugins(Chat.class); * </code> * * @param <P> Type of the requested plugin. * @param plugin The interface to request. * @see OptionPluginSelector * @return A collection of all plugins implementing the given interface. */ public <P extends Plugin> Collection<P> getPlugins(final Class<P> plugin) { return getPlugins(plugin, new PluginSelector<P>() { public boolean selectPlugin(final P p) { return true; } }); } /** * Returns all plugins. Use this method if you want to list all registed plugins. * * @see OptionPluginSelector * @return A collection of all plugins implementing the given interface. */ public Collection<Plugin> getPlugins() { return getPlugins(Plugin.class); } /** * Returns all interfaces implementing the given interface AND satisfying the * given plugin selector. Use this method if you want to list some of the * registed plugins (or select from them on your own). * * @param <P> Type of the requested plugin. * @param plugin The interface to request. * @param selector The selector will be called for each available plugin. When * it returns <code>true</code> the plugin will be added to the return value. * @see OptionPluginSelector * @return A collection of plugins for which the collector return true. */ public <P extends Plugin> Collection<P> getPlugins(final Class<P> plugin, final PluginSelector<P> selector) { final Collection<P> allPlugins = new ArrayList<P>(); this.object.getPlugin(plugin, new OptionPluginSelector<P>(new PluginSelector<P>() { public boolean selectPlugin(final P p) { if (selector.selectPlugin(p)) { allPlugins.add(p); } return false; } })); return allPlugins; } /** * Returns the next best plugin implementing the requested interface and fulfilling * all capabilities specified. * * @since 1.0.3 * @param <P> Type of the requested plugin. * @param plugin The interface to request. * @param cap1 The first capability to consider. * @param caps The other, optional, capabilities to consider. * @see OptionCapabilities * @return A collection of plugins for which the collector return true. */ public <P extends Plugin> P getPlugin(Class<P> plugin, String cap1, String... caps) { return this.object.getPlugin(plugin, new OptionCapabilities($(cap1).add(caps).unsafearray())); } /* (non-Javadoc) * @see net.xeoh.plugins.base.PluginManager#addPluginsFrom(java.net.URI, net.xeoh.plugins.base.options.AddPluginsFromOption[]) */ @Override public PluginManagerUtil addPluginsFrom(URI url, AddPluginsFromOption... options) { this.object.addPluginsFrom(url, options); return this; } /* (non-Javadoc) * @see net.xeoh.plugins.base.PluginManager#getPlugin(java.lang.Class, net.xeoh.plugins.base.options.GetPluginOption[]) */ @Override public <P extends Plugin> P getPlugin(Class<P> plugin, GetPluginOption... options) { return this.object.getPlugin(plugin, options); } /* (non-Javadoc) * @see net.xeoh.plugins.base.PluginManager#shutdown() */ @Override public void shutdown() { this.object.shutdown(); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/PluginManagerUtil.java
Java
bsd
6,699
/* * VanillaPluginUtil.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base.util; import net.jcores.jre.utils.VanillaUtil; import net.xeoh.plugins.base.Plugin; /** * Vanilla wrapper for plugins. * * @author Ralf Biedert * @param <T> */ public abstract class VanillaPluginUtil<T extends Plugin> extends VanillaUtil<T> { public VanillaPluginUtil(T object) { super(object); } }
100json-jspf
modules/core/src/net/xeoh/plugins/base/util/VanillaPluginUtil.java
Java
bsd
1,922
/* * PluginConfiguration.java * * Copyright (c) 2007, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.base; import net.xeoh.plugins.base.annotations.configuration.ConfigurationFile; import net.xeoh.plugins.base.impl.PluginManagerFactory; import net.xeoh.plugins.base.util.JSPFProperties; import net.xeoh.plugins.base.util.PluginConfigurationUtil; /** * Gives you access to configuration items of plugins. In general there are three ways * of adding configuration: * <ol> * <li>by calling <code>setPreferences()</code></li> * <li>by providing a {@link JSPFProperties} object to the {@link PluginManagerFactory}</li> * <li>by using the &#064;{@link ConfigurationFile} annotation.<br/><br/></li> * </ol> * * @author Ralf Biedert * @see PluginConfigurationUtil */ public interface PluginConfiguration extends Plugin { /** * Gets a configuration key. Root may be added for convenience and will * prefix the subkey with its fully qualified name. Thus, if there is an interface * <code>GeoService</code> in the package <code>com.company.plugins.geoservice</code> * the following call:<br/><br/> * <code> * getConfiguration(GeoService.class, "remote.url") * </code><br/><br/> * would try to return the configuration key <code>com.company.plugins.geoservice.GeoService.remote.url</code>. * * @param root May also be null. * @param subkey If used in conjunction with root it should not be prefixed * with a dot (".") * * @return The corresponding value or null if nothing was found. */ public String getConfiguration(Class<?> root, String subkey); /** * Set the key for a value. Root may be added for convenience and will * prefix the subkey with its FQN. Usually the configuration is added * by providing JSPFProperties object to the {@link PluginManagerFactory} * * @param root May also be null. * @param subkey If used in conjunction with root it should not be prefixed * with a dot (".") * @param value The value to set. */ public void setConfiguration(Class<?> root, String subkey, String value); }
100json-jspf
modules/core/src/net/xeoh/plugins/base/PluginConfiguration.java
Java
bsd
3,641
/** * Top level package, nothing to see here. * * @since 1.0 */ package net.xeoh.plugins;
100json-jspf
modules/core/src/net/xeoh/plugins/package-info.java
Java
bsd
96
/* * DiagnosisChannel.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local; import net.xeoh.plugins.diagnosis.local.options.StatusOption; /** * @author Ralf Biedert * @since 1.1 * @param <T> */ public interface DiagnosisChannel<T> { /** * @param value * @param options */ public void status(T value, StatusOption... options); }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/DiagnosisChannel.java
Java
bsd
1,892
/* * DiagnosisChannel.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local; import java.io.Serializable; import java.util.Map; /** * @author Ralf Biedert * @since 1.1 * @param <T> */ public abstract class DiagnosisChannelID<T extends Serializable> { // Note: The ChannelID itself does not have to be Serializable, as we never write any // object. We only instantiate it when we want to use some of its methods. /** * Returns an end user readable string. For example, if the channel reported Floats * representing temperature, you could convert a value of 30.7 to a string of * "30.7°C". * * @param t The value to convert. * @param args The optional arguments passed as OptionInfo(). * @return The converted value. */ public String toUserRepresentation(final T t, final Map<String, Serializable> args) { if (t == null) return "null"; return t.toString(); } }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/DiagnosisChannelID.java
Java
bsd
2,477
/* * DiagnosisListener.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local; import java.io.Serializable; /** * Listens to diagnosis status change messages. * * @author Ralf Biedert * * @param <T> Type of the status. */ public interface DiagnosisMonitor<T extends Serializable> { public void onStatusChange(DiagnosisStatus<T> status); }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/DiagnosisMonitor.java
Java
bsd
1,886
/* * StatusOption.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local.options; import net.xeoh.plugins.base.Option; /** * @author Ralf Biedert * @since 1.1 */ public interface StatusOption extends Option { }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/options/StatusOption.java
Java
bsd
1,749
/* * RegisterConditionOption.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local.options; import net.xeoh.plugins.base.Option; /** * @author Ralf Biedert * @since 1.1 */ public interface RegisterConditionOption extends Option { }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/options/RegisterConditionOption.java
Java
bsd
1,771
/* * ChannelOption.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local.options; import net.xeoh.plugins.base.Option; public interface ChannelOption extends Option { }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/options/ChannelOption.java
Java
bsd
1,705
/* * OptionAtomic.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local.options.status; import net.xeoh.plugins.diagnosis.local.options.StatusOption; public class OptionComment implements StatusOption { /** */ private static final long serialVersionUID = 1294219941602892411L; /** * @param comment */ public OptionComment(String comment) { } }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/options/status/OptionComment.java
Java
bsd
1,913
/* * OptionAtomic.java * * Copyright (c) 2011, Ralf Biedert All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the author nor the names of its contributors may be used to endorse or * promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package net.xeoh.plugins.diagnosis.local.options.status; import net.xeoh.plugins.diagnosis.local.options.StatusOption; public class OptionAtomic implements StatusOption { /** */ private static final long serialVersionUID = 1294219941602892411L; }
100json-jspf
modules/core/src/net/xeoh/plugins/diagnosis/local/options/status/OptionAtomic.java
Java
bsd
1,822