protected void maybeAddAncestors(Gwtc gwtc, Class<?> c) { addGwtcClass(gwtc, c); for (AncestorMode mode : gwtc.inheritanceMode()) { switch (mode) { case INHERIT_ONE_PARENT: Package pkg = c.getPackage(); gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } break; case INHERIT_ALL_PARENTS: addAllPackages(c.getPackage()); break; case INHERIT_ENCLOSING_CLASSES: addEnclosingClasses(c); break; case INHERIT_SUPER_CLASSES: addSuperclasses(c); break; default: X_Log.warn("Unsupported mode type", mode, "for class", c); } } }
private void jButton7ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton7ActionPerformed // TODO add your handling code here: Package pc = new Package(); pc.setVisible(true); dispose(); } // GEN-LAST:event_jButton7ActionPerformed
protected Package addClassName(final Package previousPackage, String className) { int dot = className.lastIndexOf('.'); String pkgName = dot < 0 ? "" : className.substring(0, dot); Package pkg = getPackage(previousPackage, pkgName); pkg.add(new ClassName(className.substring(dot + 1))); return pkg; }
/** * This method returns the supermost class of the class passed that is in the same package as * class * * @author aarti_sharma * @param objClass * @return */ public static Class getSupermostClassInPackage(Object obj) { Class objClass = obj.getClass(); Package objPackage = objClass.getPackage(); Logger.out.debug("Input Class: " + objClass.getName() + " Package:" + objPackage.getName()); PersistentClass persistentClass = cfg.getClassMapping(objClass); if (persistentClass != null && persistentClass.getSuperclass() != null) { Logger.out.debug( objPackage.getName() + " " + persistentClass.getName() + "*********" + persistentClass.getSuperclass().getMappedClass().getPackage().getName()); Logger.out.debug( "!!!!!!!!!!! " + persistentClass .getSuperclass() .getMappedClass() .getPackage() .getName() .equals(objPackage.getName())); do { persistentClass = persistentClass.getSuperclass(); } while (persistentClass != null); Logger.out.debug( "Supermost class in the same package:" + persistentClass.getMappedClass().getName()); } else { return objClass; } return persistentClass.getMappedClass(); }
protected Class<?> findImpl(Class<T> iface) { Package pkg = iface.getPackage(); String pkgName = (pkg != null) ? pkg.getName() : DEFAULT_PACKAGE_NAME; String clsName = iface.getSimpleName(); Class<?> implClass = null; // look up in the following orders // 1. package.name.ClassNameImpl // 2. package.name.impl.ClassNameImpl // 3. package.name.impl.ClassName // 4. package.name.DefaultClassName // 5. package.name.DefaultHandler String[] lookups = { pkgName + "." + clsName + "Impl", pkgName + ".impl." + clsName + "Impl", pkgName + ".impl." + clsName, pkgName + "." + "Default" + clsName, pkgName + "." + "DefaultHandler" }; try { implClass = new ClassNameLookup(lookups, iface).lookup(); } catch (NotFound e) { // ignore logIntentionallyIgnoredCatch(log, e); } if (log.isLoggable(Level.FINE)) { log.fine("findImpl[iface=" + iface + ", implClass=" + String.valueOf(implClass) + "]"); } return implClass; }
private void logVersionInfo(Class<?> clazz, String title, Log log) { Package pack = clazz.getPackage(); String version = null; if (pack != null) { if (pack.getImplementationTitle() != null) { title = pack.getImplementationTitle(); } version = pack.getImplementationVersion(); } if (version == null) { try { String classname = clazz.getName(); Class<?> packinf = Class.forName(classname.substring(0, classname.lastIndexOf('.')) + ".PackageInfo"); java.lang.reflect.Method mo = packinf.getMethod("getProductVersion"); version = mo.invoke(null).toString(); } catch (Exception pie) { log.info("PackageInfo not found"); } if (version == null) { version = "<unknown>"; } } log.info(title + " version " + version); }
public HashMap<String, Package> load() { HashMap<String, Package> packages = new HashMap<String, Package>(); File inFile = obtainFile(); if (null == inFile) { System.out.println(String.format("[KITS] Unable to load %s.", filename)); return packages; } try { BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) continue; String[] tokens = line.split(";"); if (tokens.length < 2) continue; Package newPkg = makePackage(tokens); if (null != newPkg) { packages.put(newPkg.getName(), newPkg); } } reader.close(); } catch (Exception e) { System.out.println(e.getStackTrace()); } return packages; }
public static void main(String args[]) throws Exception { if (args.length >= 2) { String className = args[0]; String infoNeeded = args[1]; String message = ""; Class clazz = null; try { clazz = Class.forName(className); } catch (Exception e) { System.out.println("class not found: '" + className + "'"); return; } if ("ImplementationVersion".equals(infoNeeded)) { final Package aPackage = clazz.getPackage(); if (aPackage != null) { System.out.print(aPackage.getImplementationVersion()); return; } else { System.out.println("package for class '" + className + "' not found!"); return; } } else { throw new Exception(infoNeeded + " not supported"); } } else { throw new Exception("Usage: PackageInfo class-name info-required"); } }
/* * Checks to make sure that all types in a package are defined by files in the same directory. */ private void checkPackageDirectories(Package _package) { Collection<Type> types = _package.getTypes(); Type firstType = null; File path1 = null; /* Gets the directory of the first type and compares all others to it. */ if (types.size() > 1) { for (Type type : types) { if (firstType == null) { firstType = type; path1 = typeTable.get(type).getFile().getParentFile(); } else { File path2 = typeTable.get(type).getFile().getParentFile(); if (!path1.equals(path2)) addWarning( Error.MISMATCHED_PACKAGE, "Type " + firstType + " and " + type + " both belong to package " + _package + " but are defined in different directories"); } } } // Recursively check child packages. for (Package child : _package.getChildren().values()) checkPackageDirectories(child); }
public ClassMeta getClassInfo(Class<?> cls) { final Package pkg = cls.getPackage(); URL loadedFrom = null; try { loadedFrom = cls.getProtectionDomain().getCodeSource().getLocation(); } catch (Throwable t) { Log.warn(t, "Failed to get source for %s", cls); } final API apiAnnotation = pkg.getAnnotation(API.class); final ApiInfo apiInfo = apiAnnotation != null ? new ApiInfo(apiAnnotation) : null; Map<File, Set<String>> mods = Maps.newHashMap(); for (ModCandidate candidate : table.getCandidatesFor(pkg.getName())) { if (!candidate.getClassList().contains(cls.getName().replace('.', '/'))) continue; final File candidateFile = candidate.getModContainer(); Set<String> modIds = Sets.newHashSet(); mods.put(candidateFile, modIds); for (ModContainer mod : candidate.getContainedMods()) modIds.add(mod.getModId()); } return new ClassMeta(cls, loadedFrom, apiInfo, mods); }
public void start() throws GaspException { checkInitDone(); log.debug("Starting application"); final Package pkg = getClass().getPackage(); final String title = pkg.getSpecificationTitle(); final String version = pkg.getSpecificationVersion(); if (!StringUtils.isBlank(title) && !StringUtils.isBlank(version)) { // print version in the log log.info("Using: " + title + " " + version); } final PluginRegistry pluginRegistry = PluginManager.instance().getPluginRegistry(); for (final String pluginDesc : pluginsToStart) { try { final String pluginId = getPluginId(pluginDesc); final Version pluginVersion = getPluginVersion(pluginDesc); pluginRegistry.activate(pluginId, pluginVersion); } catch (Exception e) { throw new GaspException("Error while starting plugin: " + pluginDesc, e); } } log.info("Platform is up and running"); }
/** * Returns the correct implementation instance for the interface <code>type</code>. For convention * the implentation is named <code>InterfaceName + Impl</code>. * * @param type The interface type * @return The correct ModelProxy subclass (if exists), a ModelProxy instance otherwise * @throws MalformedModelException is the interface or the implementation are not well formed * (they don't respect the conventions). * @throws ModelRuntimeException is any error occurs during the instantiation */ protected ModelProxy createInstance(Class type) { Class backClass; if (implementations.containsKey(type)) backClass = implementations.get(type); else { /* type never seen */ try { Package pkg = type.getPackage(); String pkgN = pkg == null ? "" : pkg.getName(); backClass = Class.forName(pkgN + tableName(type) + CommonStatic.getImplementationSuffix()); } catch (Exception e) { backClass = ModelProxy.class; } Validator.validateModel(type, backClass); initFieldsTypes(type); implementations.put(type, backClass); } ModelProxy impl = null; try { impl = (ModelProxy) backClass.newInstance(); } catch (Exception e) { throw new ModelRuntimeException(e.getMessage()); } return impl; }
private Object findAncestor(Class<?> clazz) { // First check enclosing classes Class<?> c = clazz.getDeclaringClass(); while (c != null) { if (c.isAnnotationPresent(Gwtc.class)) { return c; } c = c.getDeclaringClass(); } Package p = clazz.getPackage(); if (p.getAnnotation(Gwtc.class) != null) { return p; } Object o = findAncestor(p); if (o == null) { c = clazz.getSuperclass(); while (c != null) { if (c.isAnnotationPresent(Gwtc.class)) { return c; } c = c.getSuperclass(); } } return o; }
/** * Compares all SubPackage objects of two Package objects. * * @param xPackage Package from the Schema, of which all Packages should be compared. * @param gPackage Package from the SchemaGraph, of which all Packages should be compared. */ private final void compareAllSubPackages( de.uni_koblenz.jgralab.schema.Package xPackage, Package gPackage) { // Map of SubPackages is cloned Map<String, de.uni_koblenz.jgralab.schema.Package> subPackages = new HashMap<String, de.uni_koblenz.jgralab.schema.Package>(xPackage.getSubPackages()); // Loop over all ContainsSubPackage edges for (ContainsSubPackage containsSubPackage : gPackage.getContainsSubPackageIncidences(OUTGOING)) { assertTrue( "Omega should be an instance of \"Package\".", containsSubPackage.getOmega() instanceof Package); Package gSubPackage = containsSubPackage.getOmega(); de.uni_koblenz.jgralab.schema.Package subpackage = schema.getPackage(gSubPackage.get_qualifiedName()); // The references shouldn't be null assertTrue("There is no corresponding Package in Schema.", subpackage != null); assertTrue( "There is no corresponding Package in Schema.", subPackages.containsKey(subpackage.getSimpleName())); // Gets, removes and compares both Package objects with each other comparePackage(subPackages.remove(subpackage.getSimpleName()), gSubPackage); } // There shouldn't be any Package left in the map assertTrue( "There are more Packages in the Schema then in the SchemaGraph.", subPackages.isEmpty()); }
public static Map<Package, ClassLoader[]> getPackageMap( List<ClassLoader> classLoaders, Set<String> ignorePackages) { Map<Package, ClassLoader[]> answer = new HashMap<Package, ClassLoader[]>(); ClassLoader[] globalClassLoaders = { Thread.currentThread().getContextClassLoader(), ClassScanner.class.getClassLoader() }; Set<Package> packages = new HashSet<Package>(); add(answer, Package.getPackages(), globalClassLoaders, ignorePackages); ClassLoader[] classLoaderArray = new ClassLoader[classLoaders.size()]; classLoaders.toArray(classLoaderArray); for (ClassLoader classLoader : classLoaders) { Package[] loaderPackages = findPackagesForClassLoader(classLoader); add(answer, loaderPackages, classLoaderArray, ignorePackages); } SortedSet<String> names = new TreeSet<String>(); for (Package aPackage : packages) { names.add(aPackage.getName()); } for (String name : names) { LOG.info("Got package " + name); } return answer; }
private List<String> dependenciesOf(Package source) { List<String> result = new ArrayList<>(); if (source.isAnnotationPresent(DependsUpon.class)) for (Class<?> target : source.getAnnotation(DependsUpon.class).packagesOf()) result.add(target.getPackage().getName()); return result; }
/** * Scan all output dirs for artifacts and remove those files (artifacts?) that are not recognized * as such, in the javac_state file. */ public void removeUnidentifiedArtifacts() { Set<File> allKnownArtifacts = new HashSet<>(); for (Package pkg : prev.packages().values()) { for (File f : pkg.artifacts().values()) { allKnownArtifacts.add(f); } } // Do not forget about javac_state.... allKnownArtifacts.add(javacState); for (File f : binArtifacts) { if (!allKnownArtifacts.contains(f)) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } for (File f : headerArtifacts) { if (!allKnownArtifacts.contains(f)) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } for (File f : gensrcArtifacts) { if (!allKnownArtifacts.contains(f)) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } }
/** * Gets an system property value. * * @param parameterName the Name or the parameter. * @return String value or null if not found */ protected String getSystemProperty(String parameterName) { String val = null; String pkgName; final Package pkg = systemPropertyBaseClass.getPackage(); if (pkg != null) { pkgName = pkg.getName(); } else { final String className = systemPropertyBaseClass.getName(); int index = className.lastIndexOf('.'); if (index >= 0) { pkgName = className.substring(0, index); } else { pkgName = null; } } if (pkgName == null) { pkgName = ""; } else { pkgName += '.'; } val = System.getProperty(pkgName + parameterName); if (val != null) { return val; } // Try lowercased system properties val = System.getProperty(pkgName + parameterName.toLowerCase()); return val; }
/** Lookup the artifacts generated for this package in the previous build. */ private Map<String, File> fetchPrevArtifacts(String pkg) { Package p = prev.packages().get(pkg); if (p != null) { return p.artifacts(); } return new HashMap<>(); }
/** Add Karaf core features URL in the default repositories set */ private void appendKarafCoreFeaturesDescriptors() { if (repositories == null) { repositories = new ArrayList<String>(); } if (karafVersion == null) { Package p = Package.getPackage("org.apache.karaf.tooling.features"); karafVersion = p.getImplementationVersion(); } String karafCoreStandardFeaturesUrl = String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion); String karafCoreEnterpriseFeaturesUrl = String.format(KARAF_CORE_ENTERPRISE_FEATURE_URL, karafVersion); try { resolve(karafCoreStandardFeaturesUrl); repositories.add(karafCoreStandardFeaturesUrl); } catch (Exception e) { warn("Can't add " + karafCoreStandardFeaturesUrl + " in the default repositories set"); } try { resolve(karafCoreEnterpriseFeaturesUrl); repositories.add(karafCoreEnterpriseFeaturesUrl); } catch (Exception e) { warn("Can't add " + karafCoreStandardFeaturesUrl + " in the default repositories set"); } }
// Serialize the bean using the specified namespace prefix & uri public String serialize(Object bean) throws IntrospectionException, IllegalAccessException { // Use the class name as the name of the root element String className = bean.getClass().getName(); String rootElementName = null; if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) { AnnotatedElement annotatedElement = bean.getClass(); ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class); rootElementName = aliasAnnotation.value(); } // Use the package name as the namespace URI Package pkg = bean.getClass().getPackage(); nsURI = pkg.getName(); // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array) className = StringUtils.deleteTrailingChar(className, ';'); StringBuffer sb = new StringBuffer(className); String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString(); domDocument = createDomDocument(objectName); document = domDocument.getDocument(); Element root = document.getDocumentElement(); // Parse the bean elements getBeanElements(root, rootElementName, className, bean); StringBuffer xml = new StringBuffer(); if (prettyPrint) xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog)); else xml.append(domDocument.serialize(includeXmlProlog)); if (!includeTypeInfo) { int index = xml.indexOf(root.getNodeName()); xml.delete(index - 1, index + root.getNodeName().length() + 2); xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length()); } return xml.toString(); }
public boolean isNonTerminal(Class clazz) { Package pack = clazz.getPackage(); if (pack == null) { // z.B. bei int[] return false; } return patternListFilter.filter(pack.getName()); }
public void addPackages(Package pkg, GwtcServiceImpl gwtc, boolean recursive) { Iterable<ClassFile> iter; if (recursive) { iter = classpath.get().findClassesBelowPackage(pkg.getName()); } else { iter = classpath.get().findClassesInPackage(pkg.getName()); } for (ClassFile file : iter) { X_Log.info(getClass(), "Scanning file ", file); if ("package-info".equals(file.getEnclosedName())) { Package p = GwtReflect.getPackage(file.getPackage()); if (!finishedPackages.contains(p)) { gwtcService.addPackage(p, false); } } else { try { Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(file.getName()); if (!finishedClasses.contains(cls)) { gwtc.addClass(cls); } } catch (ClassNotFoundException e) { X_Log.warn(getClass(), "Unable to load class ", file); } } } }
protected void addAllPackages(Package pkg) { Gwtc gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } String parentName = pkg.getName(); int ind = parentName.lastIndexOf('.'); while (ind > -1) { parentName = parentName.substring(0, ind); ind = parentName.lastIndexOf('.'); pkg = GwtReflect.getPackage(parentName); X_Log.debug(getClass(), "Checking parent package", "'" + parentName + "'", pkg != null); if (pkg != null) { gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } } } pkg = GwtReflect.getPackage(""); if (pkg != null) { gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } } }
/** * Get the {@link JAXBContext} from an existing {@link Class} object. If the class's owning * package is a valid JAXB package, this method redirects to {@link #getFromCache(Package)} * otherwise a new JAXB context is created and NOT cached. * * @param aClass The class for which the JAXB context is to be created. May not be <code>null * </code>. * @param aClassLoader Class loader to use. May be <code>null</code> in which case the default * class loader is used. * @return Never <code>null</code>. */ @Nonnull public JAXBContext getFromCache( @Nonnull final Class<?> aClass, @Nullable final ClassLoader aClassLoader) { ValueEnforcer.notNull(aClass, "Class"); final Package aPackage = aClass.getPackage(); if (aPackage.getAnnotation(XmlSchema.class) != null) { // Redirect to cached version return getFromCache(aPackage, aClassLoader); } // E.g. an internal class - try anyway! if (GlobalDebug.isDebugMode()) s_aLogger.info("Creating JAXB context for class " + aClass.getName()); if (aClassLoader != null) s_aLogger.warn( "Package " + aPackage.getName() + " does not seem to be JAXB generated. Therefore a new JAXBContext is created and the provided ClassLoader is ignored!"); try { return JAXBContext.newInstance(aClass); } catch (final JAXBException ex) { final String sMsg = "Failed to create JAXB context for class '" + aClass.getName() + "'"; s_aLogger.error(sMsg + ": " + ex.getMessage()); throw new IllegalArgumentException(sMsg, ex); } }
/** Starts the Error Checker Service thread */ @Override public void run() { lastTab = editor.getSketch().getCodeIndex(editor.getSketch().getCurrentCode()); initializeErrorWindow(); xqpreproc = new XQPreprocessor(); // Run check code just once before entering into loop. // Makes sure everything is initialized and set. checkCode(); editor.getTextArea().repaint(); stopThread = false; while (!stopThread) { try { // Take a nap. Thread.sleep(sleepTime); } catch (Exception e) { System.out.println("Oops! [ErrorCheckerThreaded]: " + e); // e.printStackTrace(); } if (pauseThread) continue; // Check every x seconds checkCode(); if (runCount < 5) { runCount++; } if (runCount == 3) { Package p = XQMode.class.getPackage(); System.out.println(p.getImplementationTitle() + " v" + p.getImplementationVersion()); } } }
/** * Generates a simplified name from a {@link Class}. Similar to {@link Class#getSimpleName()}, but * it works fine with anonymous classes. */ public static String simpleClassName(Class<?> clazz) { Package pkg = clazz.getPackage(); if (pkg != null) { return clazz.getName().substring(pkg.getName().length() + 1); } else { return clazz.getName(); } }
private String getCurrentApplicationVersion() { Package pkg = getClass().getPackage(); if (pkg != null) { return pkg.getSpecificationVersion(); } else { // not in a jar return null; } }
/** * Find other packages with the same NVRE but with different arches * * @param pack the package * @return List of package objects */ public static List<Package> findPackagesWithDifferentArch(Package pack) { Map<String, Object> params = new HashMap<String, Object>(); params.put("evr", pack.getPackageEvr()); params.put("name", pack.getPackageName()); params.put("arch", pack.getPackageArch()); return singleton.listObjectsByNamedQuery("Package.findOtherArches", params); }
private String getPath(Class<?> clazz) { Package clazzPackage = clazz.getPackage(); String packagePath = clazzPackage.getName(); if (packagePath != null && packagePath.length() > 0) { return packagePath + "." + clazz.getSimpleName(); } return clazz.getSimpleName(); }