List of usage examples for java.lang Package getName
public String getName()
From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java
public void initialize() { StringBuilder sb = new StringBuilder(); Iterator<Package> iterator = getSchemaRegistry().getCompileTimePackages().iterator(); while (iterator.hasNext()) { Package jaxbPackage = iterator.next(); sb.append(jaxbPackage.getName()); if (iterator.hasNext()) { sb.append(":"); }// w ww .j av a 2 s . c o m } String jaxbPaths = sb.toString(); if (jaxbPaths.isEmpty()) { LOGGER.debug("No JAXB paths, skipping creation of JAXB context"); } else { try { context = JAXBContext.newInstance(jaxbPaths); } catch (JAXBException ex) { throw new SystemException("Couldn't create JAXBContext for: " + jaxbPaths, ex); } } }
From source file:org.talend.repository.nosql.ui.common.AbstractNoSQLRetrieveSchemaForm.java
private void addTable(TreeItem item) { INoSQLSchemaNode node = (INoSQLSchemaNode) item.getData(); if (isExistTable(node, false)) { MetadataTable table = getTable(node, false); orgomg.cwm.objectmodel.core.Package pack = (orgomg.cwm.objectmodel.core.Package) table.eContainer(); boolean confirm = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("AbstractNoSQLRetrieveSchemaForm.confirm"), //$NON-NLS-1$ Messages.getString("AbstractNoSQLRetrieveSchemaForm.ConfirmMessage", pack.getName())); //$NON-NLS-1$ if (confirm) { TreeItem existItem = getExistItem(table); if (existItem != null) { existItem.setChecked(false); deleteTable(existItem);/* w w w. ja v a 2 s . c o m*/ } } else { item.setChecked(false); return; } } if (!retrieveSchemaExecutor.isThreadRunning(node) && node.getSchemaType() == ENoSQLSchemaType.TABLE) { RetrieveColumnRunnable runnable = new RetrieveColumnRunnable(metadataProvider, getConnection(), node, hitTablesMap) { @Override protected void refresh(INoSQLSchemaNode schemaNode) { refreshTable(schemaNode); } }; retrieveSchemaExecutor.execute(runnable); } }
From source file:name.livitski.tools.persista.StorageBootstrap.java
/** * Uses the package name of a persistent class to designate * a persistence unit for this object./*www .j av a 2 s . com*/ * @see #setPersistenceUnit(String) * @see #getPersistenceUnit */ public void setPersistenceUnit(Class<?> persistentClass) { Package pkg = persistentClass.getPackage(); if (null == pkg) throw new IllegalArgumentException("Class " + persistentClass.getName() + " from the default package cannot be used to set the persistence unit."); setPersistenceUnit(pkg.getName()); }
From source file:com.ng.mats.psa.mt.paga.data.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 || object instanceof BigInteger || object instanceof BigDecimal) { return object; } if (object instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> coll = (Collection<Object>) object; return new JSONArray(coll); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) object; return new JSONObject(map); } 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.opennms.ng.services.pollerconfig.PollerConfigFactory.java
/** * Load the config from the default config file and create the singleton * instance of this factory.// ww w . j av a 2 s. c om * * @throws java.io.IOException Thrown if the specified config file cannot be read * @throws org.exolab.castor.xml.MarshalException Thrown if the file does not conform to the schema. * @throws org.exolab.castor.xml.ValidationException Thrown if the contents do not match the required schema. * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public synchronized void init() throws IOException, MarshalException, ValidationException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONFIG_FILE_NAME); LOG.debug("init: config file path: {}", cfgFile.getPath()); InputStream stream = null; PollerConfigFactory config = null; if (getOpennmsServerConfig() == null) { LOG.error("ServerConfigFactory is null"); } try { stream = new FileInputStream(cfgFile); config = new PollerConfigFactory(cfgFile.lastModified(), stream, getOpennmsServerConfig().getServerName(), getOpennmsServerConfig().verifyServer(), getBundleContext(), getOpennmsServerConfig()); } finally { IOUtils.closeQuietly(stream); } for (final org.opennms.netmgt.config.poller.Package pollerPackage : config.getConfiguration() .getPackageCollection()) { for (final org.opennms.netmgt.config.poller.Service service : pollerPackage.getServiceCollection()) { for (final org.opennms.netmgt.config.poller.Parameter parm : service.getParameterCollection()) { if (parm.getKey().equals("ds-name")) { if (parm.getValue().length() > ConfigFileConstants.RRD_DS_MAX_SIZE) { throw new ValidationException(String.format( "ds-name '%s' in service '%s' (poller package '%s') is greater than %d characters", parm.getValue(), service.getName(), pollerPackage.getName(), ConfigFileConstants.RRD_DS_MAX_SIZE)); } } } } } setInstance(config); }
From source file:org.disciple.db.Abatis.java
/** * * @param sqlId SQLID/*from w ww . j av a2s . co m*/ * @param bindParams sql parameter * @param bean bean class of result * * @return List<Map<String, Object>> result */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> List<T> executeForBeanList(String sqlId, Map<String, Object> bindParams, Class bean) { getDbObject(); int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName()); if (pointer == 0) { Log.e(TAG, "undefined sql id"); return null; } String sql = context.getResources().getString(pointer); if (bindParams != null) { Iterator<String> mapIterator = bindParams.keySet().iterator(); while (mapIterator.hasNext()) { String key = mapIterator.next(); Object value = bindParams.get(key); sql = sql.replaceAll("#" + key.toLowerCase() + "#", value == null ? null : "'" + value.toString() + "'"); } } if (sql.indexOf('#') != -1) { Log.e(TAG, "undefined parameter"); return null; } Cursor cursor = dbObj.rawQuery(sql, null); List<T> objectList = new ArrayList<T>(); if (cursor == null) { return null; } String[] columnNames = cursor.getColumnNames(); List<String> dataNames = new ArrayList<String>(); for (String columnName : columnNames) { dataNames.add(chgDataName(columnName)); } T beanObj = null; // get bean class package Package beanPackage = bean.getPackage(); while (cursor.moveToNext()) { Map<String, Object> map = new HashMap<String, Object>(); int i = 0; for (String dataName : dataNames) { map.put(dataName, cursor.getString(i)); i++; } JSONObject json = new JSONObject(map); try { beanObj = (T) parse(json.toString(), bean, beanPackage.getName()); } catch (Exception e) { Log.d(TAG, e.toString()); return null; } objectList.add(beanObj); } cursor.close(); dbObj.close(); return objectList; }
From source file:org.disciple.db.Abatis.java
/** * * @param sqlId SQLID//from w w w. java 2 s . c om * @param bindParams sql parameter * @param bean bean class of result * * @return List<Map<String, Object>> result */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> T executeForBean(String sqlId, Map<String, Object> bindParams, Class bean) { getDbObject(); int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName()); if (pointer == 0) { Log.e(TAG, "undefined sql id"); return null; } String sql = context.getResources().getString(pointer); if (bindParams != null) { Iterator<String> mapIterator = bindParams.keySet().iterator(); while (mapIterator.hasNext()) { String key = mapIterator.next(); Object value = bindParams.get(key); sql = sql.replaceAll("#" + key.toLowerCase() + "#", value == null ? null : "'" + value.toString() + "'"); } } if (sql.indexOf('#') != -1) { Log.e(TAG, "undefined parameter"); return null; } Cursor cursor = dbObj.rawQuery(sql, null); List<T> objectList = new ArrayList<T>(); if (cursor == null) { return null; } String[] columnNames = cursor.getColumnNames(); List<String> dataNames = new ArrayList<String>(); for (String columnName : columnNames) { dataNames.add(chgDataName(columnName)); } T beanObj = null; // get bean class package Package beanPackage = bean.getPackage(); while (cursor.moveToNext()) { Map<String, Object> map = new HashMap<String, Object>(); int i = 0; for (String dataName : dataNames) { map.put(dataName, cursor.getString(i)); i++; } JSONObject json = new JSONObject(map); try { beanObj = (T) parse(json.toString(), bean, beanPackage.getName()); } catch (Exception e) { Log.d(TAG, e.toString()); return null; } objectList.add(beanObj); } if (objectList.size() <= 0) { return null; } cursor.close(); dbObj.close(); return objectList.get(0); }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Shows the about dialog that tells about the application. *///from w w w.j a va 2s. co m public void showAboutDialog() { Package packageInfo = Package.getPackage("net.chaosserver.timelord.swingui"); if (log.isTraceEnabled()) { if (packageInfo != null) { StringBuffer sb = new StringBuffer(); sb.append(packageInfo.getClass().getName()); sb.append(" [name="); sb.append(packageInfo.getName()); sb.append(", specificationTitle="); sb.append(packageInfo.getSpecificationTitle()); sb.append(", specificationVersion="); sb.append(packageInfo.getSpecificationVersion()); sb.append(", specificationVendor="); sb.append(packageInfo.getSpecificationVendor()); sb.append(", implementationTitle="); sb.append(packageInfo.getImplementationTitle()); sb.append(", implementationVersion="); sb.append(packageInfo.getImplementationVersion()); sb.append(", implementationVendor="); sb.append(packageInfo.getImplementationVendor()); sb.append("]"); log.trace(sb.toString()); } } StringBuffer sb = new StringBuffer(); sb.append("Timelord"); if ((packageInfo != null) && (packageInfo.getImplementationVersion() != null)) { sb.append(" ["); sb.append(packageInfo.getImplementationVersion()); sb.append("]"); } else { Properties appProperties = getAppProperties(); if (appProperties != null) { sb.append(" "); sb.append(appProperties.getProperty("implementation.version", "[Unknown Version]")); } else { sb.append(" [Unknown Version]"); } } sb.append("\n"); sb.append(resourceBundle.getString(RROOT + ".about")); JOptionPane.showMessageDialog(applicationFrame, sb.toString(), "About Timelord", JOptionPane.INFORMATION_MESSAGE, applicationIcon); }
From source file:org.apache.axis2.deployment.util.Utils.java
public static boolean loadHandler(ClassLoader loader1, HandlerDescription desc) throws DeploymentException { String handlername = desc.getClassName(); Handler handler;//from w w w.j a va 2 s.c o m try { final Class handlerClass = Loader.loadClass(loader1, handlername); Package aPackage = (Package) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedAction() { public Object run() { return handlerClass.getPackage(); } }); if (aPackage != null && aPackage.getName().equals("org.apache.axis2.engine")) { String name = handlerClass.getName(); log.warn("Dispatcher " + name + " is now deprecated."); if (name.indexOf("InstanceDispatcher") != -1) { log.warn("Please remove the entry for " + handlerClass.getName() + "from axis2.xml"); } else { log.warn( "Please edit axis2.xml and replace with the same class in org.apache.axis2.dispatchers package"); } } handler = (Handler) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws InstantiationException, IllegalAccessException { return handlerClass.newInstance(); } }); handler.init(desc); desc.setHandler(handler); } catch (ClassNotFoundException e) { if (handlername.indexOf("jaxws") > 0) { log.warn("[JAXWS] - unable to load " + handlername); return false; } throw new DeploymentException(e); } catch (Exception e) { throw new DeploymentException(e); } return true; }
From source file:org.jakz.common.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. * * @param object/*from ww w . j av a2s .c om*/ * 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 || object instanceof BigInteger || object instanceof BigDecimal) { return object; } if (object instanceof Collection) { Collection<?> coll = (Collection<?>) object; return new JSONArray(coll); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { Map<?, ?> map = (Map<?, ?>) object; return new JSONObject(map); } 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(); } if (object instanceof JSONObjectWriteAspect) return ((JSONObjectWriteAspect) object).toJSONObject(); return new JSONObject(object); } catch (Exception exception) { return null; } }