List of usage examples for java.lang InstantiationException printStackTrace
public void printStackTrace()
From source file:gr.upatras.ece.nam.fci.core.FCI.java
public void loadAmazonService() { ClassLoader classLoader = FCI.class.getClassLoader(); //Dynamic loading UoPServices plugin if exists Class<?> ServicesClass; try {//from w w w . j a va 2 s.c om ServicesClass = classLoader.loadClass("gr.upatras.ece.nam.fci.amazon.AmazonServices"); log.info("Found aClass.getName() = " + ServicesClass.getName()); iAmazonServices = (IFCIService) ServicesClass.newInstance(); } catch (ClassNotFoundException e1) { //e1.printStackTrace(); log.warn("AmazonServices class not found"); } catch (InstantiationException e) { // TODO Auto-generated catch block // e.printStackTrace(); log.warn("AmazonServices class not instantiated"); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gr.upatras.ece.nam.fci.core.FCI.java
public void loadPanlabService() { ClassLoader classLoader = FCI.class.getClassLoader(); //Dynamic loading UoPServices plugin if exists Class<?> ServicesClass; try {//from w ww . j a va 2 s .c o m ServicesClass = classLoader.loadClass("gr.upatras.ece.nam.fci.panlab.PanlabServices"); log.info("Found aClass.getName() = " + ServicesClass.getName()); iPanlabServices = (IFCIService) ServicesClass.newInstance(); } catch (ClassNotFoundException e1) { //e1.printStackTrace(); log.warn("PanlabServices class not found"); } catch (InstantiationException e) { // TODO Auto-generated catch block // e.printStackTrace(); log.warn("PanlabServices class not instantiated"); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.networking.nemo.network.NetworkRequestManager.java
private <T, K> void runRequestsFromQueue() throws InterruptedException { Iterator<JsonNetworkRequest<?, JsonNetworkRequestError>> iter = mRequestQueue.iterator(); while (iter.hasNext() && mRunningRequests.size() < mMaxRunningRequestCount) { // Get the base request @SuppressWarnings("unchecked") final JsonNetworkRequest<T, JsonNetworkRequestError> baseRequest = (JsonNetworkRequest<T, JsonNetworkRequestError>) iter .next();// www .j a v a 2 s . c o m // Check if we can run it if (isAllowedToRun(baseRequest)) { // Now it's safe to remove from queue iter.remove(); // If there is no network available notify listener if (!mNetworkStateChecker.isNetworkConnected()) { try { JsonNetworkRequestError error = baseRequest.getClassOfFailedObject().newInstance(); error.setReason(NetworkErrorReason.NO_NETWORK); baseRequest.getListener().onNetworkRequestError(error); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } continue; } // Create response listener Listener<Object> responseListener = new Listener<Object>() { @SuppressWarnings("unchecked") @Override public void onResponse(Object response) { // Remove from running requests mRunningRequests.remove(baseRequest.getId()); NetworkRequestListener<T, K> listener = (NetworkRequestListener<T, K>) baseRequest .getListener(); // Notify listener if (listener != null) { listener.onNetworkRequestSuccess((T) response); } // Start more requests if in queue runDelayed(); } }; ErrorListener errorResponseListener = new ErrorListener() { @SuppressWarnings("unchecked") @Override public void onErrorResponse(VolleyError error) { NemoVolleyError e = (NemoVolleyError) error; JsonNetworkRequestError err = (JsonNetworkRequestError) e.getErrorObject(); // Check for JsonKeyNotFoundExpection if (e.getCause() != null && e.getCause() instanceof JsonKeyNotFoundExpection) { // Log JsonKeyNotFoundExpection ex = (JsonKeyNotFoundExpection) e.getCause(); NemoLog.error(NetworkRequestManager.class, "request url: " + baseRequest.getUrl()); NemoLog.error(NetworkRequestManager.class, "response missing field in JSON: " + ex.getMessage()); err.setReason(NetworkErrorReason.KEY_NOT_FOUND); } else if (err.getHttpStatusCode() != HttpStatus.SC_OK) { err.setReason(NetworkErrorReason.HTTP_ERROR); } // Remove from running requests mRunningRequests.remove(baseRequest.getId()); NetworkRequestListener<T, K> listener = (NetworkRequestListener<T, K>) baseRequest .getListener(); if (listener != null) { listener.onNetworkRequestError((K) err); } // Start more requests if in queue runDelayed(); } }; // Create JsonNetworkRequest Gson gson = new Gson(); String body = gson.toJson(baseRequest.getJsonBody()); VolleyRequest<T, JsonNetworkRequestError> request = new VolleyRequest<T, JsonNetworkRequestError>( (JsonNetworkRequest<T, JsonNetworkRequestError>) baseRequest, body, responseListener, errorResponseListener); request.setId(baseRequest.getId()); // Change request running mRunningRequests.put(baseRequest.getId(), baseRequest); request.run(mVolleyQueue); // Log String logMethod = ""; switch (baseRequest.getMethod()) { case Method.GET: logMethod = "GET"; break; case Method.POST: logMethod = "POST"; break; case Method.PUT: logMethod = "PUT"; break; case Method.DELETE: logMethod = "DELETE"; break; } NemoLog.debug(NetworkRequestManager.class, "run " + logMethod + ": " + baseRequest.getUrl()); if (baseRequest.getMethod() == Method.POST) { NemoLog.debug(NetworkRequestManager.class, "parameters: " + body); } } } }
From source file:com.t2.androidspineexample.AndroidSpineExampleActivity.java
/** Called when the activity is first created. */ @Override//from ww w .j a v a 2 s.c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, this.getClass().getSimpleName() + ".onCreate()"); mInstance = this; setContentView(R.layout.main); // Set up member variables to UI Elements mTextViewDataMindset = (TextView) findViewById(R.id.textViewData); mTextViewDataShimmerEcg = (TextView) findViewById(R.id.textViewDataShimmerEcg); mTextViewDataShimmerGsr = (TextView) findViewById(R.id.textViewDataShimmerGsr); mTextViewDataShimmerEmg = (TextView) findViewById(R.id.textViewDataShimmerEmg); // ---------------------------------------------------- // Initialize SPINE by passing the fileName with the configuration properties // ---------------------------------------------------- Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); try { mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, "Exception creating SPINE manager: " + e.toString()); Log.e(TAG, "Check to see that valid defaults.properties, and SpineTestApp.properties files exist in the Assets folder!"); e.printStackTrace(); } // ... then we need to register a SPINEListener implementation to the SPINE manager instance // to receive sensor node data from the Spine server // (I register myself since I'm a SPINEListener implementation!) mSpineManager.addListener(this); // Create a broadcast receiver. Note that this is used ONLY for command messages from the service // All data from the service goes through the mail SPINE mechanism (received(Data data)). // See public void received(Data data) this.mCommandReceiver = new SpineReceiver(this); // Set up filter intents so we can receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction("com.t2.biofeedback.service.status.BROADCAST"); this.registerReceiver(this.mCommandReceiver, filter); try { mCurrentMindsetData = new MindsetData(this); } catch (Exception e1) { Log.e(TAG, "Exception creating MindsetData: " + e1.toString()); } // Since Mindset is a static node we have to manually put it in the active node list // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor Node MindsetNode = null; MindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET)); mSpineManager.getActiveNodes().add(MindsetNode); // Since Shimmer is a static node we have to manually put it in the active node list mShimmerNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_SHIMMER)); mSpineManager.getActiveNodes().add(mShimmerNode); // Set up graph(s) mSeries = new XYSeries("parameter"); generateChart(); }
From source file:com.netease.hearttouch.htrefreshrecyclerview.base.HTBaseRecyclerView.java
private void initViews() { //RecyclerView?,attrsRecyclerView,??? mRecyclerView.setId(View.NO_ID);//Id?attrs?? mRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);// //???//from ww w .ja v a 2 s .co m removeAllViews(); mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setViewLayoutParams(mRefreshContainerView); setViewLayoutParams(mLoadMoreContainerView); addView(mRecyclerView); addView(mRefreshContainerView); //?,? if (sViewHolderClass != null) { try { Constructor constructor = sViewHolderClass.getConstructor(Context.class); try { setRefreshViewHolder((HTBaseViewHolder) constructor.newInstance(getContext())); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } catch (NoSuchMethodException e) { e.printStackTrace(); } } else { HTBaseViewHolder viewHolder; if (checkOrientationVertical()) { viewHolder = new HTDefaultVerticalRefreshViewHolder(getContext()); ((HTDefaultVerticalRefreshViewHolder) viewHolder).setDefaultRefreshViewArrow(mHTOrientation); } else { viewHolder = new HTDefaultHorizontalRefreshViewHolder(getContext()); ((HTDefaultHorizontalRefreshViewHolder) viewHolder).setDefaultRefreshViewArrow(mHTOrientation); } setRefreshViewHolder(viewHolder);//? } }
From source file:net.rllcommunity.plugins.rpgitems.item.RPGItem.java
@SuppressWarnings("unchecked") public RPGItem(ConfigurationSection s) { name = s.getString("name"); id = s.getInt("id"); setDisplay(s.getString("display"), false); setType(s.getString("type", RpgItems.plugin.getConfig().getString("defaults.sword", "Sword")), false); setHand(s.getString("hand", RpgItems.plugin.getConfig().getString("defaults.hand", "One handed")), false); setLore(s.getString("lore"), false); description = (List<String>) s.getList("description", new ArrayList<String>()); for (int i = 0; i < description.size(); i++) { description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i))); }/*from ww w . j a va2 s .c o m*/ quality = Quality.valueOf(s.getString("quality")); damageMin = s.getInt("damageMin"); damageMax = s.getInt("damageMax"); armour = s.getInt("armour", 0); item = new ItemStack(Material.valueOf(s.getString("item"))); ItemMeta meta = item.getItemMeta(); if (meta instanceof LeatherArmorMeta) { ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0))); } else { item.setDurability((short) s.getInt("item_data", 0)); } for (String locale : Locale.getLocales()) { localeMeta.put(locale, meta.clone()); } ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false); // Powers ConfigurationSection powerList = s.getConfigurationSection("powers"); if (powerList != null) { for (String sectionKey : powerList.getKeys(false)) { ConfigurationSection section = powerList.getConfigurationSection(sectionKey); try { if (!Power.powers.containsKey(section.getString("powerName"))) { // Invalid power continue; } Power pow = Power.powers.get(section.getString("powerName")).newInstance(); pow.init(section); pow.item = this; addPower(pow, false); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } encodedID = getMCEncodedID(id); // Recipes hasRecipe = s.getBoolean("hasRecipe", false); if (hasRecipe) { recipe = (List<ItemStack>) s.getList("recipe"); } ConfigurationSection drops = s.getConfigurationSection("dropChances"); if (drops != null) { for (String key : drops.getKeys(false)) { double chance = drops.getDouble(key, 0.0); chance = Math.min(chance, 100.0); if (chance > 0) { dropChances.put(key, chance); if (!Events.drops.containsKey(key)) { Events.drops.put(key, new HashSet<Integer>()); } Set<Integer> set = Events.drops.get(key); set.add(getID()); } else { dropChances.remove(key); if (Events.drops.containsKey(key)) { Set<Integer> set = Events.drops.get(key); set.remove(getID()); } } dropChances.put(key, chance); } } if (item.getType().getMaxDurability() != 0) { hasBar = true; } maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability()); forceBar = s.getBoolean("forceBar", false); if (maxDurability == 0) { maxDurability = -1; } rebuild(); }
From source file:think.rpgitems.item.RPGItem.java
@SuppressWarnings("unchecked") public RPGItem(ConfigurationSection s) { name = s.getString("name"); id = s.getInt("id"); setDisplay(s.getString("display"), false); setType(s.getString("type", Plugin.plugin.getConfig().getString("defaults.sword", "Sword")), false); setHand(s.getString("hand", Plugin.plugin.getConfig().getString("defaults.hand", "One handed")), false); setLore(s.getString("lore"), false); description = (List<String>) s.getList("description", new ArrayList<String>()); for (int i = 0; i < description.size(); i++) { description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i))); }//from w w w .jav a2 s. com quality = Quality.valueOf(s.getString("quality")); damageMin = s.getInt("damageMin"); damageMax = s.getInt("damageMax"); armour = s.getInt("armour", 0); item = new ItemStack(Material.valueOf(s.getString("item"))); ItemMeta meta = item.getItemMeta(); if (meta instanceof LeatherArmorMeta) { ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0))); } else { item.setDurability((short) s.getInt("item_data", 0)); } localeMeta = meta.clone(); ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false); // Powers ConfigurationSection powerList = s.getConfigurationSection("powers"); if (powerList != null) { for (String sectionKey : powerList.getKeys(false)) { ConfigurationSection section = powerList.getConfigurationSection(sectionKey); try { if (!Power.powers.containsKey(section.getString("powerName"))) { // Invalid power continue; } Power pow = Power.powers.get(section.getString("powerName")).newInstance(); pow.init(section); pow.item = this; addPower(pow, false); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } encodedID = getMCEncodedID(id); haspermission = s.getBoolean("haspermission", false); permission = s.getString("permission", "a.default.permission"); // Recipes recipechance = s.getInt("recipechance", 6); hasRecipe = s.getBoolean("hasRecipe", false); if (hasRecipe) { recipe = (List<ItemStack>) s.getList("recipe"); } ConfigurationSection drops = s.getConfigurationSection("dropChances"); if (drops != null) { for (String key : drops.getKeys(false)) { double chance = drops.getDouble(key, 0.0); chance = Math.min(chance, 100.0); if (chance > 0) { dropChances.put(key, chance); if (!Events.drops.containsKey(key)) { Events.drops.put(key, new HashSet<Integer>()); } Set<Integer> set = Events.drops.get(key); set.add(getID()); } else { dropChances.remove(key); if (Events.drops.containsKey(key)) { Set<Integer> set = Events.drops.get(key); set.remove(getID()); } } dropChances.put(key, chance); } } if (item.getType().getMaxDurability() != 0) { hasBar = true; } maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability()); forceBar = s.getBoolean("forceBar", false); if (maxDurability == 0) { maxDurability = -1; } rebuild(); }
From source file:org.mentawai.annotations.ApplicationManagerWithAnnotations.java
@SuppressWarnings("rawtypes") public void loadAnnotatedClasses() { ActionConfig ac;/* w ww .j a v a2 s. com*/ ArrayList<ActionConfig> acListForChains = new ArrayList<ActionConfig>(); // Para carregamento das Chains ArrayList<String> actionName = new ArrayList<String>(); ArrayList<String> innerActionName = new ArrayList<String>(); ArrayList<String> actionChain = new ArrayList<String>(); ArrayList<String> innerChain = new ArrayList<String>(); if (resources == null) { System.out.println("NO RESOURCES DEFINED"); return; } try { System.out.println("Searching for annotated classes inside package [" + resources + "]..."); findAnnotatedClasses(resources); } catch (Exception e) { System.out.println("COULD NOT LOAD PACKAGE ANNOTATED CLASSES: "); e.printStackTrace(); return; } HashSet<Class> annotatedRemove = new HashSet<Class>(); for (Class<? extends Object> klass : annotatedClasses) { if (klass.getSuperclass().isAnnotationPresent(ActionClass.class)) { annotatedRemove.add(klass.getSuperclass()); System.out.println("REMOVING " + klass.getSuperclass() + ": this actions will be mapped by its subclass " + klass.getName() + "."); } } for (Class<? extends Object> klass2Remove : annotatedRemove) { annotatedClasses.remove(klass2Remove); } if (annotatedClasses.size() > 0) { for (Class<? extends Object> klass : annotatedClasses) { if (klass.isAnnotationPresent(ActionClass.class)) { System.out.println("LOADING ANNOTATED ACTION CLASS: " + klass.getName()); // Mapear o prefixo da ao com a classe de ao ActionClass annotation = klass.getAnnotation(ActionClass.class); if (getActions().containsKey(annotation.prefix())) { ac = getActions().get(annotation.prefix()); if (ac.getActionClass().isAssignableFrom(klass)) { ac = new ActionConfig(annotation.prefix(), klass); } } else ac = new ActionConfig(annotation.prefix(), klass); // Mapear as consequencias default (sem mtodo de ao) da // classe ConsequenceOutput[] outputsClass = annotation.outputs(); if (outputsClass != null && outputsClass.length > 0) { for (ConsequenceOutput output : outputsClass) { if (output.type() == ConsequenceType.FORWARD) { // Caso seja a consequencia padro, mapear // sucesso e erro para a mesma pgina if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) { ac.addConsequence(SUCCESS, new Forward(output.page())); ac.addConsequence(ERROR, new Forward(output.page())); } else ac.addConsequence(output.result(), new Forward(output.page())); } else if (output.type() == ConsequenceType.REDIRECT) { ac.addConsequence(output.result(), "".equals(output.page()) ? new Redirect(output.RedirectWithParameters()) : new Redirect(output.page(), output.RedirectWithParameters())); } else if (output.type() == ConsequenceType.STREAMCONSEQUENCE) { ac.addConsequence(output.result(), "".equals(output.page()) ? new StreamConsequence() : new StreamConsequence(output.page())); } else if (output.type() == ConsequenceType.AJAXCONSEQUENCE) { try { AjaxRenderer ajaxRender = (AjaxRenderer) Class.forName(output.page()) .newInstance(); ac.addConsequence(output.result(), new AjaxConsequence(ajaxRender)); } catch (InstantiationException ex) { ac.addConsequence(output.result(), new AjaxConsequence(new MapAjaxRenderer())); } catch (Exception ex) { System.out.println( "COULD NOT LOAD AJAX CONSEQUENCE, LOADED DEFAULT MapAjaxRenderer"); ex.printStackTrace(); } } else if (output.type() == ConsequenceType.CUSTOM) { try { Consequence customObject = (Consequence) Class.forName(output.page()) .newInstance(); ac.addConsequence(output.result(), customObject); } catch (Exception ex) { System.out.println("COULD NOT LOAD CUSTOM CONSEQUENCE: ACTION NOT LOADED: " + klass.getSimpleName()); ex.printStackTrace(); } } } } // Mapear os mtodos de aes da classe for (Method method : klass.getMethods()) { if (method.isAnnotationPresent(Consequences.class)) { System.out.println( "LOADING CONSEQUENCE: " + annotation.prefix() + "." + method.getName()); // Buscar as consequencias anotadas na classe de // ao ConsequenceOutput[] mapConsequences = method.getAnnotation(Consequences.class) .outputs(); // Mapeando as consequencias if (mapConsequences != null && mapConsequences.length > 0) { for (ConsequenceOutput output : mapConsequences) { if (output.type() == ConsequenceType.FORWARD) { // Caso seja a consequencia padro, // mapear sucesso e erro para a mesma // pgina if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) { ac.addConsequence(SUCCESS, method.getName(), new Forward(output.page())); ac.addConsequence(ERROR, method.getName(), new Forward(output.page())); } else ac.addConsequence(output.result(), method.getName(), new Forward(output.page())); } else if (output.type() == ConsequenceType.REDIRECT) { Consequence c = null; if (output.page().equals("")) { c = new Redirect(output.RedirectWithParameters()); } else { c = new Redirect(output.page(), output.RedirectWithParameters()); } if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) { ac.addConsequence(SUCCESS, method.getName(), c); ac.addConsequence(ERROR, method.getName(), c); } else { ac.addConsequence(output.result(), method.getName(), c); } } else if (output.type() == ConsequenceType.STREAMCONSEQUENCE) { ac.addConsequence(output.result(), method.getName(), "".equals(output.page()) ? new StreamConsequence() : new StreamConsequence(output.page())); } else if (output.type() == ConsequenceType.AJAXCONSEQUENCE) { try { AjaxRenderer ajaxRender = (AjaxRenderer) Class.forName(output.page()) .newInstance(); ac.addConsequence(output.result(), method.getName(), new AjaxConsequence(ajaxRender)); } catch (InstantiationException ex) { ac.addConsequence(output.result(), method.getName(), new AjaxConsequence(new MapAjaxRenderer())); } catch (Exception ex) { System.out.println( "COULD NOT LOAD AJAX CONSEQUENCE, LOADED DEFAULT MapAjaxRenderer"); ex.printStackTrace(); } } else if (output.type() == ConsequenceType.CUSTOM) { try { Consequence customObject = (Consequence) Class.forName(output.page()) .newInstance(); ac.addConsequence(output.result(), method.getName(), customObject); } catch (Exception ex) { System.out.println( "COULD NOT LOAD CUSTOM CONSEQUENCE: ACTION NOT LOADED: " + klass.getSimpleName() + "." + method.getName()); ex.printStackTrace(); } } else if (output.type() == ConsequenceType.CHAIN) { String[] explodedParameter = output.page().split("\\."); // Usado // para // explodir // parameters // no // caso // de // uma // chain actionName.add(output.result()); innerActionName.add(method.getName()); actionChain.add(explodedParameter[0]); innerChain.add(explodedParameter.length > 1 ? explodedParameter[1] : null); acListForChains.add(ac); } } } } } add(ac); } } } // Carrega as chains atrasadas porque os ActionConfigs podem ainda nao // ter sido carregados int length = actionName.size(); Chain chain; for (int i = 0; i < length; i++) { try { ac = acListForChains.get(i); if (innerChain.get(i) == null) chain = new Chain(getActionConfig(actionChain.get(i))); else chain = new Chain(getActionConfig(actionChain.get(i)), innerChain.get(i)); if (actionName.get(i).equals(ConsequenceOutput.SUCCESS_ERROR)) { ac.addConsequence(SUCCESS, innerActionName.get(i), chain); ac.addConsequence(ERROR, innerActionName.get(i), chain); } else { ac.addConsequence(actionName.get(i), innerActionName.get(i), chain); } } catch (Exception e) { System.out.println("COULD NOT LOAD CHAIN CONSEQUENCE: ACTION NOT LOADED: " + actionChain.get(i) + "." + innerActionName.get(i)); } } }
From source file:com.jennifer.ui.chart.ChartBuilder.java
private void drawGrid() { JSONObject grid = builderoptions.getJSONObject("grid"); String[] names = JSONObject.getNames(grid); if (names == null) return;//from w ww. jav a2 s .co m if (grid != null && grid.names().length() > 0) { // create default cusotm grid if (grid.has("type")) { grid = new JSONObject().put("c", new JSONArray().put(JSONUtil.clone(grid))); } if (!builderoptions.has("scales")) { builderoptions.put("scales", new JSONObject()); } JSONObject scales = (JSONObject) builderoptions.getJSONObject("scales"); JSONArray keys = grid.names(); for (int i = 0, len = keys.length(); i < len; i++) { String key = keys.getString(i); Orient orient = Orient.CUSTOM; if ("x".equals(key)) { orient = Orient.BOTTOM; } else if ("y".equals(key)) { orient = Orient.LEFT; } else if ("x1".equals(key)) { orient = Orient.TOP; } else if ("y1".equals(key)) { orient = Orient.RIGHT; } if (!scales.has(key)) { scales.put(key, new JSONArray()); } JSONArray scale = (JSONArray) scales.getJSONArray(key); Object objGrid = grid.get(key); if (!(objGrid instanceof JSONArray) && !(objGrid instanceof JSONArray)) { JSONArray o = new JSONArray(); o.put(JSONUtil.clone(grid.getJSONObject(key))); grid.put(key, o); } else if (objGrid instanceof JSONArray) { grid.put(key, JSONUtil.clone((JSONArray) objGrid)); } JSONArray gridObject = (JSONArray) grid.getJSONArray(key); for (int keyIndex = 0, gridLen = gridObject.length(); keyIndex < gridLen; keyIndex++) { JSONObject g = JSONUtil.clone(gridObject.getJSONObject(keyIndex)); Class cls = grids.get(g.getString("type")); Grid newGrid = null; try { newGrid = (Grid) cls .getDeclaredConstructor(Orient.class, ChartBuilder.class, JSONObject.class) .newInstance(orient, this, g); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } JSONObject ret = (JSONObject) newGrid.render(); int dist = g.optInt("dist", 0); Transform root = (Transform) ret.get("root"); if ("y".equals(key)) { root.translate(area("x") - dist, area("y")); } else if ("y1".equals(key)) { root.translate(area("x2") + dist, area("y")); } else if ("x".equals(key)) { root.translate(area("x"), area("y2") + dist); } else if ("x1".equals(key)) { root.translate(area("x"), area("y") - dist); } this.root.append(root); scales.getJSONArray(key).put(keyIndex, newGrid); } } } }
From source file:iristk.util.Record.java
@Override public Record clone() { try {/*from w w w .j ava2 s .c o m*/ Constructor<?> constructor = getClass().getDeclaredConstructor(); constructor.setAccessible(true); Record clone = (Record) constructor.newInstance(null); clone.putAll(this); return clone; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; }