List of usage examples for java.lang Package getName
public String getName()
From source file:de.fischer.thotti.core.runner.NDRunner.java
protected void saveTestResult(TestSuiteResult result) { Package pkg = TestSuiteResult.class.getPackage(); File resultFile = generateResultFileName(); JAXBContext jaxbContext = null; try {/*from w w w .j a va 2 s . com*/ jaxbContext = JAXBContext.newInstance(pkg.getName()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(result, resultFile); } catch (JAXBException e) { // @todo? } }
From source file:org.netbeans.modules.trintejs.json.JSONObject.java
/** * Wrap an object, if necessary. If the object is null, return the NULL * object. If it is an array or collection, wrap it in a JSONArray. If * it is a map, wrap it in a JSONObject. If it is a standard property * (Double, String, et al) then it is already wrapped. Otherwise, if it * comes from one of the java packages, turn it into a string. And if * it doesn't, try to wrap it in a JSONObject. If the wrapping fails, * then null is returned./*w w w.j a v a 2s .c om*/ * * @param object The object to wrap * @return The wrapped value */ public static Object wrap(Object object) { try { if (object == null) { return NULL; } if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String) { return object; } if (object instanceof Collection) { return new JSONArray((Collection) object); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { return new JSONObject((Map) object); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) { return object.toString(); } return new JSONObject(object); } catch (Exception exception) { return null; } }
From source file:org.talend.core.model.metadata.DBConnectionFillerImplTest.java
private void initializeForFillTables(orgomg.cwm.objectmodel.core.Package pack, DatabaseMetaData dbmd, String[] tableType, boolean isOracle) throws SQLException { when(pack.getName()).thenReturn("tdqPackage");//$NON-NLS-1$ PowerMockito.mockStatic(PackageHelper.class); when(PackageHelper.getParentPackage(pack)).thenReturn(pack); when(PackageHelper.getCatalogOrSchema(pack)).thenReturn(pack); Connection con = mock(Connection.class); PowerMockito.mockStatic(MetadataConnectionUtils.class); when(MetadataConnectionUtils.isAS400(pack)).thenReturn(false); when(MetadataConnectionUtils.isOracle(con)).thenReturn(isOracle); when(MetadataConnectionUtils.isSybase(dbmd)).thenReturn(false); when(MetadataConnectionUtils.isOracle8i(con)).thenReturn(false); when(MetadataConnectionUtils.isOracleJDBC(con)).thenReturn(isOracle); PowerMockito.mockStatic(ConnectionHelper.class); when(ConnectionHelper.getConnection(pack)).thenReturn(con); List<String> filterNames = new ArrayList<String>(); filterNames.add("Table1");//$NON-NLS-1$ if (isOracle) { java.sql.Connection sqlConn = mock(java.sql.Connection.class); when(dbmd.getConnection()).thenReturn(sqlConn); Statement stme = mock(Statement.class); ResultSet rsTables = mock(ResultSet.class); when(sqlConn.createStatement()).thenReturn(stme); when(stme.executeQuery(TableInfoParameters.ORACLE_10G_RECBIN_SQL)).thenReturn(rsTables); stub(method(ExtractMetaDataFromDataBase.class, "getTableNamesFromQuery")).toReturn(filterNames);//$NON-NLS-1$ stub(method(ExtensionImplementationProvider.class, "getInstanceV2", IExtensionPointLimiter.class)) //$NON-NLS-1$ .toReturn(new ArrayList<IConfigurationElement>()); }// w ww .j a v a 2 s. c o m ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true).thenReturn(true).thenReturn(false); when(rs.getString(GetTable.TABLE_NAME.name())).thenReturn("Table1").thenReturn("Table2");//$NON-NLS-1$ //$NON-NLS-2$ when(rs.getString(GetTable.TABLE_TYPE.name())).thenReturn("Table");//$NON-NLS-1$ when(rs.getString(GetTable.REMARKS.name())).thenReturn("");//$NON-NLS-1$ when(dbmd.getTables("tdqPackage", "tdqPackage", "", tableType)).thenReturn(rs);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ when(dbmd.getTables("tdqPackage", null, "", tableType)).thenReturn(rs);//$NON-NLS-1$//$NON-NLS-2$ stub(method(StringUtils.class, "isBlank")).toReturn(false);//$NON-NLS-1$ ProxyRepositoryFactory proxFactory = mock(ProxyRepositoryFactory.class); when(proxFactory.getNextId()).thenReturn("abcd1").thenReturn("abcd2");//$NON-NLS-1$//$NON-NLS-2$ stub(method(ProxyRepositoryFactory.class, "getInstance")).toReturn(proxFactory);//$NON-NLS-1$ }
From source file:org.rhq.enterprise.server.plugin.pc.content.sync.PackageSourceSynchronizer.java
/** * Translates the domain representation of a list of packages into DTOs used in the plugin APIs. * During the translation the two collections (allDetails and keyPVCSMap) will be populated with * different views into the data.// w w w. ja v a 2 s . com * * @param existingPVCS list of packages in the form of the wrapper object linking them to * the content source * @param allDetails set of all translated package DTOs * @param keyPVCSMap mapping of package version key to package domain object */ private void translateDomainToDto(List<PackageVersionContentSource> existingPVCS, Set<ContentProviderPackageDetails> allDetails, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap) { for (PackageVersionContentSource pvcs : existingPVCS) { PackageVersion pv = pvcs.getPackageVersionContentSourcePK().getPackageVersion(); org.rhq.core.domain.content.Package p = pv.getGeneralPackage(); ResourceType rt = p.getPackageType().getResourceType(); String resourceTypeName = rt != null ? rt.getName() : null; String resourceTypePlugin = rt != null ? rt.getPlugin() : null; ContentProviderPackageDetailsKey key; key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), p.getPackageType().getName(), pv.getArchitecture().getName(), resourceTypeName, resourceTypePlugin); ContentProviderPackageDetails details = new ContentProviderPackageDetails(key); details.setClassification(pv.getGeneralPackage().getClassification()); details.setDisplayName(pv.getDisplayName()); details.setDisplayVersion(pv.getDisplayVersion()); details.setExtraProperties(pv.getExtraProperties()); details.setFileCreatedDate(pv.getFileCreatedDate()); details.setFileName(pv.getFileName()); details.setFileSize(pv.getFileSize()); details.setLicenseName(pv.getLicenseName()); details.setLicenseVersion(pv.getLicenseVersion()); details.setLocation(pvcs.getLocation()); details.setLongDescription(pv.getLongDescription()); details.setMD5(pv.getMD5()); details.setMetadata(pv.getMetadata()); details.setSHA256(pv.getSHA256()); details.setShortDescription(pv.getShortDescription()); allDetails.add(details); keyPVCSMap.put(key, pvcs); } }
From source file:org.openx.data.jsonserde.json.JSONObject.java
/** * Wrap an object, if necessary. If the object is null, return the NULL * object. If it is an array or collection, wrap it in a JSONArray. If * it is a map, wrap it in a JSONObject. If it is a standard property * (Double, String, et al) then it is already wrapped. Otherwise, if it * comes from one of the java packages, turn it into a string. And if * it doesn't, try to wrap it in a JSONObject. If the wrapping fails, * then null is returned.//from www. j a va2 s . c om * * @param object The object to wrap * @return The wrapped value */ public static Object wrap(Object object) { try { if (object == null) { return NULL; } if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String) { return object; } if (object instanceof Collection) { return new JSONArray((Collection) object); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { return new JSONObject((Map) object); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) { return object.toString(); } return new JSONObject(object); } catch (JSONException exception) { return null; } }
From source file:me.acristoffers.tracker.AlarmReceiver.java
@Override public void statusUpdated(final Package pkg) { final String code = pkg.getCod(); final int count = pkg.getSteps().size(); if (countSteps.get(code) < count) { pkg.save();/*from w w w . jav a 2 s . com*/ final NotificationManager notificationManager = (NotificationManager) context.get() .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { final String title = context.get().getString(R.string.notification_package_updated_title, pkg.getName()); final String message = context.get().getString(R.string.notification_package_updated_body, pkg.getName()); final Intent intent = new Intent(context.get(), PackageDetailsActivity.class); intent.putExtra(PackageDetailsActivity.PACKAGE_CODE, code); final PendingIntent pendingIntent = PendingIntent.getActivity(context.get(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final Bitmap icon = BitmapFactory.decodeResource(context.get().getResources(), R.mipmap.ic_launcher); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context.get()); builder.setTicker(title).setContentTitle(title).setContentText(message) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) context.get() .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(pkg.getId(), notification); } } }
From source file:com.tower.service.test.SoafwTesterMojo.java
private String readTestSrc(String className) { BufferedReader br = null;/* w ww . jav a 2 s . c om*/ String test = className + "Test"; StringBuilder testSrc = new StringBuilder(); try { Class tstCls = cl.loadClass(test); Package pkg = tstCls.getPackage(); String pkgName = pkg.getName(); String relativePath = pkgName.replace(".", File.separator); String testBaseSrcPath = basedPath + File.separator + "src" + File.separator + "test" + File.separator + "java"; String testSrcFullPath = testBaseSrcPath + File.separator + relativePath + File.separator + tstCls.getSimpleName() + ".java"; br = new BufferedReader(new InputStreamReader(new FileInputStream(testSrcFullPath), "UTF-8")); String line = null; while ((line = br.readLine()) != null) { testSrc.append(line); testSrc.append("\n"); } } catch (Exception e) { this.getLog().error(e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { } } return testSrc.toString(); } }
From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java
/** * Adds the java class hirarchy links./*from www . j a va2 s . c o m*/ * * @param root the root * @param clazz the clazz * @param javaClass the java class */ private void addJavaClassHirarchyLinks(final Context root, final Class<?> clazz, final JavaClass javaClass) { final Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { final Package classPack = clazz.getPackage(); final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, classPack.getName()); // javaPackage.setCaption(classPack.getName()); final JavaClass superJavaClass = writer.addChildNode(javaPackage, JavaClass.class, superClass.getName()); writer.addLink(PackageContainsType.class, javaPackage, superJavaClass); writer.addLink(JavaClassHierarchy.class, javaClass, superJavaClass); addJavaClassHirarchyLinks(root, superClass, superJavaClass); } }
From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java
/** * Adds the class implements interface links. * /* w ww. ja v a2 s. c o m*/ * @param root the root * @param clazz the clazz * @param javaClass the java class */ private void addClassImplementsInterfaceLinks(final Context root, final Class<?> clazz, final JavaClass javaClass) { final Class<?>[] iFaces = clazz.getInterfaces(); for (final Class<?> iFace : iFaces) { final Package iFacePack = iFace.getPackage(); final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, iFacePack.getName()); // javaPackage.setCaption(iFacePack.getName()); final JavaInterface javaInterface = writer.addChildNode(javaPackage, JavaInterface.class, iFace.getName()); // javaInterface.setCaption(iFace.getName()); final ClassImplementsInterface link = writer.addLink(ClassImplementsInterface.class, javaClass, javaInterface); link.setTag(randomTag()); } }
From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java
/** * Adds the java interface hirarchy links. * /*from www .j a va 2 s.co m*/ * @param root the root * @param iFace the i face * @param javaInterface the java interface */ private void addJavaInterfaceHirarchyLinks(final Context root, final Class<?> iFace, final JavaInterface javaInterface) { final Class<?>[] superIFaces = iFace.getInterfaces(); for (final Class<?> superIFace : superIFaces) { final Package iFacePack = iFace.getPackage(); final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, iFacePack.getName()); // javaPackage.setCaption(iFacePack.getName()); final JavaInterface superJavaInterface = writer.addChildNode(javaPackage, JavaInterface.class, superIFace.getName()); writer.addLink(PackageContainsType.class, javaPackage, superJavaInterface); // superJavaInterface.setCaption(superIFace.getName()); writer.addLink(JavaInterfaceHierarchy.class, javaInterface, superJavaInterface); addJavaInterfaceHirarchyLinks(root, superIFace, superJavaInterface); } }